From d51f5a069ef817aebd30a156654ef4c972341123 Mon Sep 17 00:00:00 2001 From: Eloy Duran Date: Mon, 2 Apr 2012 13:44:14 +0200 Subject: [PATCH] Make UserProjectIntegrator work again. --- .kick | 12 ++++++------ lib/cocoapods/command/install.rb | 4 ++-- lib/cocoapods/installer.rb | 6 +++--- .../installer/user_project_integrator.rb | 16 ++++++++++------ spec/functional/user_project_integrator_spec.rb | 12 ++++++++---- spec/integration_spec.rb | 7 +++++-- spec/unit/{ => command}/install_command_spec.rb | 11 ++++++----- .../installer/user_project_integrator_spec.rb | 10 ++++++---- 8 files changed, 46 insertions(+), 32 deletions(-) rename spec/unit/{ => command}/install_command_spec.rb (72%) diff --git a/.kick b/.kick index 6c25b799ff..ba565b2efd 100644 --- a/.kick +++ b/.kick @@ -4,12 +4,12 @@ Kicker::Recipes::Ruby.runner_bin = 'bacon' process do |files| specs = files.take_and_map do |file| - case file - when %r{lib/cocoapods/installer.+\.rb$} - ['spec/unit/installer_spec.rb', 'spec/unit/installer/target_installer_spec.rb'] - when %r{lib/cocoapods/(.+?)\.rb$} - s = Dir.glob("spec/**/#{$1}_spec.rb") - s unless s.empty? + if file =~ %r{lib/cocoapods/(.+?)\.rb$} + s = Dir.glob("spec/**/#{File.basename(file, '.rb')}_spec.rb") + if file =~ %r{lib/cocoapods/installer.+\.rb$} + s.concat(['spec/unit/installer_spec.rb', 'spec/unit/installer/target_installer_spec.rb']) + end + s.uniq unless s.empty? end end Kicker::Recipes::Ruby.run_tests(specs) diff --git a/lib/cocoapods/command/install.rb b/lib/cocoapods/command/install.rb index 479632f320..b78639aa9e 100644 --- a/lib/cocoapods/command/install.rb +++ b/lib/cocoapods/command/install.rb @@ -11,7 +11,7 @@ def self.banner The Xcode project file should be specified in your `Podfile` like this: - xcodeproj "path/to/project.xcodeproj" + xcodeproj 'path/to/project.xcodeproj' If no xcodeproj is specified, then a search for an Xcode project will be made. If more than one Xcode project is found, the command will @@ -59,7 +59,7 @@ def run Repo.new(ARGV.new(["update"])).run end - Installer.new(podfile, @projpath).install! + Installer.new(podfile).install! end end end diff --git a/lib/cocoapods/installer.rb b/lib/cocoapods/installer.rb index 4708025973..dd35510faf 100644 --- a/lib/cocoapods/installer.rb +++ b/lib/cocoapods/installer.rb @@ -9,8 +9,8 @@ class Installer attr_reader :sandbox - def initialize(podfile, user_project_path = nil) - @podfile, @user_project_path = podfile, user_project_path + def initialize(podfile) + @podfile = podfile # FIXME: pass this into the installer as a parameter @sandbox = Sandbox.new(config.project_pods_root) @resolver = Resolver.new(@podfile, @sandbox) @@ -91,7 +91,7 @@ def install! puts "* Writing Xcode project file to `#{@sandbox.project_path}'\n\n" if config.verbose? project.save_as(@sandbox.project_path) - UserProjectIntegrator.new(@podfile.xcodeproj, @podfile).integrate! + UserProjectIntegrator.new(@podfile).integrate! if @podfile.xcodeproj end def run_post_install_hooks diff --git a/lib/cocoapods/installer/user_project_integrator.rb b/lib/cocoapods/installer/user_project_integrator.rb index 61bc4a79e6..84c2bf6f4e 100644 --- a/lib/cocoapods/installer/user_project_integrator.rb +++ b/lib/cocoapods/installer/user_project_integrator.rb @@ -7,12 +7,8 @@ class Installer class UserProjectIntegrator include Pod::Config::Mixin - attr_reader :user_project_path, :user_project - - def initialize(user_project_path, podfile) - @user_project_path = config.project_root + user_project_path + def initialize(podfile) @podfile = podfile - @user_project = Xcodeproj::Project.new(user_project_path) end def integrate! @@ -21,7 +17,7 @@ def integrate! # Only need to write out the user's project if any of the target # integrators actually did some work. if targets.map(&:integrate!).any? - @user_project.save_as(user_project_path) + user_project.save_as(user_project_path) end unless config.silent? @@ -30,6 +26,14 @@ def integrate! end end + def user_project_path + @podfile.xcodeproj + end + + def user_project + @user_project ||= Xcodeproj::Project.new(user_project_path) + end + def workspace_path config.project_root + "#{user_project_path.basename('.xcodeproj')}.xcworkspace" end diff --git a/spec/functional/user_project_integrator_spec.rb b/spec/functional/user_project_integrator_spec.rb index 4abc1210bd..3a12fd82d0 100644 --- a/spec/functional/user_project_integrator_spec.rb +++ b/spec/functional/user_project_integrator_spec.rb @@ -4,10 +4,16 @@ extend SpecHelper::TemporaryDirectory before do + @sample_project_path = SpecHelper.create_sample_app_copy_from_fixture('SampleProject') + config.project_root = @sample_project_path.dirname + + sample_project_path = @sample_project_path @podfile = Pod::Podfile.new do platform :ios + xcodeproj sample_project_path link_with 'SampleProject' # this is an app target! + dependency 'JSONKit' target :test_runner, :exclusive => true do @@ -16,11 +22,9 @@ end end - @sample_project_path = SpecHelper.create_sample_app_copy_from_fixture('SampleProject') - config.project_root = @sample_project_path.dirname - - @integrator = Pod::Installer::UserProjectIntegrator.new(@sample_project_path, @podfile) + @integrator = Pod::Installer::UserProjectIntegrator.new(@podfile) @integrator.integrate! + @sample_project = Xcodeproj::Project.new(@sample_project_path) end diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 08ac8288cf..75128a7ebc 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -367,11 +367,14 @@ def should_xcodebuild(target_definition) basename = platform == :ios ? 'iPhone' : 'Mac' projpath = temporary_directory + 'ASIHTTPRequest.xcodeproj' FileUtils.cp_r(fixture("integration/ASIHTTPRequest/#{basename}.xcodeproj"), projpath) - spec = Pod::Podfile.new do + + podfile = Pod::Podfile.new do self.platform platform + xcodeproj projpath dependency 'SSZipArchive' end - installer = SpecHelper::Installer.new(spec, projpath) + + installer = SpecHelper::Installer.new(podfile) installer.install! workspace = Xcodeproj::Workspace.new_from_xcworkspace(temporary_directory + 'ASIHTTPRequest.xcworkspace') diff --git a/spec/unit/install_command_spec.rb b/spec/unit/command/install_command_spec.rb similarity index 72% rename from spec/unit/install_command_spec.rb rename to spec/unit/command/install_command_spec.rb index f7282fd068..451d017af3 100644 --- a/spec/unit/install_command_spec.rb +++ b/spec/unit/command/install_command_spec.rb @@ -1,8 +1,8 @@ -require File.expand_path('../../spec_helper', __FILE__) +require File.expand_path('../../../spec_helper', __FILE__) describe "Pod::Command::Install" do it "should include instructions on how to reference the xcode project" do - Pod::Command::Install.banner.should.match /xcodeproj path\/to\/project.xcodeproj/ + Pod::Command::Install.banner.should.match %r{xcodeproj 'path/to/project\.xcodeproj'} end before do @@ -17,9 +17,10 @@ describe "When the Podfile does not specify the xcodeproject" do before do - config.stubs(:rootspec).returns(Pod::Podfile.new { platform :ios; dependency 'AFNetworking'}) + config.stubs(:podfile).returns(Pod::Podfile.new { platform :ios; dependency 'AFNetworking'}) @installer = Pod::Command::Install.new(Pod::Command::ARGV.new) end + it "raises an informative error" do should.raise(Pod::Informative) { @installer.run } end @@ -28,14 +29,14 @@ begin @installer.run rescue Pod::Informative => err - err.message.should.match /xcodeproj 'path\/to\/project\.xcodeproj/ + err.message.should.match %r{xcodeproj 'path/to/project\.xcodeproj'} end end end describe "When the Podfile specifies xcodeproj to an invalid path" do before do - config.stubs(:rootspec).returns(Pod::Podfile.new { platform :ios; xcodeproj 'nonexistent/project.xcodeproj'; dependency 'AFNetworking'}) + config.stubs(:podfile).returns(Pod::Podfile.new { platform :ios; xcodeproj 'nonexistent/project.xcodeproj'; dependency 'AFNetworking'}) @installer = Pod::Command::Install.new(Pod::Command::ARGV.new) end diff --git a/spec/unit/installer/user_project_integrator_spec.rb b/spec/unit/installer/user_project_integrator_spec.rb index e2ab0d42cc..03d9f0c4ee 100644 --- a/spec/unit/installer/user_project_integrator_spec.rb +++ b/spec/unit/installer/user_project_integrator_spec.rb @@ -4,8 +4,13 @@ extend SpecHelper::TemporaryDirectory before do + @sample_project_path = SpecHelper.create_sample_app_copy_from_fixture('SampleProject') + config.project_root = @sample_project_path.dirname + + sample_project_path = @sample_project_path @podfile = Pod::Podfile.new do platform :ios + xcodeproj sample_project_path dependency 'JSONKit' target :test_runner, :exclusive => true do link_with 'TestRunner' @@ -13,10 +18,7 @@ end end - @sample_project_path = SpecHelper.create_sample_app_copy_from_fixture('SampleProject') - config.project_root = @sample_project_path.dirname - - @integrator = Pod::Installer::UserProjectIntegrator.new(@sample_project_path, @podfile) + @integrator = Pod::Installer::UserProjectIntegrator.new(@podfile) end after do