class XCTasks::TestTask::Subtask
Attributes
config[R]
name[R]
Public Class Methods
new(name_options, config)
click to toggle source
# File lib/xctasks/test_task.rb, line 197 def initialize(name_options, config) @config = config.dup self.name = name_options.kind_of?(Hash) ? name_options.keys.first : name_options.to_s self.scheme = name_options.values.first if name_options.kind_of?(Hash) end
Public Instance Methods
define_rake_tasks()
click to toggle source
# File lib/xctasks/test_task.rb, line 207 def define_rake_tasks @config.validate! if namespaced? namespace(name) do ios_versions.each do |ios_version| desc "Run #{name} tests against iOS Simulator #{ios_version} SDK" task ios_version => :prepare do run_tests(ios_version: ios_version) end end end desc "Run #{name} tests against iOS Simulator #{ios_versions.join(', ')}" task name => ios_versions.map { |ios_version| "#{name}:#{ios_version}" } else desc "Run #{name} tests" task self.name => :prepare do run_tests end end end
name=(name)
click to toggle source
# File lib/xctasks/test_task.rb, line 203 def name=(name) @name = name.to_s end
prepare()
click to toggle source
# File lib/xctasks/test_task.rb, line 230 def prepare write_environment_variables_to_scheme end
Private Instance Methods
actions_arg()
click to toggle source
# File lib/xctasks/test_task.rb, line 268 def actions_arg actions.join(' ') end
destination_arg()
click to toggle source
# File lib/xctasks/test_task.rb, line 272 def destination_arg if destinations.any? destinations.map { |d| "-destination #{d}" }.join(' ') else nil end end
namespaced?()
click to toggle source
# File lib/xctasks/test_task.rb, line 236 def namespaced? ios_versions && ios_versions.any? end
run_tests(options = {})
click to toggle source
# File lib/xctasks/test_task.rb, line 240 def run_tests(options = {}) ios_version = options[:ios_version] XCTasks::Command.run(%q{killall "iPhone Simulator"}, false) if sdk == :iphonesimulator target = workspace ? "-workspace #{workspace}" : "-project #{project}" output_log_command = output_log ? "| tee -a #{output_log}" : nil redirect_suffix = redirect_stderr ? "2> #{redirect_stderr}" : nil success = if xctool? actions_arg << " -freshSimulator" if ios_version Command.run(["#{xctool_path} #{target} -scheme '#{scheme}' -sdk #{sdk}#{ios_version}", destination_arg, actions_arg, settings_arg, redirect_suffix, output_log_command].grep(String).join(' ')) elsif xcodebuild? Command.run(["#{xcodebuild_path} #{target} -scheme '#{scheme}' -sdk #{sdk}#{ios_version}", destination_arg, actions_arg, settings_arg, redirect_suffix, output_log_command].grep(String).join(' ')) elsif xcpretty? xcpretty_bin = runner.is_a?(String) ? runner : "xcpretty -c" Command.run(["#{xcodebuild_path} #{target} -scheme '#{scheme}' -sdk #{sdk}#{ios_version}", destination_arg, actions_arg, settings_arg, redirect_suffix, output_log_command, "| #{xcpretty_bin} ; exit ${PIPESTATUS[0]}"].grep(String).join(' ')) end XCTasks::TestReport.instance.add_result(self, options, success) end
settings_arg()
click to toggle source
# File lib/xctasks/test_task.rb, line 260 def settings_arg if settings.any? settings.map { |k,v| "#{k}=#{v}"}.join(' ') else nil end end
write_environment_variables_to_scheme()
click to toggle source
# File lib/xctasks/test_task.rb, line 280 def write_environment_variables_to_scheme if env.any? path = "#{workspace || project}/xcshareddata/xcschemes/#{scheme}.xcscheme" doc = Nokogiri::XML(File.read(path)) testable_node = doc.at('TestAction') env_variables_node = Nokogiri::XML::Node.new "EnvironmentVariables", doc env.each do |key, value| node = Nokogiri::XML::Node.new "EnvironmentVariable", doc node.set_attribute "key", key node.set_attribute "value", value node.set_attribute "isEnabled", "YES" env_variables_node << node end testable_node << env_variables_node File.open(path, 'w') { |f| f << doc.to_s } end end