lib/run_loop/device.rb in run_loop-2.1.6 vs lib/run_loop/device.rb in run_loop-2.1.7
- old
+ new
@@ -2,10 +2,13 @@
class Device
require 'securerandom'
include RunLoop::Regex
+ require "run_loop/shell"
+ include RunLoop::Shell
+
# Starting in Xcode 7, iOS 9 simulators have a new "booting" state.
#
# The simulator must completely boot before run-loop tries to do things
# like installing an app or clearing an app sandbox. Run-loop tries to
# wait for a the simulator stabilize by watching the checksum of the
@@ -37,11 +40,10 @@
attr_reader :state
attr_reader :simulator_root_dir
attr_reader :simulator_accessibility_plist_path
attr_reader :simulator_preferences_plist_path
attr_reader :simulator_log_file_path
- attr_reader :pbuddy
# Create a new device.
#
# @param [String] name The name of the device. For sims this should be
# 'iPhone 5s' and for physical devices it will be the name the user gave
@@ -266,11 +268,11 @@
def update_simulator_state
if physical_device?
raise RuntimeError, 'This method is available only for simulators'
end
- @state = fetch_simulator_state
+ @state = simctl.simulator_state_as_string(self)
end
# @!visibility private
def simulator_root_dir
@simulator_root_dir ||= lambda {
@@ -496,24 +498,39 @@
end
global_plist = simulator_global_preferences_path
cmd = [
- "PlistBuddy",
+ "/usr/libexec/PlistBuddy",
"-c",
"Add :AppleLanguages:0 string '#{lang_code}'",
global_plist
]
# RunLoop::PlistBuddy cannot add items to arrays.
- xcrun.run_command_in_context(cmd, {:log_cmd => true})
+ hash = run_shell_command(cmd, {:log_cmd => true})
+ if hash[:exit_status] != 0
+ raise RuntimeError, %Q[
+Could not update the Simulator languages because this command:
+
+#{cmd.join(" ")}
+
+failed with this output:
+
+#{hash[:out]}
+
+]
+ end
+
simulator_languages
end
private
+ attr_reader :pbuddy, :simctl, :xcrun
+
# @!visibility private
def xcrun
RunLoop::Xcrun.new
end
@@ -521,46 +538,11 @@
def pbuddy
RunLoop::PlistBuddy.new
end
# @!visibility private
- def detect_state_from_line(line)
-
- if line[/unavailable/, 0]
- RunLoop.log_debug("Simulator state is unavailable: #{line}")
- return 'Unavailable'
- end
-
- state = line[/(Booted|Shutdown|Shutting Down)/,0]
-
- if state.nil?
- RunLoop.log_debug("Simulator state is unknown: #{line}")
- 'Unknown'
- else
- state
- end
- end
-
- # @!visibility private
- def fetch_simulator_state
- if physical_device?
- raise RuntimeError, 'This method is available only for simulators'
- end
-
- args = ['simctl', 'list', 'devices']
- hash = xcrun.run_command_in_context(args)
- out = hash[:out]
-
- matched_line = out.split("\n").find do |line|
- line.include?(udid)
- end
-
- if matched_line.nil?
- raise RuntimeError,
- "Expected a simulator with udid '#{udid}', but found none"
- end
-
- detect_state_from_line(matched_line)
+ def simctl
+ @simctl ||= RunLoop::Simctl.new
end
# @!visibility private
CORE_SIMULATOR_DEVICE_DIR = File.join(RunLoop::Environment.user_home_directory,
"Library",