Class: XctoolRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/xctool_runner.rb

Overview

Author:

  • Vittorio Monaco

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ XctoolRunner

Creates a new instance given a GAConfiguration object

Parameters:

  • configuration (GAConfiguration)

    the configuration you want to use to build and run the tests (see #GAConfiguration)



8
9
10
# File 'lib/xctool_runner.rb', line 8

def initialize(configuration)
  @configuration=configuration
end

Instance Method Details

#buildObject

Note:

This method supports both workspace- and project-based environments

Builds the tests target through xctool



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/xctool_runner.rb', line 25

def build()
  workspace = @configuration.workspace
  scheme = @configuration.scheme
  target = @configuration.target
  project = @configuration.project
  xctool = @configuration.xctool_path
  
  building = workspace
  building = project if workspace.nil?
  
  GALogger.log("Building " + building + " with scheme " + scheme + "...")
  
  toBuild = buildArgument()
  system(xctool + toBuild + 
         ' -scheme ' + scheme +
         ' -sdk iphonesimulator' +
         ' build-tests', out: $stdout, err: :out)
end

#buildArgumentObject

Returns the main argument for xctool to build the project/workspace

Example: -workspace ‘MyWorkspace.xcworkspace’ or -project ‘MyProject.xcodeproj’



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/xctool_runner.rb', line 50

def buildArgument()
   workspace = @configuration.workspace
   scheme = @configuration.scheme
   project = @configuration.project
   
   toBuild = ''
   if workspace.nil?
     toBuild = " -project '" + project + ".xcodeproj'"
   else  
     toBuild = " -workspace '" + workspace + ".xcworkspace'"
   end 
   
   return toBuild
end

#prepareForFile(filename) ⇒ Object

Note:

since xctool needs to build the tests every time, this method just calls build

Tells the runner to prepare the environment for a subsequent test run

(see #build)

Parameters:

  • filename (String)

    the name of the file the caller wishes to test



18
19
20
# File 'lib/xctool_runner.rb', line 18

def prepareForFile(filename)
  build()
end

#test(filename) ⇒ Object

Note:

This method supports both workspace- and project-based environments

Runs tests for the specified file

Parameters:

  • filename (String)

    the file you wish to run the tests for



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/xctool_runner.rb', line 69

def test(filename)
  scheme = @configuration.scheme
  target = @configuration.target
  xctool = @configuration.xctool_path
  reporter = @configuration.reporter
  suffix = @configuration.suffix
  
  GALogger.log("Running tests for file " + filename + '...')
  
  toBuild = buildArgument()
  system(xctool + toBuild +
         ' -scheme ' + scheme +
         ' -sdk iphonesimulator' +
         ' run-tests' +
         ' only ' + target + ':' + filename + suffix +
         ' -reporter ' + reporter, out: $stdout, err: :out)
end