From d1ef7c739c7fc92e603d581491cc152bea5105d3 Mon Sep 17 00:00:00 2001 From: Fabio Pelosin Date: Fri, 23 Nov 2012 20:44:02 +0100 Subject: [PATCH] [Specs] Fix for master repo update & small performance improvements. --- lib/cocoapods/command/push.rb | 2 +- lib/cocoapods/command/repo.rb | 2 + .../test_repo/BananaLib/1.0/BananaLib.podspec | 1 - spec/functional/command/list_spec.rb | 39 ++-- spec/functional/command/push_spec.rb | 74 ++++--- spec/functional/command/repo_spec.rb | 202 +++++++++--------- spec/functional/command/setup_spec.rb | 39 ++-- spec/functional/user_interface_spec.rb | 7 +- spec/integration_spec.rb | 24 ++- spec/spec_helper/temporary_repos.rb | 86 +++++--- spec/unit/resolver_spec.rb | 17 +- spec/unit/source_spec.rb | 4 +- 12 files changed, 256 insertions(+), 241 deletions(-) diff --git a/lib/cocoapods/command/push.rb b/lib/cocoapods/command/push.rb index 09358d0..01e6123 100644 --- a/lib/cocoapods/command/push.rb +++ b/lib/cocoapods/command/push.rb @@ -82,7 +82,7 @@ module Pod lint_argv = ["lint"] lint_argv << "--only-errors" if @allow_warnings lint_argv << "--silent" if config.silent - all_valid = true + # all_valid = true podspec_files.each do |podspec| Spec.new(ARGV.new(lint_argv + [podspec.to_s])).run end diff --git a/lib/cocoapods/command/repo.rb b/lib/cocoapods/command/repo.rb index 669078b..906e0f3 100644 --- a/lib/cocoapods/command/repo.rb +++ b/lib/cocoapods/command/repo.rb @@ -153,6 +153,8 @@ module Pod is_compatilbe(versions) end + #--------------------------------------# + private def versions(dir) diff --git a/spec/fixtures/spec-repos/test_repo/BananaLib/1.0/BananaLib.podspec b/spec/fixtures/spec-repos/test_repo/BananaLib/1.0/BananaLib.podspec index 0c40f04..aff4db5 100644 --- a/spec/fixtures/spec-repos/test_repo/BananaLib/1.0/BananaLib.podspec +++ b/spec/fixtures/spec-repos/test_repo/BananaLib/1.0/BananaLib.podspec @@ -8,7 +8,6 @@ Pod::Spec.new do |s| s.source = { :git => 'http://banana-corp.local/banana-lib.git', :tag => 'v1.0' } s.source_files = 'Classes/*.{h,m}', 'Vendor' s.xcconfig = { 'OTHER_LDFLAGS' => '-framework SystemConfiguration' } - s.clean_paths = "sub-dir" s.prefix_header_file = 'Classes/BananaLib.pch' s.resources = "Resources/*.png" s.dependency 'monkey', '~> 1.0.1', '< 1.0.9' diff --git a/spec/functional/command/list_spec.rb b/spec/functional/command/list_spec.rb index b50f349..997bee2 100644 --- a/spec/functional/command/list_spec.rb +++ b/spec/functional/command/list_spec.rb @@ -2,41 +2,36 @@ require File.expand_path('../../../spec_helper', __FILE__) describe "Pod::Command::List" do extend SpecHelper::TemporaryRepos + extend SpecHelper::TemporaryDirectory def command(arguments = argv) command = Pod::Command::List.new(arguments) end - it "complains for wrong parameters" do - lambda { command(argv('wrong')).run }.should.raise Pod::Command::Help - lambda { command(argv('--wrong')).run }.should.raise Pod::Command::Help + before do + set_up_test_repo + config.repos_dir = SpecHelper.tmp_repos_path end it "presents the known pods" do - list = command() - list.run - [ /ZBarSDK/, - /TouchJSON/, - /SDURLCache/, - /MagicalRecord/, - /A2DynamicDelegate/, + command.run + Pod::UI.output + [ /BananaLib/, + /JSONKit/, /\d+ pods were found/ ].each { |regex| Pod::UI.output.should =~ regex } end it "returns the new pods" do - Time.stubs(:now).returns(Time.mktime(2012,2,3)) - list = command(argv('new')) - list.run - [ 'iCarousel', - 'libPusher', - 'SSCheckBoxView', - 'KKPasscodeLock', - 'SOCKit', - 'FileMD5Hash', - 'cocoa-oauth', - 'iRate' - ].each {|s| Pod::UI.output.should.include s } + sets = Pod::Source.all_sets + jsonkit_set = sets.find { |s| s.name == 'JSONKit' } + dates = { + 'BananaLib' => Time.now, + 'JSONKit' => Time.parse('01/01/1970') } + Pod::Specification::Statistics.any_instance.stubs(:creation_dates).returns(dates) + command(argv('new')).run + Pod::UI.output.should.include('BananaLib') + Pod::UI.output.should.not.include('JSONKit') end end diff --git a/spec/functional/command/push_spec.rb b/spec/functional/command/push_spec.rb index 22da44a..1935dd2 100644 --- a/spec/functional/command/push_spec.rb +++ b/spec/functional/command/push_spec.rb @@ -9,72 +9,70 @@ describe Pod::Command::Push do config.repos_dir = SpecHelper.tmp_repos_path end - def master_repo - fixture('spec-repos/master') - end - - it "complains for wrong parameters" do - lambda { run_command('push') }.should.raise Pod::Command::Help - lambda { run_command('push', '--allow-warnings') }.should.raise Pod::Command::Help - lambda { run_command('push', '--wrong-option') }.should.raise Pod::Command::Help - end - it "complains if it can't find the repo" do - repo1 = add_repo('repo1', master_repo) Dir.chdir(fixture('banana-lib')) do - lambda { run_command('push', 'repo2') }.should.raise Pod::Informative + cmd = command('push', 'missing_repo') + cmd.expects(:validate_podspec_files).returns(true) + e = lambda { cmd.run }.should.raise Pod::Informative + e.message.should.match(/repo not found/) end end it "complains if it can't find a spec" do - repo1 = add_repo('repo1', master_repo) - lambda { run_command('push', 'repo1') }.should.raise Pod::Informative + repo_make('test_repo') + e = lambda { run_command('push', 'test_repo') }.should.raise Pod::Informative + e.message.should.match(/Couldn't find any .podspec/) end - it "it raises if the pod is not validated" do - repo1 = add_repo('repo1', master_repo) - repo2 = add_repo('repo2', repo1.dir) - git_config('repo2', 'remote.origin.url').should == (tmp_repos_path + 'repo1').to_s - Dir.chdir(fixture('banana-lib')) do - lambda { command('push', 'repo2', '--silent').run }.should.raise Pod::Informative + # TODO: the validation should not use the pod spec command + xit "it raises if the specification doesn't validates" do + repo_make('test_repo') + Dir.chdir(temporary_directory) do + spec = "Spec.new do |s|; s.name = 'Broken'; end" + File.open('Broken.podspec', 'w') {|f| f.write(spec) } + cmd = command('push', 'test_repo') + cmd.expects(:validate_podspec_files).returns(true) + e = lambda { cmd.run }.should.raise Pod::Informative + e.message.should.match(/repo not clean/) end - # (repo1.dir + 'BananaLib/1.0/BananaLib.podspec').read.should.include 'Added!' end + before do - # prepare the repos - @upstream = add_repo('upstream', master_repo) - @local_repo = add_repo('local_repo', @upstream.dir) - git_config('local_repo', 'remote.origin.url').should == (tmp_repos_path + 'upstream').to_s + repo_make('upstream') + repo_clone('upstream', 'local_repo') # prepare the spec spec = (fixture('spec-repos') + 'master/JSONKit/1.4/JSONKit.podspec').read spec_fix = spec.gsub(/https:\/\/github\.com\/johnezang\/JSONKit\.git/, fixture('integration/JSONKit').to_s) spec_add = spec.gsub(/'JSONKit'/, "'PushTest'") - File.open(temporary_directory + 'JSONKit.podspec', 'w') {|f| f.write(spec_fix) } + File.open(temporary_directory + 'JSONKit.podspec', 'w') {|f| f.write(spec_fix) } File.open(temporary_directory + 'PushTest.podspec', 'w') {|f| f.write(spec_add) } end it "refuses to push if the repo is not clean" do - File.open(@local_repo.dir + 'README', 'w') {|f| f.write('Added!') } - (@local_repo.dir + 'README').read.should.include 'Added!' - cmd = command('push', 'local_repo') - cmd.expects(:validate_podspec_files).returns(true) - Dir.chdir(temporary_directory) { lambda { cmd.run }.should.raise Pod::Informative } - - (@upstream.dir + 'PushTest/1.4/PushTest.podspec').should.not.exist? + repo_make_readme_change('local_repo', 'dirty') + Dir.chdir(temporary_directory) do + cmd = command('push', 'local_repo') + cmd.expects(:validate_podspec_files).returns(true) + e = lambda { cmd.run }.should.raise Pod::Informative + e.message.should.match(/repo not clean/) + end + (repo_path('upstream') + 'PushTest/1.4/PushTest.podspec').should.not.exist? end - it "sucessfully pushes a spec" do - git('upstream', 'checkout master') # checkout master, to allow push in a non-bare repository + it "sucessfully pushes a spec" do cmd = command('push', 'local_repo') + Dir.chdir(repo_path 'upstream') { `git checkout -b tmp_for_push -q` } cmd.expects(:validate_podspec_files).returns(true) Dir.chdir(temporary_directory) { cmd.run } Pod::UI.output.should.include('[Add] PushTest (1.4)') - Pod::UI.output.should.include('[Fix] JSONKit (1.4)') + Pod::UI.output.should.include('[Add] JSONKit (1.4)') + # TODO check the commit messages + # Pod::UI.output.should.include('[Fix] JSONKit (1.4)') - git('upstream', 'checkout test') # checkout because test because is it the branch used in the specs. - (@upstream.dir + 'PushTest/1.4/PushTest.podspec').read.should.include('PushTest') + Dir.chdir(repo_path 'upstream') { `git checkout master -q` } + (repo_path('upstream') + 'PushTest/1.4/PushTest.podspec').read.should.include('PushTest') end end diff --git a/spec/functional/command/repo_spec.rb b/spec/functional/command/repo_spec.rb index f647be1..c17cb74 100644 --- a/spec/functional/command/repo_spec.rb +++ b/spec/functional/command/repo_spec.rb @@ -1,123 +1,115 @@ require File.expand_path('../../../spec_helper', __FILE__) -describe "Pod::Command::Repo" do +module Pod + describe Command::Repo do + describe "In general" do + extend SpecHelper::Command + extend SpecHelper::TemporaryDirectory + extend SpecHelper::TemporaryRepos - before do - config.repos_dir = SpecHelper.tmp_repos_path - end - - describe "In general" do - extend SpecHelper::Command - extend SpecHelper::TemporaryDirectory - extend SpecHelper::TemporaryRepos - - it "runs with correct parameters" do - lambda { run_command('repo', 'update') }.should.not.raise - lambda { run_command('repo', 'lint', temporary_directory.to_s) }.should.not.raise - end - - it "complains for wrong parameters" do - lambda { run_command('repo', 'add') }.should.raise Pod::Informative - lambda { run_command('repo', 'add', 'NAME') }.should.raise Pod::Informative - end - - it "adds a spec-repo" do - run_command('repo', 'add', 'private', fixture('spec-repos/master')) - git_config('private', 'remote.origin.url').should == fixture('spec-repos/master').to_s - end - - it "adds a spec-repo with on a specified branch" do - repo1 = add_repo('repo1', fixture('spec-repos/master')) - Dir.chdir(repo1.dir) do - `git checkout -b my-branch >/dev/null 2>&1` - `git checkout master >/dev/null 2>&1` + before do + set_up_test_repo + config.repos_dir = SpecHelper.tmp_repos_path + end + + it "updates a repository" do + upstream = SpecHelper.temporary_directory + 'upstream' + FileUtils.cp_r(test_repo_path, upstream) + Dir.chdir(test_repo_path) do + `git remote add origin #{upstream}` + `git remote -v` + `git fetch -q` + `git branch --set-upstream master origin/master` + end + lambda { command('repo', 'update').run }.should.not.raise + end + + it "lints a repository" do + lambda { run_command('repo', 'lint', temporary_directory.to_s) }.should.not.raise + end + + it "complains for wrong parameters" do + lambda { run_command('repo', 'add') }.should.raise Informative + lambda { run_command('repo', 'add', 'NAME') }.should.raise Informative + end + + it "adds a spec-repo" do + run_command('repo', 'add', 'private', test_repo_path) + Dir.chdir(config.repos_dir + 'private') do + `git config --get remote.origin.url`.chomp.should == test_repo_path.to_s + end + end + + it "adds a spec-repo with a specified branch" do + repo1 = repo_make('repo1') + Dir.chdir(repo1) do + `git checkout -b my-branch >/dev/null 2>&1` + `git checkout master >/dev/null 2>&1` + end + repo2 = command( 'repo' ,'add', 'repo2', repo1.to_s, 'my-branch') + repo2.run + Dir.chdir(repo2.dir) { `git symbolic-ref HEAD` }.should.include? 'my-branch' + end + + it "updates a spec-repo" do + repo1 = repo_make('repo1') + repo2 = repo_clone('repo1', 'repo2') + repo_make_readme_change(repo1, 'Updated') + Dir.chdir(repo1) {`git commit -a -m "Update"`} + run_command('repo', 'update', 'repo2') + (repo2 + 'README').read.should.include 'Updated' end - repo2 = command( 'repo' ,'add', 'repo2', repo1.dir, 'my-branch') - repo2.run - Dir.chdir(repo2.dir) { `git symbolic-ref HEAD` }.should.include? 'my-branch' end - it "updates a spec-repo" do - repo1 = add_repo('repo1', fixture('spec-repos/master')) - repo2 = add_repo('repo2', repo1.dir) - make_change(repo1, 'repo1') - run_command('repo', 'update', 'repo2') - (repo2.dir + 'README').read.should.include 'Added!' - end + describe "CocoaPods version" do + extend SpecHelper::Command + extend SpecHelper::TemporaryDirectory + extend SpecHelper::TemporaryRepos - it "updates all the spec-repos" do - repo1 = add_repo('repo1', fixture('spec-repos/master')) - repo2 = add_repo('repo2', repo1.dir) - repo3 = add_repo('repo3', repo1.dir) - make_change(repo1, 'repo1') - run_command('repo', 'update') - (repo2.dir + 'README').read.should.include 'Added!' - (repo3.dir + 'README').read.should.include 'Added!' - end + require 'yaml' - before do - config.repos_dir = fixture('spec-repos') - end + before do + config.repos_dir = SpecHelper.tmp_repos_path + @repo = repo_make('repo1') + end - it "lints a repo" do - cmd = command('repo', 'lint', 'master') - lambda { cmd.run }.should.raise Pod::Informative - Pod::UI.output.should.include "Missing license type" - end - end + def write_version_file(hash) + yaml = YAML.dump(hash) + @versions_file = tmp_repos_path + "repo1/CocoaPods-version.yml" + File.open(@versions_file, 'w') {|f| f.write(yaml) } + end - describe "Concerning a repo support" do - extend SpecHelper::Command - extend SpecHelper::TemporaryDirectory - extend SpecHelper::TemporaryRepos + it "it doesn't requires CocoaPods-version.yml" do + cmd = command('repo', 'update') + lambda { cmd.check_versions(@repo) }.should.not.raise + end - before do - add_repo('repo1', fixture('spec-repos/master')) - FileUtils.rm_rf(versions_file) - versions_file.should.not.exist? - end + it "runs with a compatible repo" do + write_version_file({'min' => "0.0.1"}) + cmd = command('repo', 'update') + lambda { cmd.check_versions(@repo) }.should.not.raise + end - require 'yaml' + it "raises if a repo is not compatible" do + write_version_file({'min' => "999.0.0"}) + cmd = command('repo', 'update') + lambda { cmd.check_versions(@repo) }.should.raise Informative + end - def versions_file - tmp_repos_path + "repo1/CocoaPods-version.yml" - end + it "informs about a higher known CocoaPods version" do + write_version_file({'last' => "999.0.0"}) + cmd = command('repo', 'update') + cmd.check_versions(@repo) + UI.output.should.include "Cocoapods 999.0.0 is available" + end - def write_version_file(hash) - yaml = YAML.dump(hash) - File.open(versions_file, 'w') {|f| f.write(yaml) } - end + it "has a class method that returns if a repo is supported" do + write_version_file({'min' => "999.0.0"}) + Command::Repo.compatible?('repo1').should == false - it "it doesn't requires CocoaPods-version.yml" do - cmd = command('repo', 'update') - lambda { cmd.check_versions(versions_file.dirname) }.should.not.raise - end - - it "runs with a compatible repo" do - write_version_file({'min' => "0.0.1"}) - cmd = command('repo', 'update') - lambda { cmd.check_versions(versions_file.dirname) }.should.not.raise - end - - it "raises if a repo is not compatible" do - write_version_file({'min' => "999.0.0"}) - cmd = command('repo', 'update') - lambda { cmd.check_versions(versions_file.dirname) }.should.raise Pod::Informative - end - - it "informs about a higher known CocoaPods version" do - write_version_file({'last' => "999.0.0"}) - cmd = command('repo', 'update') - cmd.check_versions(versions_file.dirname) - Pod::UI.output.should.include "Cocoapods 999.0.0 is available" - end - - it "has a class method that returns if a repo is supported" do - write_version_file({'min' => "999.0.0"}) - Pod::Command::Repo.compatible?('repo1').should == false - - write_version_file({'min' => "0.0.1"}) - Pod::Command::Repo.compatible?('repo1').should == true + write_version_file({'min' => "0.0.1"}) + Command::Repo.compatible?('repo1').should == true + end end end end diff --git a/spec/functional/command/setup_spec.rb b/spec/functional/command/setup_spec.rb index 7a383a1..70ae1a6 100644 --- a/spec/functional/command/setup_spec.rb +++ b/spec/functional/command/setup_spec.rb @@ -1,7 +1,7 @@ require File.expand_path('../../../spec_helper', __FILE__) -describe "Pod::Command::Setup" do +describe Pod::Command::Setup do extend SpecHelper::Command extend SpecHelper::TemporaryDirectory extend SpecHelper::TemporaryRepos @@ -10,6 +10,23 @@ describe "Pod::Command::Setup" do config.repos_dir = SpecHelper.tmp_repos_path end + it "returns the read only URL of the `master` spec-repo" do + cmd = Pod::Command::Setup.new(argv) + cmd.url.should == 'https://github.com/CocoaPods/Specs.git' + end + + it "returns the push URL of the `master' spec-repo" do + config.silent = true + cmd = Pod::Command::Setup.new(argv('--push')) + cmd.url.should == 'git@github.com:CocoaPods/Specs.git' + end + + before do + set_up_test_repo + Pod::Command::Setup.any_instance.stubs(:read_only_url).returns(test_repo_path.to_s) + config.repos_dir = SpecHelper.temporary_directory + end + it "runs with correct parameters" do lambda { run_command('setup') }.should.not.raise end @@ -19,32 +36,18 @@ describe "Pod::Command::Setup" do lambda { run_command('setup', '--wrong') }.should.raise Pod::Command::Help end - it "returns the read only URL of the `master' spec-repo" do - cmd = Pod::Command::Setup.new(argv) - cmd.url.should == 'https://github.com/CocoaPods/Specs.git' - end - - it "returns the push URL of the `master' spec-repo" do - config.silent = true - cmd = Pod::Command::Setup.new(argv('--push')) - cmd.url.should == 'git@github.com:CocoaPods/Specs.git' - end - - class Pod::Command::Setup - def read_only_url; SpecHelper.fixture('spec-repos/master'); end - end - it "creates the local spec-repos directory and creates a clone of the `master' repo" do output = run_command('setup') output.should.include "Setup completed" output.should.not.include "push" - git_config('master', 'remote.origin.url').should == fixture('spec-repos/master').to_s + url = Dir.chdir(config.repos_dir + 'master') { `git config --get remote.origin.url`.chomp } + url.should == test_repo_path.to_s end it "preserves push access for the `master' repo" do output = run_command('setup') output.should.not.include "push" - git('master', 'remote set-url origin git@github.com:CocoaPods/Specs.git') + Dir.chdir(config.repos_dir + 'master') { `git remote set-url origin git@github.com:CocoaPods/Specs.git` } command('setup').url.should == 'git@github.com:CocoaPods/Specs.git' end diff --git a/spec/functional/user_interface_spec.rb b/spec/functional/user_interface_spec.rb index 5b545ac..3642042 100644 --- a/spec/functional/user_interface_spec.rb +++ b/spec/functional/user_interface_spec.rb @@ -15,17 +15,12 @@ describe Pod::UI do output.should.include? 'CocoaLumberjack' output.should.include? '1.0' output.should.include? '1.1' + output.should.include? '[master repo]' output.should.include? 'A fast & simple, yet powerful & flexible logging framework for Mac and iOS.' output.should.include? 'https://github.com/robbiehanson/CocoaLumberjack' output.should.include? 'https://github.com/robbiehanson/CocoaLumberjack.git' end - it "presents the name, version, description, homepage and source of a specification set" do - Pod::UI.pod(@set) - output = Pod::UI.output - output.should.include? 'Versions: 1.6, 1.3.3, 1.3.2, 1.3.1, 1.3, 1.2.3, 1.2.2, 1.2.1, 1.2, 1.1, 1.0 [master repo]' - end - it "presents the stats of a specification set" do repo = { "forks"=>42, "watchers"=>318, "pushed_at"=>"2011-01-26T19:06:43Z" } Octokit.expects(:repo).with("robbiehanson/CocoaLumberjack").returns(repo) diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 1ded9ef..7a7fc1b 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -196,15 +196,19 @@ else result = installer.lockfile.to_hash result['PODS'].should == [ - { "ASIHTTPRequest (1.8.1)" => ["ASIHTTPRequest/ASIWebPageRequest (= 1.8.1)", - "ASIHTTPRequest/CloudFiles (= 1.8.1)", - "ASIHTTPRequest/S3 (= 1.8.1)", - "Reachability"]}, - { "ASIHTTPRequest/ASIWebPageRequest (1.8.1)" => ["Reachability"] }, - { "ASIHTTPRequest/CloudFiles (1.8.1)" => ["Reachability"] }, - { "ASIHTTPRequest/S3 (1.8.1)" => ["Reachability"] }, - "JSONKit (1.4)", - "Reachability (3.0.0)"] + { "ASIHTTPRequest (1.8.1)" => + [ "ASIHTTPRequest/ASIWebPageRequest (= 1.8.1)", + "ASIHTTPRequest/CloudFiles (= 1.8.1)", + "ASIHTTPRequest/S3 (= 1.8.1)", + "Reachability" + ] + }, + { "ASIHTTPRequest/ASIWebPageRequest (1.8.1)" => ["Reachability"] }, + { "ASIHTTPRequest/CloudFiles (1.8.1)" => ["Reachability"] }, + { "ASIHTTPRequest/S3 (1.8.1)" => ["Reachability"] }, + "JSONKit (1.4)", + "Reachability (3.1.0)" + ] result['DEPENDENCIES'].should == ["ASIHTTPRequest", "JSONKit (= 1.4)"] # TODO might be nicer looking to not show the dependencies of the top level spec for each subspec (Reachability). @@ -304,7 +308,7 @@ else lockfile_contents = { 'PODS' => [ 'JSONKit (999.999.999)', - 'Reachability (3.0.0)', + 'Reachability (3.1.0)', 'SSZipArchive (0.1.1)', ], 'DEPENDENCIES' => [ diff --git a/spec/spec_helper/temporary_repos.rb b/spec/spec_helper/temporary_repos.rb index 604e63d..259f49d 100644 --- a/spec/spec_helper/temporary_repos.rb +++ b/spec/spec_helper/temporary_repos.rb @@ -1,5 +1,8 @@ require 'spec_helper/temporary_directory' +# Important +# Include with temporary directory + module SpecHelper def self.tmp_repos_path TemporaryRepos.tmp_repos_path @@ -9,41 +12,64 @@ module SpecHelper extend Pod::Executable executable :git + # @return [Pathname] The path for the repo with the given name. + # + def repo_path(name) + tmp_repos_path + name + end + + # Makes a repo with the given name. + # + def repo_make(name) + path = repo_path(name) + path.mkpath + Dir.chdir(path) do + `git init` + repo_make_readme_change(name, 'Added') + `git add .` + `git commit -m "Initialized."` + end + path + end + + # Clones a repo to the given name. + # + def repo_clone(from_name, to_name) + Dir.chdir(tmp_repos_path) { `git clone #{from_name} #{to_name}` } + repo_path(to_name) + end + + def repo_make_readme_change(name, string) + file = repo_path(name) + 'README' + file.open('w') { |f| f << "#{string}" } + end + + #--------------------------------------# + + def test_repo_path + repo_path('master') + end + + # Sets up a lighweight master repo in `tmp/cocoapods/master` with the + # contents of `spec/fixtures/spec-repos/test_repo`. + # + def set_up_test_repo + require 'fileutils' + test_repo_path.mkpath + origin = ROOT + 'spec/fixtures/spec-repos/test_repo/.' + destination = tmp_repos_path + 'master' + FileUtils.cp_r(origin, destination) + repo_make('master') + end + + #--------------------------------------# + def tmp_repos_path SpecHelper.temporary_directory + 'cocoapods' end + module_function :tmp_repos_path - alias_method :git_super, :git - def git(repo, command) - Dir.chdir(tmp_repos_path + repo) do - if output = git_super(command) - output.strip - end - end - end - - def git_config(repo, attr) - git repo, "config --get #{attr}" - end - - def add_repo(name, from) - command = command('repo', 'add', name, from) - command.run - # The test branch is used by the push specs - Dir.chdir(command.dir) do - `git checkout -b test >/dev/null 2>&1` - `git branch --set-upstream test origin/master >/dev/null 2>&1` - end - command - end - - def make_change(repo, name) - (repo.dir + 'README').open('w') { |f| f << 'Added!' } - git(name, 'add README') - git(name, 'commit -m "changed"') - end - def self.extended(base) base.before do tmp_repos_path.mkpath diff --git a/spec/unit/resolver_spec.rb b/spec/unit/resolver_spec.rb index 9ad8150..d4fbd0d 100644 --- a/spec/unit/resolver_spec.rb +++ b/spec/unit/resolver_spec.rb @@ -5,8 +5,8 @@ module Pod before do config.repos_dir = fixture('spec-repos') @podfile = Podfile.new do - platform :ios - pod 'BlocksKit' + platform :ios, '6.0' + pod 'BlocksKit', '1.8.0' end @resolver = Resolver.new(@podfile, nil, stub('sandbox')) end @@ -14,7 +14,6 @@ module Pod it "holds the context state, such as cached specification sets" do @resolver.resolve @resolver.cached_sets.values.sort_by(&:name).should == [ - Pod::Source.search_by_name('A2DynamicDelegate').first, Pod::Source.search_by_name('BlocksKit').first, Pod::Source.search_by_name('libffi').first ].sort_by(&:name) @@ -23,13 +22,13 @@ module Pod it "returns all specs needed for the dependency" do specs = @resolver.resolve.values.flatten specs.map(&:class).uniq.should == [Specification] - specs.map(&:name).sort.should == %w{ A2DynamicDelegate BlocksKit libffi } + specs.map(&:name).sort.should == %w{ BlocksKit libffi } end it "does not raise if all dependencies match the platform of the root spec (Podfile)" do - @podfile.platform :ios + @podfile.platform :ios, '6.0' lambda { @resolver.resolve }.should.not.raise - @podfile.platform :osx + @podfile.platform :osx, '10.7' lambda { @resolver.resolve }.should.not.raise end @@ -259,7 +258,7 @@ module Pod platform :ios pod 'JSONKit' pod 'BlocksKit' - pod 'libPusher' # New pod + pod 'libPusher', '1.3' # New pod end @resolver = Resolver.new(podfile, @lockfile, stub('sandbox')) installed = @resolver.resolve.values.flatten.map(&:to_s) @@ -348,7 +347,7 @@ module Pod before do config.repos_dir = fixture('spec-repos') @podfile = Podfile.new do - platform :ios + platform :ios, '6.0' pod 'BlocksKit' pod 'JSONKit' pod 'libPusher' @@ -376,7 +375,7 @@ module Pod it "respects the constraints of the podfile" do podfile = Podfile.new do - platform :ios + platform :ios, '6.0' pod 'BlocksKit' pod 'JSONKit', '1.4' end diff --git a/spec/unit/source_spec.rb b/spec/unit/source_spec.rb index e2bcc09..c340e21 100644 --- a/spec/unit/source_spec.rb +++ b/spec/unit/source_spec.rb @@ -16,7 +16,9 @@ describe "Pod::Source" do end it "returns the available versions of a Pod" do - @source.versions('Reachability').map(&:to_s).should == %w| 3.0.0 2.0.5 2.0.4 | + known = %w| 3.0.0 2.0.5 2.0.4 | + computed = @source.versions('Reachability').map(&:to_s) + (known - computed).should.be.empty? end it "returns the specification of a given version of a Pod" do