Commit c4dd56e9 authored by Ian Ynda-Hummel's avatar Ian Ynda-Hummel

Implement default pods inclusion for the init subcommand

* Added default_podfile_path and default_test_podfile_path to Pod::Config
* Add behavior to Command::Init to read out the above paths into generate Podfiles when appropriate.
* Implemented tests for the relevant pieces of behavior.
parent 39f70d6d
...@@ -49,10 +49,13 @@ module Pod ...@@ -49,10 +49,13 @@ module Pod
# Uncomment this line to define a global platform for your project # Uncomment this line to define a global platform for your project
# platform :ios, "6.0" # platform :ios, "6.0"
PLATFORM PLATFORM
if config.default_podfile_path.exist?
open(config.default_podfile_path, 'r') { |f| podfile << f.read }
end
for target in project.targets for target in project.targets
podfile << target_module(target) podfile << target_module(target)
end end
podfile podfile << "\n"
end end
# @param [Xcodeproj::PBXTarget] target # @param [Xcodeproj::PBXTarget] target
...@@ -61,12 +64,15 @@ module Pod ...@@ -61,12 +64,15 @@ module Pod
# @return [String] the text for the target module # @return [String] the text for the target module
# #
def target_module(target) def target_module(target)
return <<-TARGET.strip_heredoc target_module = <<-TARGET.strip_heredoc
target "#{target.name}" do
end target "#{target.name}" do
TARGET TARGET
if config.default_test_podfile_path.exist? and target.name =~ /tests?/i
open(config.default_test_podfile_path, 'r') { |f| target_module << f.read }
end
target_module << "\nend"
end end
end end
end end
......
...@@ -223,6 +223,26 @@ module Pod ...@@ -223,6 +223,26 @@ module Pod
@lockfile_path ||= installation_root + 'Podfile.lock' @lockfile_path ||= installation_root + 'Podfile.lock'
end end
# Returns the path of the default Podfile pods.
#
# @note The file is expected to be named default.podfile
#
# @return [Pathname]
#
def default_podfile_path
@default_podfile_path ||= repos_dir + "default.podfile"
end
# Returns the path of the default Podfile test pods.
#
# @note The file is expected to be named test.podfile
#
# @return [Pathname]
#
def default_test_podfile_path
@default_test_podfile_path ||= repos_dir + "test.podfile"
end
# @return [Pathname] The file to use a cache of the statistics provider. # @return [Pathname] The file to use a cache of the statistics provider.
# #
def statistics_cache_file def statistics_cache_file
......
...@@ -16,69 +16,110 @@ module Pod ...@@ -16,69 +16,110 @@ module Pod
end end
it "complains if more than one project exists and none is specified" do it "complains if more than one project exists and none is specified" do
pwd = Dir.pwd Dir.chdir(temporary_directory) do
Dir.chdir(temporary_directory) Xcodeproj::Project.new.save_as(temporary_directory + 'test1.xcodeproj')
Xcodeproj::Project.new.save_as(temporary_directory + 'test2.xcodeproj')
Xcodeproj::Project.new.save_as(temporary_directory + 'test1.xcodeproj') lambda { run_command('init') }.should.raise CLAide::Help
Xcodeproj::Project.new.save_as(temporary_directory + 'test2.xcodeproj') end
lambda { run_command('init') }.should.raise CLAide::Help
Dir.chdir(pwd)
end end
it "complains if a Podfile already exists" do it "complains if a Podfile already exists" do
pwd = Dir.pwd Dir.chdir(temporary_directory) do
Dir.chdir(temporary_directory) (Pathname.pwd + 'Podfile').open('w') { |f| f << "pod 'AFNetworking'" }
Xcodeproj::Project.new.save_as(temporary_directory + 'test1.xcodeproj')
lambda { run_command('init') }.should.raise CLAide::Help
end
end
(Pathname.pwd + 'Podfile').open('w') { |f| f << "pod 'AFNetworking'" } it "creates a Podfile for a project in current directory" do
Xcodeproj::Project.new.save_as(temporary_directory + 'test1.xcodeproj') Dir.chdir(temporary_directory) do
lambda { run_command('init') }.should.raise CLAide::Help Xcodeproj::Project.new.save_as(temporary_directory + 'test1.xcodeproj')
run_command('init')
Pathname.new(temporary_directory + 'Podfile').exist?.should == true
end
end
Dir.chdir(pwd) it "creates a Podfile for a specified project" do
Dir.chdir(temporary_directory) do
Xcodeproj::Project.new.save_as(temporary_directory + 'test1.xcodeproj')
Xcodeproj::Project.new.save_as(temporary_directory + 'test2.xcodeproj')
run_command('init', 'test2.xcodeproj')
Pathname.new(temporary_directory + 'Podfile').exist?.should == true
config.podfile.nil?.should == false
end
end end
it "creates a Podfile for a project in current directory" do it "creates a Podfile with targets from the project" do
pwd = Dir.pwd Dir.chdir(temporary_directory) do
Dir.chdir(temporary_directory) project = Xcodeproj::Project.new
target1 = project.new_target(:application, "AppA", :ios)
target2 = project.new_target(:application, "AppB", :ios)
project.save_as(temporary_directory + 'test.xcodeproj')
run_command('init')
config.podfile.nil?.should == false
config.podfile.target_definitions.length.should == project.targets.length + 1
config.podfile.target_definitions["AppA"].nil?.should == false
config.podfile.target_definitions["AppB"].nil?.should == false
end
end
it "includes default pods in a Podfile" do
Dir.chdir(temporary_directory) do
tmp_repos_dir = Pathname.pwd + 'repos_dir'
tmp_repos_dir.mkpath
config.repos_dir = tmp_repos_dir
open(config.default_podfile_path, 'w') { |f| f << "pod 'AFNetworking'" }
Xcodeproj::Project.new.save_as(temporary_directory + 'test.xcodeproj')
Xcodeproj::Project.new.save_as(temporary_directory + 'test1.xcodeproj') run_command('init')
run_command('init')
Pathname.new(temporary_directory + 'Podfile').exist?.should == true
Dir.chdir(pwd) config.podfile.nil?.should == false
config.podfile.dependencies.length.should == 1
config.podfile.dependencies.first.name.should == "AFNetworking"
end
end end
it "creates a Podfile for a specified project" do it "includes default test pods in test targets in a Podfile" do
pwd = Dir.pwd Dir.chdir(temporary_directory) do
Dir.chdir(temporary_directory) tmp_repos_dir = Pathname.pwd + 'repo_dir'
tmp_repos_dir.mkpath
config.repos_dir = tmp_repos_dir
open(config.default_test_podfile_path, 'w') { |f| f << "pod 'Kiwi'" }
Xcodeproj::Project.new.save_as(temporary_directory + 'test1.xcodeproj') project = Xcodeproj::Project.new
Xcodeproj::Project.new.save_as(temporary_directory + 'test2.xcodeproj') project.new_target(:application, "AppTests", :ios)
run_command('init', 'test2.xcodeproj') project.save_as(temporary_directory + 'test.xcodeproj')
Pathname.new(temporary_directory + 'Podfile').exist?.should == true
config.podfile.nil?.should == false
Dir.chdir(pwd) run_command('init')
config.podfile.nil?.should == false
config.podfile.dependencies.length.should == 1
config.podfile.dependencies.first.name.should == "Kiwi"
end
end end
it "creates a Podfile with targets from the project" do it "does not include default test pods if there are no test targets" do
pwd = Dir.pwd Dir.chdir(temporary_directory) do
Dir.chdir(temporary_directory) tmp_repos_dir = Pathname.pwd + 'repo_dir'
tmp_repos_dir.mkpath
config.repos_dir = tmp_repos_dir
project = Xcodeproj::Project.new open(config.default_test_podfile_path, 'w') { |f| f << "pod 'Kiwi'" }
target1 = project.new_target(:application, "AppA", :ios)
target2 = project.new_target(:application, "AppB", :ios)
project.save_as(temporary_directory + 'test.xcodeproj')
run_command('init') project = Xcodeproj::Project.new
project.new_target(:application, "App", :ios)
project.save_as(temporary_directory + 'test.xcodeproj')
config.podfile.nil?.should == false run_command('init')
puts config.podfile.target_definitions
config.podfile.target_definitions.length.should == project.targets.length + 1
config.podfile.target_definitions["AppA"].nil?.should == false
config.podfile.target_definitions["AppB"].nil?.should == false
Dir.chdir(pwd) config.podfile.nil?.should == false
config.podfile.dependencies.length.should == 0
end
end end
end end
......
...@@ -389,6 +389,3 @@ describe "Integration" do ...@@ -389,6 +389,3 @@ describe "Integration" do
#--------------------------------------# #--------------------------------------#
end end
# Uncomment this line to define a global platform for your project # Uncomment this line to define a global platform for your project
# platform :ios, "6.0" # platform :ios, "6.0"
target "SampleApp" do target "SampleApp" do
end end
......
...@@ -21,6 +21,9 @@ module Pod ...@@ -21,6 +21,9 @@ module Pod
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 @sut.repos_dir.should == Pathname.new("~/.cocoapods/repos").expand_path
it "returns the path of the default podfiles" do
config.default_podfile_path.should == Pathname.new("~/.cocoapods/default.podfile").expand_path
config.default_test_podfile_path.should == Pathname.new("~/.cocoapods/test.podfile").expand_path
end end
it "allows to specify whether the aggressive cache should be used with an environment variable" do it "allows to specify whether the aggressive cache should be used with an environment variable" do
......
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