Class: Splot::Runner

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRunner

Returns a new instance of Runner.



9
10
11
# File 'lib/splot/runner.rb', line 9

def initialize
  @params = {}
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'lib/splot/runner.rb', line 3

def params
  @params
end

Class Method Details

.run!Object



5
6
7
# File 'lib/splot/runner.rb', line 5

def self.run!
  new.tap(&:parse).run!
end

Instance Method Details

#commandObject



13
14
15
# File 'lib/splot/runner.rb', line 13

def command
  ::Splot.command params
end

#parseObject



17
18
19
20
# File 'lib/splot/runner.rb', line 17

def parse
  parse_splotrc
  parse_command_line_arguments
end

#parse_command_line_argumentsObject



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
# File 'lib/splot/runner.rb', line 22

def parse_command_line_arguments
  OptionParser.new do |opts|
    opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [options]"

    opts.on('-f', '--file FILE', 'Run test for a given FILE') do |file|
      params[:file] = file
    end

    opts.on('-i', '--include-path PATH', 'Add an include PATH') do |path|
      params[:include_path] = path
    end

    opts.on('-l', '--line LINE', 'Only run test on LINE') do |line|
      params[:line] = line.to_i
    end

    opts.on('-r', '--runner RUNNER', 'Specify alternate runner') do |runner|
      params[:runner] = runner
    end

    opts.on('-p', '--preloader PRELOADER', 'Use e.g. zeus or spring to preload the environment') do |preloader|
      params[:preloader] = preloader
    end
  end.parse!
end

#parse_splotrcObject



48
49
50
# File 'lib/splot/runner.rb', line 48

def parse_splotrc
  params[:config_file] = splotrc if File.size? splotrc
end

#run!Object



52
53
54
55
56
57
# File 'lib/splot/runner.rb', line 52

def run!
  Kernel.exec command
rescue RunnerNotFoundError => e
  warn "Warning: #{e}; will not run any test"
  exit 2
end