Skip to content

Commit 896b87f

Browse files
committed
Simctl: wait for 'state' key instead of file
1 parent 126f1f2 commit 896b87f

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

lib/run_loop/simctl.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Simctl
2424
"Shutdown" => 1,
2525
"Shutting Down" => 2,
2626
"Booted" => 3,
27-
"Plist Missing" => -1
27+
"Plist Missing Key" => -1
2828
}.freeze
2929

3030
# @!visibility private
@@ -125,10 +125,11 @@ def app_container(device, bundle_id)
125125
# @!visibility private
126126
def simulator_state_as_int(device)
127127
plist = device.simulator_device_plist
128-
if File.exist?(plist)
128+
129+
if pbuddy.plist_key_exists?("state", plist)
129130
pbuddy.plist_read("state", plist).to_i
130131
else
131-
SIM_STATES["Plist Missing"]
132+
SIM_STATES["Plist Missing Key"]
132133
end
133134
end
134135

spec/lib/simctl_spec.rb

+13-7
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@
215215
expect(simctl.send(:string_for_sim_state, 1)).to be == "Shutdown"
216216
expect(simctl.send(:string_for_sim_state, 2)).to be == "Shutting Down"
217217
expect(simctl.send(:string_for_sim_state, 3)).to be == "Booted"
218-
expect(simctl.send(:string_for_sim_state, -1)).to be == "Plist Missing"
218+
expect(simctl.send(:string_for_sim_state, -1)).to be == "Plist Missing Key"
219219
end
220220

221221
it "raises an error for invalid states" do
@@ -228,21 +228,27 @@
228228
context "#simulator_state_as_int" do
229229
it "returns the numeric state of the simulator by asking the sim plist" do
230230
plist = device.simulator_device_plist
231-
expect(File).to receive(:exist?).with(plist).and_return(true)
232-
233231
pbuddy = RunLoop::PlistBuddy.new
234-
expect(simctl).to receive(:pbuddy).and_return(pbuddy)
232+
233+
expect(simctl).to receive(:pbuddy).at_least(:once).and_return(pbuddy)
234+
expect(pbuddy).to(
235+
receive(:plist_key_exists?).with("state", plist).and_return(true)
236+
)
235237
expect(pbuddy).to receive(:plist_read).and_return("10")
236238

237239
expect(simctl.simulator_state_as_int(device)).to be == 10
238240
end
239241

240-
it "returns the Plist Missing state (-1) if the plist is missing" do
242+
it "returns the Plist Missing Key state (-1) state key is missing" do
241243
plist = device.simulator_device_plist
242-
expect(File).to receive(:exist?).with(plist).and_return(false)
244+
pbuddy = RunLoop::PlistBuddy.new
243245

244-
expected = RunLoop::Simctl::SIM_STATES["Plist Missing"]
246+
expect(simctl).to receive(:pbuddy).and_return(pbuddy)
247+
expect(pbuddy).to(
248+
receive(:plist_key_exists?).with("state", plist).and_return(false)
249+
)
245250

251+
expected = RunLoop::Simctl::SIM_STATES["Plist Missing Key"]
246252
expect(simctl.simulator_state_as_int(device)).to be == expected
247253
end
248254
end

0 commit comments

Comments
 (0)