Commit 8c920151 authored by Kyle Fuller's avatar Kyle Fuller

[Specs] Stop using `sut`

parent cdf94bda
...@@ -356,14 +356,14 @@ module Pod ...@@ -356,14 +356,14 @@ module Pod
before do before do
# TODO Use class methods # TODO Use class methods
@sut = Command::Spec.new(CLAide::ARGV.new([])) @command = Command::Spec.new(CLAide::ARGV.new([]))
end end
describe '#get_path_of_spec' do describe '#get_path_of_spec' do
it 'returns the path of the specification with the given name' do it 'returns the path of the specification with the given name' do
path = @sut.send(:get_path_of_spec, 'AFNetworking') path = @command.send(:get_path_of_spec, 'AFNetworking')
path.should == fixture('spec-repos') + 'master/Specs/AFNetworking/2.4.1/AFNetworking.podspec.json' path.should == fixture('spec-repos') + 'master/Specs/AFNetworking/2.4.1/AFNetworking.podspec.json'
end end
...@@ -373,16 +373,16 @@ module Pod ...@@ -373,16 +373,16 @@ module Pod
it 'should return a valid index for the given array' do it 'should return a valid index for the given array' do
UI.next_input = "1\n" UI.next_input = "1\n"
index = @sut.send(:choose_from_array, %w(item1 item2 item3), 'A message') index = @command.send(:choose_from_array, %w(item1 item2 item3), 'A message')
UI.output.should.include "1: item1\n2: item2\n3: item3\nA message\n" UI.output.should.include "1: item1\n2: item2\n3: item3\nA message\n"
index.should == 0 index.should == 0
end end
it 'should raise when the index is out of bounds' do it 'should raise when the index is out of bounds' do
UI.next_input = "4\n" UI.next_input = "4\n"
lambda { @sut.send(:choose_from_array, %w(item1 item2 item3), 'A message') }.should.raise Pod::Informative lambda { @command.send(:choose_from_array, %w(item1 item2 item3), 'A message') }.should.raise Pod::Informative
UI.next_input = "0\n" UI.next_input = "0\n"
lambda { @sut.send(:choose_from_array, %w(item1 item2 item3), 'A message') }.should.raise Pod::Informative lambda { @command.send(:choose_from_array, %w(item1 item2 item3), 'A message') }.should.raise Pod::Informative
end end
end end
......
...@@ -3,7 +3,7 @@ require File.expand_path('../../spec_helper', __FILE__) ...@@ -3,7 +3,7 @@ require File.expand_path('../../spec_helper', __FILE__)
module Pod module Pod
describe Config do describe Config do
before do before do
@sut = Config.new(false) @config = Config.new(false)
end end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
...@@ -11,35 +11,35 @@ module Pod ...@@ -11,35 +11,35 @@ module Pod
describe 'In general' do describe 'In general' do
it 'returns the singleton config instance' do it 'returns the singleton config instance' do
@sut.should.be.instance_of Config @config.should.be.instance_of Config
end end
it 'returns the path to the home dir' do it 'returns the path to the home dir' do
@sut.home_dir.should == Pathname.new('~/.cocoapods').expand_path @config.home_dir.should == Pathname.new('~/.cocoapods').expand_path
end end
it 'returns the path to the spec-repos dir' do it 'returns the path to the spec-repos dir' do
@sut.repos_dir.should == Pathname.new('~/.cocoapods/repos').expand_path @config.repos_dir.should == Pathname.new('~/.cocoapods/repos').expand_path
end end
it 'returns the path to the templates dir' do it 'returns the path to the templates dir' do
@sut.templates_dir.should == Pathname.new('~/.cocoapods/templates').expand_path @config.templates_dir.should == Pathname.new('~/.cocoapods/templates').expand_path
end end
it 'returns the path of the default podfiles' do it 'returns the path of the default podfiles' do
@sut.default_podfile_path.should == Pathname.new('~/.cocoapods/templates/Podfile.default').expand_path @config.default_podfile_path.should == Pathname.new('~/.cocoapods/templates/Podfile.default').expand_path
@sut.default_test_podfile_path.should == Pathname.new('~/.cocoapods/templates/Podfile.test').expand_path @config.default_test_podfile_path.should == Pathname.new('~/.cocoapods/templates/Podfile.test').expand_path
end end
it 'allows to specify the home dir with an environment variable' do it 'allows to specify the home dir with an environment variable' do
ENV['CP_HOME_DIR'] = '~/custom_home_dir' ENV['CP_HOME_DIR'] = '~/custom_home_dir'
@sut.home_dir.should == Pathname.new('~/custom_home_dir').expand_path @config.home_dir.should == Pathname.new('~/custom_home_dir').expand_path
ENV.delete('CP_HOME_DIR') ENV.delete('CP_HOME_DIR')
end end
it 'allows to specify the repos dir with an environment variable' do it 'allows to specify the repos dir with an environment variable' do
ENV['CP_REPOS_DIR'] = '~/custom_repos_dir' ENV['CP_REPOS_DIR'] = '~/custom_repos_dir'
@sut.repos_dir.should == Pathname.new('~/custom_repos_dir').expand_path @config.repos_dir.should == Pathname.new('~/custom_repos_dir').expand_path
ENV.delete('CP_REPOS_DIR') ENV.delete('CP_REPOS_DIR')
end end
end end
...@@ -51,7 +51,7 @@ module Pod ...@@ -51,7 +51,7 @@ module Pod
it 'returns the working directory as the installation root if a Podfile can be found' do it 'returns the working directory as the installation root if a Podfile can be found' do
Dir.chdir(temporary_directory) do Dir.chdir(temporary_directory) do
File.open('Podfile', 'w') {} File.open('Podfile', 'w') {}
@sut.installation_root.should == temporary_directory @config.installation_root.should == temporary_directory
end end
end end
...@@ -61,54 +61,54 @@ module Pod ...@@ -61,54 +61,54 @@ module Pod
sub_dir = temporary_directory + 'sub_dir' sub_dir = temporary_directory + 'sub_dir'
sub_dir.mkpath sub_dir.mkpath
Dir.chdir(sub_dir) do Dir.chdir(sub_dir) do
@sut.installation_root.should == temporary_directory @config.installation_root.should == temporary_directory
end end
end end
end end
it 'it returns the working directory as the installation root if no Podfile can be found' do it 'it returns the working directory as the installation root if no Podfile can be found' do
Dir.chdir(temporary_directory) do Dir.chdir(temporary_directory) do
@sut.installation_root.should == temporary_directory @config.installation_root.should == temporary_directory
end end
end end
before do before do
@sut.installation_root = temporary_directory @config.installation_root = temporary_directory
end end
it 'returns the path to the project root' do it 'returns the path to the project root' do
@sut.installation_root.should == temporary_directory @config.installation_root.should == temporary_directory
end end
it 'returns the path to the project Podfile if it exists' do it 'returns the path to the project Podfile if it exists' do
(temporary_directory + 'Podfile').open('w') { |f| f << '# Yo' } (temporary_directory + 'Podfile').open('w') { |f| f << '# Yo' }
@sut.podfile_path.should == temporary_directory + 'Podfile' @config.podfile_path.should == temporary_directory + 'Podfile'
end end
it 'can detect yaml Podfiles' do it 'can detect yaml Podfiles' do
(temporary_directory + 'CocoaPods.podfile.yaml').open('w') { |f| f << '# Yo' } (temporary_directory + 'CocoaPods.podfile.yaml').open('w') { |f| f << '# Yo' }
@sut.podfile_path.should == temporary_directory + 'CocoaPods.podfile.yaml' @config.podfile_path.should == temporary_directory + 'CocoaPods.podfile.yaml'
end end
it 'can detect files named `CocoaPods.podfile`' do it 'can detect files named `CocoaPods.podfile`' do
(temporary_directory + 'CocoaPods.podfile').open('w') { |f| f << '# Yo' } (temporary_directory + 'CocoaPods.podfile').open('w') { |f| f << '# Yo' }
@sut.podfile_path.should == temporary_directory + 'CocoaPods.podfile' @config.podfile_path.should == temporary_directory + 'CocoaPods.podfile'
end end
it 'returns the path to the Pods directory that holds the dependencies' do it 'returns the path to the Pods directory that holds the dependencies' do
@sut.sandbox_root.should == temporary_directory + 'Pods' @config.sandbox_root.should == temporary_directory + 'Pods'
end end
it 'returns the Podfile path' do it 'returns the Podfile path' do
Dir.chdir(temporary_directory) do Dir.chdir(temporary_directory) do
File.open('Podfile', 'w') {} File.open('Podfile', 'w') {}
@sut.podfile_path.should == temporary_directory + 'Podfile' @config.podfile_path.should == temporary_directory + 'Podfile'
end end
end end
it 'returns nils if the Podfile if no paths exists' do it 'returns nils if the Podfile if no paths exists' do
Dir.chdir(temporary_directory) do Dir.chdir(temporary_directory) do
@sut.podfile_path.should.nil? @config.podfile_path.should.nil?
end end
end end
...@@ -116,12 +116,12 @@ module Pod ...@@ -116,12 +116,12 @@ module Pod
Dir.chdir(temporary_directory) do Dir.chdir(temporary_directory) do
File.open('Podfile', 'w') {} File.open('Podfile', 'w') {}
File.open('Podfile.lock', 'w') {} File.open('Podfile.lock', 'w') {}
@sut.lockfile_path.should == temporary_directory + 'Podfile.lock' @config.lockfile_path.should == temporary_directory + 'Podfile.lock'
end end
end end
it 'returns the search index file' do it 'returns the search index file' do
@sut.search_index_file.to_s.should.end_with?('search_index.yaml') @config.search_index_file.to_s.should.end_with?('search_index.yaml')
end end
end end
...@@ -131,19 +131,19 @@ module Pod ...@@ -131,19 +131,19 @@ module Pod
describe 'Default settings' do describe 'Default settings' do
it 'prints out normal information' do it 'prints out normal information' do
@sut.should.not.be.silent @config.should.not.be.silent
end end
it 'does not print verbose information' do it 'does not print verbose information' do
@sut.should.not.be.verbose @config.should.not.be.verbose
end end
it 'cleans SCM dirs in dependency checkouts' do it 'cleans SCM dirs in dependency checkouts' do
@sut.should.clean @config.should.clean
end end
it 'returns the cache root' do it 'returns the cache root' do
@sut.cache_root.should == Pathname.new(File.join(ENV['HOME'], 'Library/Caches/CocoaPods')) @config.cache_root.should == Pathname.new(File.join(ENV['HOME'], 'Library/Caches/CocoaPods'))
end end
end end
...@@ -152,13 +152,13 @@ module Pod ...@@ -152,13 +152,13 @@ module Pod
describe 'Private helpers' do describe 'Private helpers' do
it 'returns the path of the user settings file' do it 'returns the path of the user settings file' do
@sut.send(:user_settings_file).should == Pathname.new('~/.cocoapods/config.yaml').expand_path @config.send(:user_settings_file).should == Pathname.new('~/.cocoapods/config.yaml').expand_path
end end
it 'can be configured with a hash' do it 'can be configured with a hash' do
hash = { :verbose => true } hash = { :verbose => true }
@sut.send(:configure_with, hash) @config.send(:configure_with, hash)
@sut.should.be.verbose @config.should.be.verbose
end end
#----------------------------------------# #----------------------------------------#
...@@ -168,26 +168,26 @@ module Pod ...@@ -168,26 +168,26 @@ module Pod
it 'detects the CocoaPods.podfile.yaml file' do it 'detects the CocoaPods.podfile.yaml file' do
expected = temporary_directory + 'CocoaPods.podfile.yaml' expected = temporary_directory + 'CocoaPods.podfile.yaml'
File.open(expected, 'w') {} File.open(expected, 'w') {}
path = @sut.send(:podfile_path_in_dir, temporary_directory) path = @config.send(:podfile_path_in_dir, temporary_directory)
path.should == expected path.should == expected
end end
it 'detects the CocoaPods.podfile file' do it 'detects the CocoaPods.podfile file' do
expected = temporary_directory + 'CocoaPods.podfile' expected = temporary_directory + 'CocoaPods.podfile'
File.open(expected, 'w') {} File.open(expected, 'w') {}
path = @sut.send(:podfile_path_in_dir, temporary_directory) path = @config.send(:podfile_path_in_dir, temporary_directory)
path.should == expected path.should == expected
end end
it 'detects the Podfile file' do it 'detects the Podfile file' do
expected = temporary_directory + 'Podfile' expected = temporary_directory + 'Podfile'
File.open(expected, 'w') {} File.open(expected, 'w') {}
path = @sut.send(:podfile_path_in_dir, temporary_directory) path = @config.send(:podfile_path_in_dir, temporary_directory)
path.should == expected path.should == expected
end end
it 'returns nils if the Podfile is not available' do it 'returns nils if the Podfile is not available' do
path = @sut.send(:podfile_path_in_dir, temporary_directory) path = @config.send(:podfile_path_in_dir, temporary_directory)
path.should.nil? path.should.nil?
end end
......
...@@ -77,7 +77,7 @@ module Pod ...@@ -77,7 +77,7 @@ module Pod
describe 'Private Helpers' do describe 'Private Helpers' do
before do before do
@sut = PrivatePodXCConfig.new(stub, stub) @config = PrivatePodXCConfig.new(stub, stub)
end end
#----------------------------------------# #----------------------------------------#
...@@ -87,21 +87,21 @@ module Pod ...@@ -87,21 +87,21 @@ module Pod
it 'appends to the values of the keys of the destination the value of the keys of the source' do it 'appends to the values of the keys of the destination the value of the keys of the source' do
source_config = { 'HEADER_SEARCH_PATHS' => '${PODS_ROOT}/MyPod' } source_config = { 'HEADER_SEARCH_PATHS' => '${PODS_ROOT}/MyPod' }
destination_config = { 'HEADER_SEARCH_PATHS' => '${PODS_ROOT}/BuildHeaders' } destination_config = { 'HEADER_SEARCH_PATHS' => '${PODS_ROOT}/BuildHeaders' }
result = @sut.send(:add_xcconfig_namespaced_keys, source_config, destination_config, 'PREFIX_') result = @config.send(:add_xcconfig_namespaced_keys, source_config, destination_config, 'PREFIX_')
result.should == { 'HEADER_SEARCH_PATHS' => '${PODS_ROOT}/BuildHeaders ${PREFIX_HEADER_SEARCH_PATHS}' } result.should == { 'HEADER_SEARCH_PATHS' => '${PODS_ROOT}/BuildHeaders ${PREFIX_HEADER_SEARCH_PATHS}' }
end end
it 'uses the key of the destination xcconfig if not present in the source' do it 'uses the key of the destination xcconfig if not present in the source' do
source_config = {} source_config = {}
destination_config = { 'HEADER_SEARCH_PATHS' => '${PODS_ROOT}/BuildHeaders' } destination_config = { 'HEADER_SEARCH_PATHS' => '${PODS_ROOT}/BuildHeaders' }
result = @sut.send(:add_xcconfig_namespaced_keys, source_config, destination_config, 'PREFIX_') result = @config.send(:add_xcconfig_namespaced_keys, source_config, destination_config, 'PREFIX_')
result.should == { 'HEADER_SEARCH_PATHS' => '${PODS_ROOT}/BuildHeaders' } result.should == { 'HEADER_SEARCH_PATHS' => '${PODS_ROOT}/BuildHeaders' }
end end
it 'preserves any value of the source not present in the destination' do it 'preserves any value of the source not present in the destination' do
source_config = { 'EXCLUDED_SOURCE_FILE_NAMES' => 'ZBarReaderViewImpl_Simulator.m' } source_config = { 'EXCLUDED_SOURCE_FILE_NAMES' => 'ZBarReaderViewImpl_Simulator.m' }
destination_config = {} destination_config = {}
result = @sut.send(:add_xcconfig_namespaced_keys, source_config, destination_config, 'PREFIX_') result = @config.send(:add_xcconfig_namespaced_keys, source_config, destination_config, 'PREFIX_')
result.should == { 'EXCLUDED_SOURCE_FILE_NAMES' => '${PREFIX_EXCLUDED_SOURCE_FILE_NAMES}' } result.should == { 'EXCLUDED_SOURCE_FILE_NAMES' => '${PREFIX_EXCLUDED_SOURCE_FILE_NAMES}' }
end end
...@@ -112,12 +112,12 @@ module Pod ...@@ -112,12 +112,12 @@ module Pod
describe '#conditional_less_key' do describe '#conditional_less_key' do
it 'returns the key without the xcconfig conditional syntax if present' do it 'returns the key without the xcconfig conditional syntax if present' do
result = @sut.send(:conditional_less_key, 'EXCLUDED_SOURCE_FILE_NAMES[sdk=iphoneos*][arch=*]') result = @config.send(:conditional_less_key, 'EXCLUDED_SOURCE_FILE_NAMES[sdk=iphoneos*][arch=*]')
result.should == 'EXCLUDED_SOURCE_FILE_NAMES' result.should == 'EXCLUDED_SOURCE_FILE_NAMES'
end end
it 'returns the key as it is if no conditional syntax is present' do it 'returns the key as it is if no conditional syntax is present' do
result = @sut.send(:conditional_less_key, 'EXCLUDED_SOURCE_FILE_NAMES') result = @config.send(:conditional_less_key, 'EXCLUDED_SOURCE_FILE_NAMES')
result.should == 'EXCLUDED_SOURCE_FILE_NAMES' result.should == 'EXCLUDED_SOURCE_FILE_NAMES'
end end
......
...@@ -47,40 +47,40 @@ module Pod ...@@ -47,40 +47,40 @@ module Pod
describe 'Quick mode' do describe 'Quick mode' do
it 'validates a correct podspec' do it 'validates a correct podspec' do
sut = Validator.new(podspec_path, SourcesManager.master.map(&:url)) validator = Validator.new(podspec_path, SourcesManager.master.map(&:url))
sut.quick = true validator.quick = true
sut.validate validator.validate
sut.results.should == [] validator.results.should == []
sut.validated?.should.be.true validator.validated?.should.be.true
end end
it 'lints the podspec during validation' do it 'lints the podspec during validation' do
podspec = stub_podspec(/.*name.*/, '"name": "TEST",') podspec = stub_podspec(/.*name.*/, '"name": "TEST",')
file = write_podspec(podspec) file = write_podspec(podspec)
sut = Validator.new(file, SourcesManager.master.map(&:url)) validator = Validator.new(file, SourcesManager.master.map(&:url))
sut.quick = true validator.quick = true
sut.validate validator.validate
sut.results.map(&:to_s).first.should.match /should match the name/ validator.results.map(&:to_s).first.should.match /should match the name/
sut.validated?.should.be.false validator.validated?.should.be.false
end end
it 'respects quick mode' do it 'respects quick mode' do
file = write_podspec(stub_podspec) file = write_podspec(stub_podspec)
sut = Validator.new(file, SourcesManager.master.map(&:url)) validator = Validator.new(file, SourcesManager.master.map(&:url))
sut.quick = true validator.quick = true
sut.expects(:perform_extensive_analysis).never validator.expects(:perform_extensive_analysis).never
sut.validate validator.validate
end end
it 'respects the allow warnings option' do it 'respects the allow warnings option' do
podspec = stub_podspec(/.*summary.*/, '"summary": "A short description of",') podspec = stub_podspec(/.*summary.*/, '"summary": "A short description of",')
file = write_podspec(podspec) file = write_podspec(podspec)
sut = Validator.new(file, SourcesManager.master.map(&:url)) validator = Validator.new(file, SourcesManager.master.map(&:url))
sut.quick = true validator.quick = true
sut.allow_warnings = true validator.allow_warnings = true
sut.validate validator.validate
sut.results.map(&:to_s).first.should.match /summary.*meaningful/ validator.results.map(&:to_s).first.should.match /summary.*meaningful/
sut.validated?.should.be.true validator.validated?.should.be.true
end end
it 'handles symlinks' do it 'handles symlinks' do
...@@ -99,11 +99,11 @@ module Pod ...@@ -99,11 +99,11 @@ module Pod
describe 'URL validation' do describe 'URL validation' do
before do before do
@sut = Validator.new(podspec_path, SourcesManager.master.map(&:url)) @validator = Validator.new(podspec_path, SourcesManager.master.map(&:url))
@sut.stubs(:install_pod) @validator.stubs(:install_pod)
@sut.stubs(:build_pod) @validator.stubs(:build_pod)
@sut.stubs(:check_file_patterns) @validator.stubs(:check_file_patterns)
@sut.stubs(:tear_down_validation_environment) @validator.stubs(:tear_down_validation_environment)
WebMock::API.stub_request(:head, /not-found/).to_return(:status => 404) WebMock::API.stub_request(:head, /not-found/).to_return(:status => 404)
WebMock::API.stub_request(:get, /not-found/).to_return(:status => 404) WebMock::API.stub_request(:get, /not-found/).to_return(:status => 404)
end end
...@@ -111,15 +111,15 @@ module Pod ...@@ -111,15 +111,15 @@ module Pod
describe 'Homepage validation' do describe 'Homepage validation' do
it 'checks if the homepage is valid' do it 'checks if the homepage is valid' do
Specification.any_instance.stubs(:homepage).returns('http://banana-corp.local/not-found/') Specification.any_instance.stubs(:homepage).returns('http://banana-corp.local/not-found/')
@sut.validate @validator.validate
@sut.results.map(&:to_s).first.should.match /The URL (.*) is not reachable/ @validator.results.map(&:to_s).first.should.match /The URL (.*) is not reachable/
end end
it 'indicates if it was not able to validate the homepage' do it 'indicates if it was not able to validate the homepage' do
WebMock::API.stub_request(:head, 'banana-corp.local').to_raise(SocketError) WebMock::API.stub_request(:head, 'banana-corp.local').to_raise(SocketError)
Specification.any_instance.stubs(:homepage).returns('http://banana-corp.local/') Specification.any_instance.stubs(:homepage).returns('http://banana-corp.local/')
@sut.validate @validator.validate
@sut.results.map(&:to_s).first.should.match /There was a problem validating the URL/ @validator.results.map(&:to_s).first.should.match /There was a problem validating the URL/
end end
it 'does not fail if the homepage redirects' do it 'does not fail if the homepage redirects' do
...@@ -127,24 +127,24 @@ module Pod ...@@ -127,24 +127,24 @@ module Pod
:status => 301, :headers => { 'Location' => 'http://banana-corp.local/found/' }) :status => 301, :headers => { 'Location' => 'http://banana-corp.local/found/' })
WebMock::API.stub_request(:head, /found/).to_return(:status => 200) WebMock::API.stub_request(:head, /found/).to_return(:status => 200)
Specification.any_instance.stubs(:homepage).returns('http://banana-corp.local/redirect/') Specification.any_instance.stubs(:homepage).returns('http://banana-corp.local/redirect/')
@sut.validate @validator.validate
@sut.results.length.should.equal 0 @validator.results.length.should.equal 0
end end
it 'does not fail if the homepage does not support HEAD' do it 'does not fail if the homepage does not support HEAD' do
WebMock::API.stub_request(:head, /page/).to_return(:status => 405) WebMock::API.stub_request(:head, /page/).to_return(:status => 405)
WebMock::API.stub_request(:get, /page/).to_return(:status => 200) WebMock::API.stub_request(:get, /page/).to_return(:status => 200)
Specification.any_instance.stubs(:homepage).returns('http://banana-corp.local/page/') Specification.any_instance.stubs(:homepage).returns('http://banana-corp.local/page/')
@sut.validate @validator.validate
@sut.results.length.should.equal 0 @validator.results.length.should.equal 0
end end
it 'does not fail if the homepage errors on HEAD' do it 'does not fail if the homepage errors on HEAD' do
WebMock::API.stub_request(:head, /page/).to_return(:status => 500) WebMock::API.stub_request(:head, /page/).to_return(:status => 500)
WebMock::API.stub_request(:get, /page/).to_return(:status => 200) WebMock::API.stub_request(:get, /page/).to_return(:status => 200)
Specification.any_instance.stubs(:homepage).returns('http://banana-corp.local/page/') Specification.any_instance.stubs(:homepage).returns('http://banana-corp.local/page/')
@sut.validate @validator.validate
@sut.results.length.should.equal 0 @validator.results.length.should.equal 0
end end
it 'does not follow redirects infinitely' do it 'does not follow redirects infinitely' do
...@@ -153,8 +153,8 @@ module Pod ...@@ -153,8 +153,8 @@ module Pod
:headers => { 'Location' => 'http://banana-corp.local/redirect/' }) :headers => { 'Location' => 'http://banana-corp.local/redirect/' })
Specification.any_instance.stubs(:homepage).returns( Specification.any_instance.stubs(:homepage).returns(
'http://banana-corp.local/redirect/') 'http://banana-corp.local/redirect/')
@sut.validate @validator.validate
@sut.results.map(&:to_s).first.should.match /The URL \(.*\) is not reachable/ @validator.results.map(&:to_s).first.should.match /The URL \(.*\) is not reachable/
end end
it 'supports relative redirects' do it 'supports relative redirects' do
...@@ -165,14 +165,14 @@ module Pod ...@@ -165,14 +165,14 @@ module Pod
:status => 200) :status => 200)
Specification.any_instance.stubs(:homepage).returns( Specification.any_instance.stubs(:homepage).returns(
'http://banana-corp.local/redirect') 'http://banana-corp.local/redirect')
@sut.validate @validator.validate
@sut.results.length.should.equal 0 @validator.results.length.should.equal 0
end end
end end
describe 'Screenshot validation' do describe 'Screenshot validation' do
before do before do
@sut.stubs(:validate_homepage) @validator.stubs(:validate_homepage)
WebMock::API. WebMock::API.
stub_request(:head, 'banana-corp.local/valid-image.png'). stub_request(:head, 'banana-corp.local/valid-image.png').
to_return( to_return(
...@@ -184,101 +184,101 @@ module Pod ...@@ -184,101 +184,101 @@ module Pod
it 'checks if the screenshots are valid' do it 'checks if the screenshots are valid' do
Specification.any_instance.stubs(:screenshots). Specification.any_instance.stubs(:screenshots).
returns(['http://banana-corp.local/valid-image.png']) returns(['http://banana-corp.local/valid-image.png'])
@sut.validate @validator.validate
@sut.results.should.be.empty? @validator.results.should.be.empty?
end end
it 'should fail if any of the screenshots URLS do not return an image' do it 'should fail if any of the screenshots URLS do not return an image' do
WebMock::API.stub_request(:head, 'banana-corp.local/').to_return(:status => 200) WebMock::API.stub_request(:head, 'banana-corp.local/').to_return(:status => 200)
Specification.any_instance.stubs(:screenshots).returns(['http://banana-corp.local/valid-image.png', 'http://banana-corp.local/']) Specification.any_instance.stubs(:screenshots).returns(['http://banana-corp.local/valid-image.png', 'http://banana-corp.local/'])
@sut.validate @validator.validate
@sut.results.map(&:to_s).first.should.match /The screenshot .* is not a valid image/ @validator.results.map(&:to_s).first.should.match /The screenshot .* is not a valid image/
end end
end end
describe 'social media URL validation' do describe 'social media URL validation' do
before do before do
@sut.stubs(:validate_homepage) @validator.stubs(:validate_homepage)
end end
it 'checks if the social media URL is valid' do it 'checks if the social media URL is valid' do
Specification.any_instance.stubs(:social_media_url).returns('http://banana-corp.local/') Specification.any_instance.stubs(:social_media_url).returns('http://banana-corp.local/')
WebMock::API.stub_request(:head, /banana-corp.local/).to_return(:status => 200) WebMock::API.stub_request(:head, /banana-corp.local/).to_return(:status => 200)
@sut.validate @validator.validate
@sut.results.should.be.empty? @validator.results.should.be.empty?
end end
it "should fail validation if it wasn't able to validate the URL" do it "should fail validation if it wasn't able to validate the URL" do
Specification.any_instance.stubs(:social_media_url).returns('http://banana-corp.local/not-found/') Specification.any_instance.stubs(:social_media_url).returns('http://banana-corp.local/not-found/')
WebMock::API.stub_request(:head, /banana-corp.local/).to_return(:status => 404) WebMock::API.stub_request(:head, /banana-corp.local/).to_return(:status => 404)
@sut.validate @validator.validate
@sut.results.map(&:to_s).first.should.match /The URL \(.*\) is not reachable/ @validator.results.map(&:to_s).first.should.match /The URL \(.*\) is not reachable/
end end
end end
describe 'documentation URL validation' do describe 'documentation URL validation' do
before do before do
@sut.stubs(:validate_homepage) @validator.stubs(:validate_homepage)
end end
it 'checks if the documentation URL is valid' do it 'checks if the documentation URL is valid' do
Specification.any_instance.stubs(:documentation_url).returns('http://banana-corp.local/') Specification.any_instance.stubs(:documentation_url).returns('http://banana-corp.local/')
WebMock::API.stub_request(:head, /banana-corp.local/).to_return(:status => 200) WebMock::API.stub_request(:head, /banana-corp.local/).to_return(:status => 200)
@sut.validate @validator.validate
@sut.results.should.be.empty? @validator.results.should.be.empty?
end end
it "should fail validation if it wasn't able to validate the URL" do it "should fail validation if it wasn't able to validate the URL" do
Specification.any_instance.stubs(:documentation_url).returns('http://banana-corp.local/not-found') Specification.any_instance.stubs(:documentation_url).returns('http://banana-corp.local/not-found')
@sut.validate @validator.validate
@sut.results.map(&:to_s).first.should.match /The URL (.*) is not reachable/ @validator.results.map(&:to_s).first.should.match /The URL (.*) is not reachable/
end end
end end
describe 'docset URL validation' do describe 'docset URL validation' do
before do before do
@sut.stubs(:validate_homepage) @validator.stubs(:validate_homepage)
end end
it 'checks if the docset URL is valid' do it 'checks if the docset URL is valid' do
Specification.any_instance.stubs(:docset_url).returns('http://banana-corp.local/') Specification.any_instance.stubs(:docset_url).returns('http://banana-corp.local/')
WebMock::API.stub_request(:head, /banana-corp.local/).to_return(:status => 200) WebMock::API.stub_request(:head, /banana-corp.local/).to_return(:status => 200)
@sut.validate @validator.validate
@sut.results.should.be.empty? @validator.results.should.be.empty?
end end
it "should fail validation if it wasn't able to validate the URL" do it "should fail validation if it wasn't able to validate the URL" do
Specification.any_instance.stubs(:docset_url).returns('http://banana-corp.local/not-found') Specification.any_instance.stubs(:docset_url).returns('http://banana-corp.local/not-found')
@sut.validate @validator.validate
@sut.results.map(&:to_s).first.should.match /The URL (.*) is not reachable/ @validator.results.map(&:to_s).first.should.match /The URL (.*) is not reachable/
end end
end end
end end
it 'respects the no clean option' do it 'respects the no clean option' do
file = write_podspec(stub_podspec) file = write_podspec(stub_podspec)
sut = Validator.new(file, SourcesManager.master.map(&:url)) validator = Validator.new(file, SourcesManager.master.map(&:url))
sut.stubs(:validate_url) validator.stubs(:validate_url)
sut.no_clean = true validator.no_clean = true
sut.validate validator.validate
sut.validation_dir.should.exist validator.validation_dir.should.exist
end end
it 'builds the pod per platform' do it 'builds the pod per platform' do
file = write_podspec(stub_podspec) file = write_podspec(stub_podspec)
sut = Validator.new(file, SourcesManager.master.map(&:url)) validator = Validator.new(file, SourcesManager.master.map(&:url))
sut.stubs(:validate_url) validator.stubs(:validate_url)
sut.expects(:install_pod).twice validator.expects(:install_pod).twice
sut.expects(:build_pod).twice validator.expects(:build_pod).twice
sut.expects(:check_file_patterns).twice validator.expects(:check_file_patterns).twice
sut.validate validator.validate
end end
it 'uses the deployment target of the specification' do it 'uses the deployment target of the specification' do
sut = Validator.new(podspec_path, SourcesManager.master.map(&:url)) validator = Validator.new(podspec_path, SourcesManager.master.map(&:url))
sut.stubs(:validate_url) validator.stubs(:validate_url)
sut.stubs(:validate_screenshots) validator.stubs(:validate_screenshots)
podfile = sut.send(:podfile_from_spec, :ios, '5.0') podfile = validator.send(:podfile_from_spec, :ios, '5.0')
dependency = podfile.target_definitions['Pods'].dependencies.first dependency = podfile.target_definitions['Pods'].dependencies.first
dependency.external_source.key?(:podspec).should.be.true dependency.external_source.key?(:podspec).should.be.true
end end
...@@ -303,12 +303,12 @@ module Pod ...@@ -303,12 +303,12 @@ module Pod
describe '#podfile_from_spec' do describe '#podfile_from_spec' do
before do before do
@sut = Validator.new(podspec_path, SourcesManager.master.map(&:url)) @validator = Validator.new(podspec_path, SourcesManager.master.map(&:url))
@sut.stubs(:validate_url) @validator.stubs(:validate_url)
end end
it 'configures the deployment target' do it 'configures the deployment target' do
podfile = @sut.send(:podfile_from_spec, :ios, '5.0') podfile = @validator.send(:podfile_from_spec, :ios, '5.0')
target_definition = podfile.target_definitions['Pods'] target_definition = podfile.target_definitions['Pods']
platform = target_definition.platform platform = target_definition.platform
platform.symbolic_name.should == :ios platform.symbolic_name.should == :ios
...@@ -316,13 +316,13 @@ module Pod ...@@ -316,13 +316,13 @@ module Pod
end end
it 'includes the use_frameworks! directive' do it 'includes the use_frameworks! directive' do
podfile = @sut.send(:podfile_from_spec, :ios, '5.0', true) podfile = @validator.send(:podfile_from_spec, :ios, '5.0', true)
target_definition = podfile.target_definitions['Pods'] target_definition = podfile.target_definitions['Pods']
target_definition.uses_frameworks?.should == true target_definition.uses_frameworks?.should == true
end end
it 'includes the use_frameworks!(false) directive' do it 'includes the use_frameworks!(false) directive' do
podfile = @sut.send(:podfile_from_spec, :ios, '5.0', false) podfile = @validator.send(:podfile_from_spec, :ios, '5.0', false)
target_definition = podfile.target_definitions['Pods'] target_definition = podfile.target_definitions['Pods']
(!!target_definition.uses_frameworks?).should == false (!!target_definition.uses_frameworks?).should == false
end end
...@@ -330,74 +330,74 @@ module Pod ...@@ -330,74 +330,74 @@ module Pod
it 'repects the source_urls parameter' do it 'repects the source_urls parameter' do
sources = %w(https://github.com/CocoaPods/Specs.git https://github.com/artsy/Specs.git) sources = %w(https://github.com/CocoaPods/Specs.git https://github.com/artsy/Specs.git)
sut = Validator.new(podspec_path, sources) validator = Validator.new(podspec_path, sources)
sut.stubs(:validate_url) validator.stubs(:validate_url)
podfile = sut.send(:podfile_from_spec, :ios, '5.0') podfile = validator.send(:podfile_from_spec, :ios, '5.0')
podfile.sources.should == sources podfile.sources.should == sources
end end
it 'uses xcodebuild to generate notes and warnings' do it 'uses xcodebuild to generate notes and warnings' do
sut = Validator.new(podspec_path, SourcesManager.master.map(&:url)) validator = Validator.new(podspec_path, SourcesManager.master.map(&:url))
sut.stubs(:check_file_patterns) validator.stubs(:check_file_patterns)
sut.stubs(:xcodebuild).returns("file.m:1:1: warning: direct access to objective-c's isa is deprecated") validator.stubs(:xcodebuild).returns("file.m:1:1: warning: direct access to objective-c's isa is deprecated")
sut.stubs(:validate_url) validator.stubs(:validate_url)
sut.validate validator.validate
first = sut.results.map(&:to_s).first first = validator.results.map(&:to_s).first
first.should.include '[xcodebuild]' first.should.include '[xcodebuild]'
sut.result_type.should == :note validator.result_type.should == :note
end end
it 'checks if xcodebuild returns a successful status code' do it 'checks if xcodebuild returns a successful status code' do
Validator.any_instance.unstub(:xcodebuild) Validator.any_instance.unstub(:xcodebuild)
sut = Validator.new(podspec_path, SourcesManager.master.map(&:url)) validator = Validator.new(podspec_path, SourcesManager.master.map(&:url))
sut.stubs(:check_file_patterns) validator.stubs(:check_file_patterns)
sut.stubs(:validate_url) validator.stubs(:validate_url)
sut.stubs(:`).returns('Output') validator.stubs(:`).returns('Output')
$?.stubs(:success?).returns(false) $?.stubs(:success?).returns(false)
sut.validate validator.validate
first = sut.results.map(&:to_s).first first = validator.results.map(&:to_s).first
first.should.include '[xcodebuild] Returned a unsuccessful exit code' first.should.include '[xcodebuild] Returned a unsuccessful exit code'
sut.result_type.should == :error validator.result_type.should == :error
end end
it 'does filter InputFile errors completely' do it 'does filter InputFile errors completely' do
sut = Validator.new(podspec_path, SourcesManager.master.map(&:url)) validator = Validator.new(podspec_path, SourcesManager.master.map(&:url))
sut.stubs(:check_file_patterns) validator.stubs(:check_file_patterns)
sut.stubs(:xcodebuild).returns("2014-10-01 06:27:36.693 xcodebuild[61207:2007] error: InputFile Target Support Files/Pods-OneUpFoundation/Pods-OneUpFoundation-prefix.pch 0 1412159238 77 33188... malformed line 10; 'InputFile' should have exactly five arguments") validator.stubs(:xcodebuild).returns("2014-10-01 06:27:36.693 xcodebuild[61207:2007] error: InputFile Target Support Files/Pods-OneUpFoundation/Pods-OneUpFoundation-prefix.pch 0 1412159238 77 33188... malformed line 10; 'InputFile' should have exactly five arguments")
sut.stubs(:validate_url) validator.stubs(:validate_url)
sut.validate validator.validate
sut.results.count.should == 0 validator.results.count.should == 0
end end
describe 'file pattern validation' do describe 'file pattern validation' do
it 'checks for file patterns' do it 'checks for file patterns' do
file = write_podspec(stub_podspec(/.*source_files.*/, '"source_files": "wrong_paht.*",')) file = write_podspec(stub_podspec(/.*source_files.*/, '"source_files": "wrong_paht.*",'))
sut = Validator.new(file, SourcesManager.master.map(&:url)) validator = Validator.new(file, SourcesManager.master.map(&:url))
sut.stubs(:build_pod) validator.stubs(:build_pod)
sut.stubs(:validate_url) validator.stubs(:validate_url)
sut.validate validator.validate
sut.results.map(&:to_s).first.should.match /source_files.*did not match/ validator.results.map(&:to_s).first.should.match /source_files.*did not match/
sut.result_type.should == :error validator.result_type.should == :error
end end
it 'checks private_header_files matches only headers' do it 'checks private_header_files matches only headers' do
file = write_podspec(stub_podspec(/.*source_files.*/, '"source_files": "JSONKit.*", "private_header_files": "JSONKit.m",')) file = write_podspec(stub_podspec(/.*source_files.*/, '"source_files": "JSONKit.*", "private_header_files": "JSONKit.m",'))
sut = Validator.new(file, SourcesManager.master.map(&:url)) validator = Validator.new(file, SourcesManager.master.map(&:url))
sut.stubs(:build_pod) validator.stubs(:build_pod)
sut.stubs(:validate_url) validator.stubs(:validate_url)
sut.validate validator.validate
sut.results.map(&:to_s).first.should.match /matches non-header files \(JSONKit\.m\)/ validator.results.map(&:to_s).first.should.match /matches non-header files \(JSONKit\.m\)/
sut.result_type.should == :error validator.result_type.should == :error
end end
it 'checks public_header_files matches only headers' do it 'checks public_header_files matches only headers' do
file = write_podspec(stub_podspec(/.*source_files.*/, '"source_files": "JSONKit.*", "public_header_files": "JSONKit.m",')) file = write_podspec(stub_podspec(/.*source_files.*/, '"source_files": "JSONKit.*", "public_header_files": "JSONKit.m",'))
sut = Validator.new(file, SourcesManager.master.map(&:url)) validator = Validator.new(file, SourcesManager.master.map(&:url))
sut.stubs(:build_pod) validator.stubs(:build_pod)
sut.stubs(:validate_url) validator.stubs(:validate_url)
sut.validate validator.validate
sut.results.map(&:to_s).first.should.match /matches non-header files \(JSONKit\.m\)/ validator.results.map(&:to_s).first.should.match /matches non-header files \(JSONKit\.m\)/
sut.result_type.should == :error validator.result_type.should == :error
end end
end end
...@@ -408,11 +408,11 @@ module Pod ...@@ -408,11 +408,11 @@ module Pod
file = write_podspec(podspec, 'ZKit.podspec.json') file = write_podspec(podspec, 'ZKit.podspec.json')
spec = Specification.from_file(file) spec = Specification.from_file(file)
sut = Validator.new(spec, SourcesManager.master.map(&:url)) validator = Validator.new(spec, SourcesManager.master.map(&:url))
sut.stubs(:validate_url) validator.stubs(:validate_url)
sut.stubs(:build_pod) validator.stubs(:build_pod)
sut.validate validator.validate
sut.validated?.should.be.true validator.validated?.should.be.true
end end
end end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment