From cac3abdd17fc56cb457bb7a81d4425c63e02db24 Mon Sep 17 00:00:00 2001 From: Arkadiusz Konopacki Date: Mon, 23 May 2016 13:45:32 +0200 Subject: [PATCH] Fixing failed device tests --- lib/run_loop/detect_aut/xcode.rb | 33 ++++++++++++++++++-------------- lib/run_loop/device.rb | 9 +++++++-- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/lib/run_loop/detect_aut/xcode.rb b/lib/run_loop/detect_aut/xcode.rb index 6277624b..07c1652a 100644 --- a/lib/run_loop/detect_aut/xcode.rb +++ b/lib/run_loop/detect_aut/xcode.rb @@ -43,10 +43,13 @@ def find_xcodeproj # @!visibility private def self.find_user_state_file username = RunLoop::Environment.username - xcworkspace = RunLoop::Environment.xcodeproj.gsub("xcodeproj", "xcworkspace") - file = Dir.glob("#{xcworkspace}/xcuserdata/#{username}.xcuserdatad/UserInterfaceState.xcuserstate") - if !file.nil? && file.is_a?(Array) - return file[0] + xcworkspace = RunLoop::Environment.xcodeproj + unless xcworkspace.nil? + xcworkspace = xcworkspace.gsub("xcodeproj", "xcworkspace") + file = Dir.glob("#{xcworkspace}/xcuserdata/#{username}.xcuserdatad/UserInterfaceState.xcuserstate") + if !file.nil? && file.is_a?(Array) + return file[0] + end end end @@ -156,22 +159,24 @@ def xcode_preferences_plist end # @!visibility private - def self.pbuddy + def pbuddy @pbuddy ||= RunLoop::PlistBuddy.new end # @!visibility private def self.detect_selected_device file_name = find_user_state_file - selected_device = @pbuddy.plist_find_device(file_name) - - udid = selected_device.split(':')[1] - selected_device = RunLoop::Device.device_with_identifier(udid) - #TODO now only returning detected device if simulator detected - if selected_device.simulator? - selected_device - else - nil + pbuddy ||= RunLoop::PlistBuddy.new + selected_device = pbuddy.plist_find_device(file_name) + if selected_device != '' && !selected_device.nil? + udid = selected_device.split(':')[1] + selected_device = RunLoop::Device.device_with_identifier(udid) + #TODO now only returning detected device if simulator detected + if selected_device.simulator? + selected_device + else + nil + end end end end diff --git a/lib/run_loop/device.rb b/lib/run_loop/device.rb index fd37855f..43742462 100644 --- a/lib/run_loop/device.rb +++ b/lib/run_loop/device.rb @@ -142,8 +142,13 @@ def self.device_with_identifier(udid_or_name, options={}) # @raise [ArgumentError] If DEVICE_TARGET or options specify an identifier # that does not match an iOS Simulator or physical device. def self.detect_device(options, xcode, simctl, instruments) - device = RunLoop::DetectAUT::Xcode.detect_selected_device || - self.device_from_opts_or_env(options) + detected_device = RunLoop::DetectAUT::Xcode.detect_selected_device + if detected_device.is_a?(RunLoop::Device) + device = detected_device + else + device = self.device_from_opts_or_env(options) + end + # Passed an instance of RunLoop::Device return device if device && device.is_a?(RunLoop::Device)