Class: UISpecRunner::Drivers::Shell

Inherits:
Object
  • Object
show all
Defined in:
lib/uispecrunner/drivers/shell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Shell

Returns a new instance of Shell.



8
9
10
# File 'lib/uispecrunner/drivers/shell.rb', line 8

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/uispecrunner/drivers/shell.rb', line 6

def config
  @config
end

Instance Method Details

#path_to_securitydObject



38
39
40
# File 'lib/uispecrunner/drivers/shell.rb', line 38

def path_to_securityd
  "#{config.sdk_dir}/usr/libexec/securityd"
end

#run_command(command) ⇒ Object



33
34
35
36
# File 'lib/uispecrunner/drivers/shell.rb', line 33

def run_command(command)
  puts "Executing: #{command}" if config.verbose?
  system(command)
end

#run_specs(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/uispecrunner/drivers/shell.rb', line 12

def run_specs(env)
  run_env = config.env.merge(env)
  run_env.merge!('DYLD_ROOT_PATH' => config.sdk_dir, 'IPHONE_SIMULATOR_ROOT' => config.sdk_dir, 'CFFIXED_USER_HOME' => Dir.tmpdir)
  puts "Setting environment variables: #{run_env.inspect}" if config.verbose?
  with_env(run_env) do
    start_securityd if config.securityd
    command = "#{config.app_executable_path} -RegisterForSystemEvents"
    puts "Executing: #{command}" if config.verbose?
    output = `#{command}`
    return $?
  end        
end

#start_securitydObject



42
43
44
45
46
47
48
# File 'lib/uispecrunner/drivers/shell.rb', line 42

def start_securityd
  run_command("launchctl submit -l UISpecRunnerDaemons -- #{path_to_securityd}")
  @securityd_running = true
  Signal.trap("INT") { stop_securityd }
  Signal.trap("TERM") { stop_securityd }
  Signal.trap("EXIT") { stop_securityd }
end

#stop_securitydObject



50
51
52
53
# File 'lib/uispecrunner/drivers/shell.rb', line 50

def stop_securityd
  run_command("launchctl remove UISpecRunnerDaemons") if @securityd_running
  @securityd_running = false
end

#with_env(env) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/uispecrunner/drivers/shell.rb', line 25

def with_env(env)
  before = env.inject({}) { |h, (k, _)| h[k] = ENV[k]; h }
  env.each { |k, v| ENV[k] = v }
  yield
ensure
  before.each { |k, v| ENV[k] = v }
end