require File.expand_path('../spec_helper', __FILE__) WHITELIST_FILE = './spec/mocks/whitelist.json' module Pod describe Command::Whitelist do describe 'general' do it 'registers itself' do Command.parse(%w{ whitelist }).should.be.instance_of Command::Whitelist end it 'parse whitelist json' do command = Command.parse(['whitelist', "--config=#{WHITELIST_FILE}"]) dependencies = command.get_whitelist dependencies.size.should.equal 5 end end describe 'validations' do it 'dependency without version should not be valid' do # Whitelist: ('MeliSDK', '~>5.*') | Podspec: ('MeliSDK') command = Command.parse(['whitelist', "--config=#{WHITELIST_FILE}", "--fail-on-error"]) specification = Pod::Specification.from_file('./spec/mocks/without_version.podspec') command.expects(:get_podspec_specifications).returns([specification]) lambda { command.run }.should.raise Informative end it 'dependency with major version fixed should be valid' do # Whitelist: ('MeliSDK', '~>5.*') | Podspec: ('MeliSDK', '~>5.0') command = Command.parse(['whitelist', "--config=#{WHITELIST_FILE}", "--fail-on-error"]) specification = Pod::Specification.from_file('./spec/mocks/major_version_fixed.podspec') command.expects(:get_podspec_specifications).returns([specification]) lambda { command.run }.should.not.raise end # it 'dependency with incorrect name should not be valid' do # # Whitelist: ('MeliSDK', '~>5.*') | Podspec: ('Meli', '~>5.0') # command = Command.parse(['whitelist', "--config=#{WHITELIST_FILE}", "--fail-on-error"]) # specification = Pod::Specification.from_file('./spec/mocks/bad_name.podspec') # command.expects(:get_podspec_specifications).returns([specification]) # lambda { command.run }.should.raise Informative # end it 'not allowed dependency should not be valid' do command = Command.parse(['whitelist', "--config=#{WHITELIST_FILE}", "--fail-on-error"]) specification = Pod::Specification.from_file('./spec/mocks/not_allowed.podspec') command.expects(:get_podspec_specifications).returns([specification]) lambda { command.run }.should.raise Informative end it 'not allowed similar dependency should not be valid' do # Whitelist: ('MercadoPagoSDKV4', '~>5.*') | Podspec: ('MercadoPagoSDK') command = Command.parse(['whitelist', "--config=#{WHITELIST_FILE}", "--fail-on-error"]) specification = Pod::Specification.from_file('./spec/mocks/with_similar_name_not_allowed.podspec') command.expects(:get_podspec_specifications).returns([specification]) lambda { command.run }.should.raise Informative end it 'dependency with not allowed version should be valid' do command = Command.parse(['whitelist', "--config=#{WHITELIST_FILE}", "--fail-on-error"]) specification = Pod::Specification.from_file('./spec/mocks/with_fixed_version.podspec') command.expects(:get_podspec_specifications).returns([specification]) lambda { command.run }.should.raise Informative end it 'expired dependency should not be valid' do # Whitelist: ('MeliSDK', '~>5.*') | Podspec: ('AFNetworking') command = Command.parse(['whitelist', "--config=#{WHITELIST_FILE}", "--fail-on-error"]) specification = Pod::Specification.from_file('./spec/mocks/with_expired_dependencies.podspec') command.expects(:get_podspec_specifications).returns([specification]) lambda { command.run }.should.raise Informative end it 'not yet expired dependency should be valid' do # Whitelist: ('MeliSDK', '~>5.*') | Podspec: ('AFNetworking') command = Command.parse(['whitelist', "--config=#{WHITELIST_FILE}", "--fail-on-error"]) specification = Pod::Specification.from_file('./spec/mocks/with_not_yet_expired_dependencies.podspec') command.expects(:get_podspec_specifications).returns([specification]) lambda { command.run }.should.not.raise Informative end it 'dependency with two versions requierement should not be valid' do # Whitelist: ('MeliSDK', '~>5.*') | Podspec: ('AFNetworking') command = Command.parse(['whitelist', "--config=#{WHITELIST_FILE}", "--fail-on-error"]) specification = Pod::Specification.from_file('./spec/mocks/with_two_requirement.podspec') command.expects(:get_podspec_specifications).returns([specification]) lambda { command.run }.should.raise Informative end it 'dependency with two versions requierement should not be valid' do # Whitelist: ('MeliSDK', '~>5.*') | Podspec: ('AFNetworking') command = Command.parse(['whitelist', "--config=#{WHITELIST_FILE}", "--fail-on-error"]) specification = Pod::Specification.from_file('./spec/mocks/with_more_than_one_version_in_subspec.podspec') command.expects(:get_podspec_specifications).returns([specification]) lambda { command.run }.should.raise Informative end it 'dependency not allowed in subspec should not be valid' do # Whitelist: ('MeliSDK', '~>5.*') | Podspec: ('AFNetworking') command = Command.parse(['whitelist', "--config=#{WHITELIST_FILE}", "--fail-on-error"]) specification = Pod::Specification.from_file('./spec/mocks/with_not_allowed_in_subspec.podspec') command.expects(:get_podspec_specifications).returns([specification]) lambda { command.run }.should.raise Informative end it 'subspec dependency allowed in the whitelist should be valid' do # Whitelist: ('MeliSDK', '~>5.*') | Podspec: ('MeliSDK/Error') command = Command.parse(['whitelist', "--config=#{WHITELIST_FILE}", "--fail-on-error"]) specification = Pod::Specification.from_file('./spec/mocks/with_allowed_subspec.podspec') command.expects(:get_podspec_specifications).returns([specification]) lambda { command.run }.should.not.raise end it 'subspec dependency not allowed in the whitelist should not be valid' do # Whitelist: ('MeliSDK', '~>5.*') | Podspec: ('MyMeliSDK/Error') command = Command.parse(['whitelist', "--config=#{WHITELIST_FILE}", "--fail-on-error"]) specification = Pod::Specification.from_file('./spec/mocks/with_not_allowed_subspec.podspec') command.expects(:get_podspec_specifications).returns([specification]) lambda { command.run }.should.raise Informative end it 'podspec without dependencies should be valid' do # Whitelist: ('MeliSDK', '~>5.*') | Podspec: ('AFNetworking') command = Command.parse(['whitelist', "--config=#{WHITELIST_FILE}", "--fail-on-error"]) specification = Pod::Specification.from_file('./spec/mocks/without_dependencies.podspec') command.expects(:get_podspec_specifications).returns([specification]) lambda { command.run }.should.not.raise end it 'podspec with allowed dependencies in subspec should be valid' do # Whitelist: ('MeliSDK', '~>5.*') | Subspec: ('MeliSDK') command = Command.parse(['whitelist', "--config=#{WHITELIST_FILE}", "--fail-on-error"]) specification = Pod::Specification.from_file('./spec/mocks/with_allowed_in_subspec.podspec') command.expects(:get_podspec_specifications).returns([specification]) lambda { command.run }.should.not.raise end it 'podspec with dependency not restricted by version should be valid' do # Whitelist: ('MeliSDK', '~>5.*') | Podspec: ('MLRecommendations', '~>1.0.0') command = Command.parse(['whitelist', "--config=#{WHITELIST_FILE}", "--fail-on-error"]) specification = Pod::Specification.from_file('./spec/mocks/free_version.podspec') command.expects(:get_podspec_specifications).returns([specification]) lambda { command.run }.should.not.raise end it 'fixed mayor dependency in whitelist and podspec should not fail on first option' do # Whitelist: ('MLMyDependency', '1.0.0|2.0.0') | Podspec: ('MLMyDependency', '1.0.0') command = Command.parse(['whitelist', "--config=#{WHITELIST_FILE}", "--fail-on-error"]) specification = Pod::Specification.from_file('./spec/mocks/with_whitelisted_dependency_fixed_versions_v1.podspec') command.expects(:get_podspec_specifications).returns([specification]) lambda { command.run }.should.not.raise end it 'fixed mayor dependency in whitelist and podspec should not fail on second option' do # Whitelist: ('MLMyDependency', '1.0.0|2.0.0') | Podspec: ('MLMyDependency', '2.0.0') command = Command.parse(['whitelist', "--config=#{WHITELIST_FILE}", "--fail-on-error"]) specification = Pod::Specification.from_file('./spec/mocks/with_whitelisted_dependency_fixed_versions_v2.podspec') command.expects(:get_podspec_specifications).returns([specification]) lambda { command.run }.should.not.raise end it 'fixed mayor dependency in whitelist but not in podspec should fail' do # Whitelist: ('MLMyDependency', '1.0.0|2.0.0') | Podspec: ('MLMyDependency', '~> 1.0') command = Command.parse(['whitelist', "--config=#{WHITELIST_FILE}", "--fail-on-error"]) specification = Pod::Specification.from_file('./spec/mocks/with_whitelisted_dependency_fixed_versions_variable.podspec') command.expects(:get_podspec_specifications).returns([specification]) lambda { command.run }.should.raise Informative end it 'not allowed dependency should not raise exception if --fail-on-error is not present' do # Whitelist: ('MeliSDK', '~>5.*') | Podspec: ('AFNetworking') command = Command.parse(['whitelist', "--config=#{WHITELIST_FILE}", "--podspec=./spec/mocks/not_allowed.podspec"]) lambda { command.run }.should.not.raise end it 'should not fail when no podspecs are found' do command = Command.parse(['whitelist', "--config=#{WHITELIST_FILE}"]) lambda { command.run }.should.not.raise end end end end