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
# Uncomment this line to define a global platform for your project
# platform :ios, "6.0"
PLATFORM
if config.default_podfile_path.exist?
open(config.default_podfile_path, 'r') { |f| podfile << f.read }
end
for target in project.targets
podfile << target_module(target)
end
podfile
podfile << "\n"
end
# @param [Xcodeproj::PBXTarget] target
......@@ -61,12 +64,15 @@ module Pod
# @return [String] the text for the target module
#
def target_module(target)
return <<-TARGET.strip_heredoc
target_module = <<-TARGET.strip_heredoc
target "#{target.name}" do
end
target "#{target.name}" do
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
......
......@@ -223,6 +223,26 @@ module Pod
@lockfile_path ||= installation_root + 'Podfile.lock'
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.
#
def statistics_cache_file
......
......@@ -16,55 +16,41 @@ module Pod
end
it "complains if more than one project exists and none is specified" do
pwd = Dir.pwd
Dir.chdir(temporary_directory)
Dir.chdir(temporary_directory) do
Xcodeproj::Project.new.save_as(temporary_directory + 'test1.xcodeproj')
Xcodeproj::Project.new.save_as(temporary_directory + 'test2.xcodeproj')
lambda { run_command('init') }.should.raise CLAide::Help
Dir.chdir(pwd)
end
end
it "complains if a Podfile already exists" do
pwd = Dir.pwd
Dir.chdir(temporary_directory)
Dir.chdir(temporary_directory) do
(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
Dir.chdir(pwd)
end
end
it "creates a Podfile for a project in current directory" do
pwd = Dir.pwd
Dir.chdir(temporary_directory)
Dir.chdir(temporary_directory) do
Xcodeproj::Project.new.save_as(temporary_directory + 'test1.xcodeproj')
run_command('init')
Pathname.new(temporary_directory + 'Podfile').exist?.should == true
Dir.chdir(pwd)
end
end
it "creates a Podfile for a specified project" do
pwd = Dir.pwd
Dir.chdir(temporary_directory)
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
Dir.chdir(pwd)
end
end
it "creates a Podfile with targets from the project" do
pwd = Dir.pwd
Dir.chdir(temporary_directory)
Dir.chdir(temporary_directory) do
project = Xcodeproj::Project.new
target1 = project.new_target(:application, "AppA", :ios)
target2 = project.new_target(:application, "AppB", :ios)
......@@ -73,12 +59,67 @@ module Pod
run_command('init')
config.podfile.nil?.should == false
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
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')
run_command('init')
config.podfile.nil?.should == false
config.podfile.dependencies.length.should == 1
config.podfile.dependencies.first.name.should == "AFNetworking"
end
end
it "includes default test pods in test targets in a Podfile" do
Dir.chdir(temporary_directory) do
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'" }
project = Xcodeproj::Project.new
project.new_target(:application, "AppTests", :ios)
project.save_as(temporary_directory + 'test.xcodeproj')
run_command('init')
config.podfile.nil?.should == false
config.podfile.dependencies.length.should == 1
config.podfile.dependencies.first.name.should == "Kiwi"
end
end
it "does not include default test pods if there are no test targets" do
Dir.chdir(temporary_directory) do
tmp_repos_dir = Pathname.pwd + 'repo_dir'
tmp_repos_dir.mkpath
config.repos_dir = tmp_repos_dir
Dir.chdir(pwd)
open(config.default_test_podfile_path, 'w') { |f| f << "pod 'Kiwi'" }
project = Xcodeproj::Project.new
project.new_target(:application, "App", :ios)
project.save_as(temporary_directory + 'test.xcodeproj')
run_command('init')
config.podfile.nil?.should == false
config.podfile.dependencies.length.should == 0
end
end
end
......
......@@ -389,6 +389,3 @@ describe "Integration" do
#--------------------------------------#
end
# Uncomment this line to define a global platform for your project
# platform :ios, "6.0"
target "SampleApp" do
end
......
......@@ -21,6 +21,9 @@ module Pod
it "returns the path to the spec-repos dir" do
@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
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