class ParallelCalabash::IosHelper
Public Class Methods
new(filter = nil, default_simulator = nil, config_file = nil, instruments = nil)
click to toggle source
# File lib/parallel_calabash/adb_helper.rb, line 60 def initialize(filter = nil, default_simulator = nil, config_file = nil, instruments = nil) @filter = filter || [] @default_simulator = default_simulator || {} config_file = config_file || "#{ENV['HOME']}/.parallel_calabash" if config_file.is_a? Hash @config = config_file else @config = File.exist?(config_file) ? eval(File.read(config_file)) : {} end @instruments = instruments || %x(instruments -s devices ; echo) # Bizarre workaround for xcode 7 end
Public Instance Methods
apply_filter(configs)
click to toggle source
# File lib/parallel_calabash/adb_helper.rb, line 121 def apply_filter(configs) return configs if @filter.empty? filter_join = @filter.join('|') configs.select do |c| [c.keys, c.values].flatten.find { |k| k.to_s.match(filter_join) } end end
compute_devices()
click to toggle source
# File lib/parallel_calabash/adb_helper.rb, line 103 def compute_devices users = @config[:USERS] || [] init = @config[:INIT] || '' devices = remove_unconnected_devices(@config[:DEVICES]) fail 'Devices configured, but no devices attached!' if devices.empty? configs = devices.map.with_index do |d, i| if users[i] d[:USER] = users[i] d[:INIT] = init d else print "** No user for device #{d}" nil end end configs.compact end
compute_simulators()
click to toggle source
# File lib/parallel_calabash/adb_helper.rb, line 88 def compute_simulators port = (@config[:CALABASH_SERVER_PORT] || 28000).to_i users = @config[:USERS] || [] init = @config[:INIT] || '' simulator = @config[:DEVICE_TARGET] || nil users.map.with_index do |u, i| {}.tap do |my_hash| my_hash[:USER] = u my_hash[:CALABASH_SERVER_PORT] = port + i my_hash[:INIT] = init my_hash[:DEVICE_TARGET] = simulator unless simulator.nil? end end end
connected_devices_with_model_info()
click to toggle source
# File lib/parallel_calabash/adb_helper.rb, line 76 def connected_devices_with_model_info return @devices if @devices if @config[:DEVICES] configs = apply_filter(compute_devices) fail '** No devices (or users) unfiltered!' if configs.empty? else configs = apply_filter(compute_simulators) configs = configs.empty? ? [@default_simulator] : configs end @devices = configs end
remove_unconnected_devices(configs)
click to toggle source
# File lib/parallel_calabash/adb_helper.rb, line 129 def remove_unconnected_devices(configs) udids = @instruments.each_line.map { |n| n.match(/\[(.*)\]/) && $1 }.flatten.compact configs.find_all do |c| var = c[:DEVICE_TARGET] !udids.grep(var).empty? end end
xcode7?()
click to toggle source
# File lib/parallel_calabash/adb_helper.rb, line 72 def xcode7? !@instruments.match(' Simulator\)') end