Class: Thrust::Tasks::SpecRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/thrust/tasks/spec_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(out = $stdout, xcode_tools_provider = Thrust::XcodeToolsProvider.new, ios_spec_launcher = Thrust::IOSSpecLauncher.new, osx_spec_launcher = Thrust::OSXSpecLauncher.new, scheme_parser = Thrust::SchemeParser.new) ⇒ SpecRunner

Returns a new instance of SpecRunner.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/thrust/tasks/spec_runner.rb', line 7

def initialize(out = $stdout,
               xcode_tools_provider = Thrust::XcodeToolsProvider.new,
               ios_spec_launcher = Thrust::IOSSpecLauncher.new,
               osx_spec_launcher = Thrust::OSXSpecLauncher.new,
               scheme_parser = Thrust::SchemeParser.new)
  @xcode_tools_provider = xcode_tools_provider
  @ios_spec_launcher = ios_spec_launcher
  @osx_spec_launcher = osx_spec_launcher
  @scheme_parser = scheme_parser
  @out = out
end

Instance Method Details

#run(app_config, target_info, args) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/thrust/tasks/spec_runner.rb', line 19

def run(app_config, target_info, args)
  build_configuration = target_info.build_configuration
  type = target_info.type
  scheme = target_info.scheme
  build_sdk = target_info.build_sdk
  os_version = args[:os_version] || target_info.os_version
  device_name = args[:device_name] || target_info.device_name

  if device_name
    substitution_map = {'bundle' => '-', 'app' => ' '}
    destination_map = {'bundle' => ' ', 'app' => '-'}
    device_name.gsub!(substitution_map[type], destination_map[type])
  end

  xcode_tools = @xcode_tools_provider.instance(@out,
                                               build_configuration,
                                               app_config.build_directory,
                                               project_name: app_config.project_name,
                                               workspace_name: app_config.workspace_name)

  if type == 'app'
    xcode_tools.build_scheme(scheme, build_sdk)

    executable_name = xcode_tools.find_executable_name(scheme)
    environment_variables = @scheme_parser.parse_environment_variables(scheme, app_config.path_to_xcodeproj)
    environment_variables['CEDAR_RANDOM_SEED'] = ENV['CEDAR_RANDOM_SEED'] if ENV['CEDAR_RANDOM_SEED']

    if build_sdk.include?('macosx')
      @osx_spec_launcher.run(executable_name,
                             build_configuration,
                             app_config.build_directory,
                             environment_variables)
    else
      xcode_tools.kill_simulator

      @ios_spec_launcher.run(executable_name,
                             build_configuration,
                             build_sdk,
                             os_version,
                             device_name,
                             target_info.timeout,
                             app_config.build_directory,
                             app_config.ios_sim_path,
                             environment_variables)
    end
  else
    xcode_tools.test(scheme,
                     build_configuration,
                     os_version,
                     device_name,
                     target_info.timeout,
                     app_config.build_directory)
  end
end