Commit 91eaa5f7 authored by Orta Therox's avatar Orta Therox Committed by Samuel Giddins

Add support for multiple tests inside a target

parent 7010d7f4
......@@ -68,31 +68,32 @@ module Pod
# Create an array of [app, (optional)test] target pairs
app_test_pairs = all_app_targets.map do |target|
test = all_tests_targets.find { |t| t.name.start_with? target.name }
[target, test].compact
test = all_tests_targets.select { |t| t.name.start_with? target.name }
[target, *test].compact
end
app_test_pairs.each do |target_pair|
podfile << target_module(target_pair)
end
podfile
end
# @param [[Xcodeproj::PBXTarget]] targets
# An array which always has a target as it's first item
# and may optionally contain a second target as its test target
# and may optionally contain related test targets
#
# @return [String] the text for the target module
#
def target_module(targets)
app = targets.first
target_module = "\ntarget '#{app.name.gsub(/'/, "\\\\\'")}' do\n"
target_module << template_contents(config.default_podfile_path, " ")
target_module << template_contents(config.default_podfile_path, " ", "Pods for #{app.name}\n")
test = targets[1]
if test
targets[1..-1].each do |test|
target_module << "\n target '#{test.name.gsub(/'/, "\\\\\'")}' do\n"
target_module << " inherit! :search_paths\n"
target_module << template_contents(config.default_test_podfile_path, " ")
target_module << template_contents(config.default_test_podfile_path, " ", "Pods for testing")
target_module << "\n end\n"
end
......@@ -105,11 +106,11 @@ module Pod
#
# @return [String] the text for the target module
#
def template_contents(path, prefix)
def template_contents(path, prefix, fallback)
if path.exist?
path.read.chomp.lines.map { |line| "#{prefix}#{line}" }.join("\n")
else
''
"#{prefix}# #{fallback}"
end
end
end
......
......@@ -86,6 +86,44 @@ module Pod
end
end
fit 'handles hooking up mulitple test targets based on an xcodeproj project' do
Dir.chdir(temporary_directory) do
project = Xcodeproj::Project.new(temporary_directory + 'test.xcodeproj')
project.new_target(:application, 'App', :ios)
project.new_target(:application, 'AppTests', :ios)
project.new_target(:application, "AppFeatureTests", :ios)
project.save
run_command('init')
podfile_text = File.read(temporary_directory + "Podfile")
podfile_exact = <<-PODFILE.strip_heredoc
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
# Uncomment this line if you're using Swift
# use_frameworks!
target 'App' do
# Pods for App
target 'AppTests' do
inherit! :search_paths
# Pods for testing
end
target 'AppFeatureTests' do
inherit! :search_paths
# Pods for testing
end
end
PODFILE
podfile_text.should == podfile_exact
end
end
it 'includes default test pods in test targets in a Podfile' do
Dir.chdir(temporary_directory) do
tmp_templates_dir = Pathname.pwd + 'templates_dir'
......
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