class TripAdvisor::TestTasks
Attributes
environment_variables[RW]
ios_versions[RW]
namespace_name[R]
prepare_dependency[R]
runner[RW]
schemes[RW]
schemes_dir[RW]
settings[RW]
test_devices[RW]
workspace[RW]
xcodebuild_path[RW]
xctool_path[RW]
Public Class Methods
new(namespace_name = :test) { |self| ... }
click to toggle source
# File lib/trip_advisor/rake_tasks.rb, line 90 def initialize(namespace_name = :test) @namespace_name = namespace_name.is_a?(Hash) ? namespace_name.keys.first : namespace_name @prepare_dependency = namespace_name.is_a?(Hash) ? namespace_name.values.first : nil @schemes_dir = 'Tests/Schemes' @ios_versions = %w{8.4 9.0} @xctool_path = 'xctool' @xcodebuild_path = 'xcodebuild' @runner = :xctool @settings = {} @environment_variables = '' yield self if block_given? raise "A workspace must be configured" unless workspace raise "At least one scheme must be configured" unless schemes raise "At least one test device must be configured" unless test_devices define_tasks end
Public Instance Methods
define_tasks()
click to toggle source
# File lib/trip_advisor/rake_tasks.rb, line 113 def define_tasks namespace self.namespace_name do task (prepare_dependency ? { prepare: prepare_dependency} : :prepare ) do run(%Q{mkdir -p "#{workspace}/xcshareddata/xcschemes" && cp Tests/Schemes/*.xcscheme "#{workspace}/xcshareddata/xcschemes/"}) end # Iterate across the schemes and define a task for each version of iOS and an aggregate task schemes.each do |scheme_namespace, scheme_names| scheme_names_array = scheme_names.is_a?(Array) ? scheme_names : [scheme_names] namespace scheme_namespace do scheme_names_array.each do |scheme_name| ios_versions.each do |ios_version| namespace ios_version do test_devices.each do |test_device| next unless test_device.valid_for?(scheme_name) desc "Run #{scheme_namespace} tests against #{ios_version} SDK on #{test_device}" task test_device.short_name => :prepare do test_scheme(scheme_name, namespace: scheme_namespace, ios_version: ios_version, test_device: test_device) end end end desc "Run #{scheme_namespace} tests against #{ios_version} SDK on valid devices" task "#{ios_version}" => test_devices.select { |test_device| test_device.valid_for?(scheme_name) }.map { |test_device| "#{scheme_namespace}:#{ios_version}:#{test_device.short_name}" } end end end desc "Run #{scheme_namespace} tests against all SDKs and valid devices" task scheme_namespace => ios_versions.map { |ios_version| "#{scheme_namespace}:#{ios_version}" } end end desc "Run the #{schemes.keys.join(', ')} tests on all devices and SDKs" task namespace_name => schemes.keys.map { |scheme| "#{namespace_name}:#{scheme}" } do TripAdvisor::TestReport.instance.report end end
runner=(runner)
click to toggle source
# File lib/trip_advisor/rake_tasks.rb, line 108 def runner=(runner) raise ArgumentError, "Must be :xctool or :xcodebuild" unless %w{xctool xcodebuild}.include?(runner.to_s) @runner = runner.to_sym end
Private Instance Methods
run(command)
click to toggle source
# File lib/trip_advisor/rake_tasks.rb, line 152 def run(command) puts "Executing `#{command}`" system(command) end
test_scheme(scheme, options)
click to toggle source
# File lib/trip_advisor/rake_tasks.rb, line 157 def test_scheme(scheme, options) system(%q{killall "iPhone Simulator"}) namespace = options[:namespace] ios_version = options[:ios_version] test_device = options[:test_device] test_sdk = "#{ios_version}" settings_arg = settings.map { |k,v| "#{k}=#{v}"}.join(' ') destination_arg = test_device.destination_arg(ios_version) success = if xctool? run("#{xctool_path} -workspace #{workspace} -scheme #{scheme} -sdk #{test_device.sdk} test -freshSimulator -destination #{destination_arg} #{settings_arg} #{environment_variables} DEVICE_NAME=#{test_device.short_name}_#{ios_version} -reporter junit:#{scheme}-#{test_sdk}-#{test_device.short_name}.xml") elsif xcodebuild? run("#{xcodebuild_path} -workspace #{workspace} -scheme #{scheme} -sdk #{test_device.sdk} test -destination #{destination_arg} #{settings_arg} #{environment_variables} DEVICE_NAME=#{test_device.short_name}_#{ios_version} | xcpretty -cr html --output build/reports/#{scheme}-#{test_sdk}-#{test_device.short_name}.html ; exit ${PIPESTATUS[0]}") end TripAdvisor::TestReport.instance.add_result(namespace, ios_version, test_device, success) end
xcodebuild?()
click to toggle source
# File lib/trip_advisor/rake_tasks.rb, line 178 def xcodebuild? runner == :xcodebuild end
xctool?()
click to toggle source
# File lib/trip_advisor/rake_tasks.rb, line 174 def xctool? runner == :xctool end