Class: GARunner

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

Overview

Author:

  • Vittorio Monaco

Instance Method Summary collapse

Constructor Details

#initialize(configuration, filename) ⇒ GARunner

Note:

filename can also be a tests file

Creates a new instance given a GAConfiguration object and a filename to run tests

Parameters:

  • configuration (GAConfiguration)

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

  • filename (String)

    the name of the file you want to run the tests for



13
14
15
16
17
# File 'lib/ga_runner.rb', line 13

def initialize(configuration, filename)
    @configuration=configuration
    @filename=filename
    @runner=XcodebuildRunner.new(configuration)
end

Instance Method Details

#codeFilenameString

Returns the code file corresponding to @filename, stripping the suffix if @filename is a test file.

Returns:

  • (String)

    the code file corresponding to @filename, stripping the suffix if @filename is a test file



50
51
52
53
54
55
56
57
58
# File 'lib/ga_runner.rb', line 50

def codeFilename() 
  suffix = @configuration.suffix
  stripped = @filename
  if isTest()
    stripped = @filename.slice(/(?<file>.*)#{suffix}$/, "file")
  end
  
  return stripped
end

#isTestObject

Returns true if the filename is a tests file.

Returns:

  • true if the filename is a tests file



45
46
47
# File 'lib/ga_runner.rb', line 45

def isTest()
  return @filename.end_with? @configuration.suffix
end

#testObject

Tries to run unit tests for the filename setup during initialization

(see #testIfAvailable)



39
40
41
42
# File 'lib/ga_runner.rb', line 39

def test()    
  @runner.prepareForFile(@filename)
  testIfAvailable(codeFilename())
end

#testIfAvailable(filename) ⇒ Object

Note:

filename must be a code file, not a tests file. If you’re not sure whether the file is a tests file or not, use #test instead

Note:

if a corresponding tests file cannot be found, outputs a warning line

Runs unit tests for the given filename, if a tests file exists

Parameters:

  • filename (String)

    the file you want to run tests for



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ga_runner.rb', line 24

def testIfAvailable(filename)
    suffix = @configuration.suffix
    
    fileExists = system("find . | grep '" + filename + suffix + "' > /dev/null")
    if !fileExists
      GALogger.log(filename + " doesn't seem to have associated tests. You should think about creating some.", :Warning)
      return
    end
    
    @runner.test(filename)
end