Skip to content

Commit

Permalink
[Spec] Fix Linter::Analyzer style
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiopelosin committed Apr 3, 2014
1 parent 8e5815b commit 2340ae8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 54 deletions.
10 changes: 4 additions & 6 deletions lib/cocoapods-core/specification/linter/analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,13 @@ def check_if_spec_is_empty
#
def check_install_hooks
unless consumer.spec.pre_install_callback.nil?
warning "The pre install hook of the specification DSL has been " \
"deprecated, use the `resource_bundles` or the " \
"`prepare_command` attributes."
warning "The pre install hook has been deprecated, " \
"use the `resource_bundles` or the `prepare_command` attributes."
end

unless consumer.spec.post_install_callback.nil?
warning "The post install hook of the specification DSL has been " \
"deprecated, use the `resource_bundles` or the " \
" `prepare_command` attributes."
warning "The post install hook has been deprecated, " \
"use the `resource_bundles` or the `prepare_command` attributes."
end
end
end
Expand Down
96 changes: 48 additions & 48 deletions spec/specification/linter/analyzer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,55 @@ module Pod
describe Specification::Linter::Analyzer do

describe 'File patterns & Build settings' do

before do
fixture_path = 'spec-repos/test_repo/Specs/BananaLib/1.0/BananaLib.podspec'
podspec_path = fixture(fixture_path)
linter = Specification::Linter.new(podspec_path)
@spec = linter.spec
@sut = Specification::Linter::Analyzer.new(@spec.consumer(:ios))
@subject = Specification::Linter::Analyzer.new(@spec.consumer(:ios))
end

def message_should_include(*values)
@sut.analyze
results = @sut.results
results.should.not.be.nil
#----------------------------------------#

matched = results.select do |result|
values.all? do |value|
result.message.downcase.include?(value.downcase)
end
describe "File Patterns" do
it 'checks if any file patterns is absolute' do
@spec.source_files = '/Classes'
@subject.analyze
@subject.results.count.should.be.equal(1)
expected = 'patterns must be relative'
@subject.results.first.message.should.include?(expected)
end

matched.size.should == 1
end

it 'checks if any file patterns is absolute' do
@spec.source_files = '/Classes'
@sut.analyze
message_should_include('patterns', 'relative', 'source_files')
end

it 'checks if a specification is empty' do
consumer = Specification::Consumer
consumer.any_instance.stubs(:source_files).returns([])
consumer.any_instance.stubs(:resources).returns({})
consumer.any_instance.stubs(:preserve_paths).returns([])
consumer.any_instance.stubs(:subspecs).returns([])
consumer.any_instance.stubs(:dependencies).returns([])
consumer.any_instance.stubs(:vendored_libraries).returns([])
consumer.any_instance.stubs(:vendored_frameworks).returns([])
@sut.analyze
message_should_include('spec', 'empty')
it 'checks if a specification is empty' do
consumer = Specification::Consumer
consumer.any_instance.stubs(:source_files).returns([])
consumer.any_instance.stubs(:resources).returns({})
consumer.any_instance.stubs(:preserve_paths).returns([])
consumer.any_instance.stubs(:subspecs).returns([])
consumer.any_instance.stubs(:dependencies).returns([])
consumer.any_instance.stubs(:vendored_libraries).returns([])
consumer.any_instance.stubs(:vendored_frameworks).returns([])
@subject.analyze
@subject.results.count.should.be.equal(1)
@subject.results.first.message.should.include?('spec is empty')
end
end

#----------------------------------------#

describe 'File patterns & Build settings' do
describe 'Requires ARC' do
it 'that the attribute is not nil' do
@spec.requires_arc = nil
@sut.analyze
@sut.results.should.not.be.empty?
@sut.results.first.message.should.include?('`requires_arc` should be specified')
@subject.analyze
@subject.results.count.should.be.equal(1)
expected = '`requires_arc` should be specified'
@subject.results.first.message.should.include?(expected)
end

it 'supports the declaration of the attribute per platform' do
@spec.ios.requires_arc = true
@sut.analyze
@sut.results.should.be.empty?
@subject.analyze
@subject.results.should.be.empty?
end

it 'supports the declaration of the attribute in the parent' do
Expand All @@ -68,24 +61,31 @@ def message_should_include(*values)
s.subspec 'SubSpec' do |sp|
end
end
@sut = Specification::Linter::Analyzer.new(@spec.consumer(:ios))
@sut.analyze
@sut.results.should.be.empty?
consumer = @spec.consumer(:ios)
@subject = Specification::Linter::Analyzer.new(consumer)
@subject.analyze
@subject.results.should.be.empty?
end
end

#----------------------------------------#

it 'checks if the pre install hook has been defined' do
@spec.pre_install {}
@sut.analyze
message_should_include('pre install hook', 'deprecated')
end
describe 'Hooks' do
it 'checks if the pre install hook has been defined' do
@spec.pre_install {}
@subject.analyze
@subject.results.count.should.be.equal(1)
expected = 'pre install hook has been deprecated'
@subject.results.first.message.should.include?(expected)
end

it 'checks if the post install hook has been defined' do
@spec.post_install {}
@sut.analyze
message_should_include('post install hook', 'deprecated')
it 'checks if the post install hook has been defined' do
@spec.post_install {}
@subject.analyze
@subject.results.count.should.be.equal(1)
expected = 'post install hook has been deprecated'
@subject.results.first.message.should.include?(expected)
end
end
end
end
Expand Down

0 comments on commit 2340ae8

Please sign in to comment.