class Instrumentality::Simctl

Public Class Methods

execute_with_simulator_ready(runtime, type) { |udid| ... } click to toggle source
# File lib/instrumentality/simctl.rb, line 6
def self.execute_with_simulator_ready(runtime, type)
  device = create_device(runtime, type)
  device.launch
  device.wait(Constants::TIMEOUT) do |d|
    d.state == :booted && d.ready?
  end
  begin
    yield device.udid
  rescue StandardError => error
    throw error
  ensure
    delete_device(device)
  end
end

Private Class Methods

create_device(runtime, type) click to toggle source
# File lib/instrumentality/simctl.rb, line 21
def self.create_device(runtime, type)
  runtime = if runtime.eql? 'latest'
              SimCtl::Runtime.latest('ios')
            else
              SimCtl.runtime(name: runtime)
            end
  device_type = SimCtl.devicetype(name: type)
  device_name = "#{type}-instr"
  SimCtl.reset_device(device_name, device_type, runtime)
end
delete_device(device) click to toggle source
# File lib/instrumentality/simctl.rb, line 34
def self.delete_device(device)
  if device.state != :shutdown
    device.shutdown
    device.kill
    device.wait do |d|
      d.state == :shutdown
    end
  end
  device.delete
end