Class: Test::Runner

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

Overview

The Test::Runner class handles the execution of tests.

Constant Summary collapse

OPEN_ERRORS =

Exceptions that are not caught by test runner.

[NoMemoryError, SignalException, Interrupt, SystemExit]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil, &block) ⇒ Runner

New Runner.

Parameters:

  • config (Config) (defaults to: nil)

    Config instance.



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/rubytest/runner.rb', line 86

def initialize(config=nil, &block)
  if config
    @config = Hash === config ? Config.new(config) : config
  else
    @config = Test.configuration
  end

  block.call(@config) if block

  @advice = Advice.new
end

Instance Attribute Details

#configObject (readonly)

Handle all configuration via the config instance.



33
34
35
# File 'lib/rubytest/runner.rb', line 33

def config
  @config
end

#observersObject (readonly)

Array of observers, typically this just contains the recorder and reporter instances.



106
107
108
# File 'lib/rubytest/runner.rb', line 106

def observers
  @observers
end

#recorderObject (readonly)

Record pass, fail, error and pending tests.



102
103
104
# File 'lib/rubytest/runner.rb', line 102

def recorder
  @recorder
end

#reporterObject (readonly)

The reporter to use for ouput.



99
100
101
# File 'lib/rubytest/runner.rb', line 99

def reporter
  @reporter
end

Class Method Details

.run(config = nil, &config_proc) ⇒ Object

TODO: Wrap run in at_exit ?



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rubytest/runner.rb', line 17

def self.run(config=nil, &config_proc)
  runner = Runner.new(config, &config_proc)
  begin
    success = runner.run
    exit -1 unless success
  rescue => error
    raise error if $DEBUG
    $stderr.puts('ERROR: ' + error.to_s)
    exit -1
  end
end

Instance Method Details

#adviceObject

Instance of Advice is a special customizable observer.



59
60
61
# File 'lib/rubytest/runner.rb', line 59

def advice
  @advice
end

#after(type, &block) ⇒ Object

Define universal after advice. Can be used by mock libraries, for example to run mock verification.



70
71
72
# File 'lib/rubytest/runner.rb', line 70

def after(type, &block)
  advice.join_after(type, &block)
end

#before(type, &block) ⇒ Object

Define universal before advice.



64
65
66
# File 'lib/rubytest/runner.rb', line 64

def before(type, &block)
  advice.join_before(type, &block)
end

#formatObject

Reporter format name, or name fragment, used to look up reporter class.



49
50
51
# File 'lib/rubytest/runner.rb', line 49

def format
  config.format
end

#runBoolean

Run test suite.

Returns:

  • (Boolean)

    That the tests ran without error or failure.



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/rubytest/runner.rb', line 113

def run
  cd_chdir do
    Test::Config.load_path_setup if config.autopath?

    ignore_callers

    config.loadpath.each{ |path| $LOAD_PATH.unshift(path) }
    config.requires.each{ |file| require file }

    test_files.each do |test_file|
      require test_file
    end

    @reporter  = reporter_load(format)
    @recorder  = Recorder.new

    @observers = [advice, @recorder, @reporter]

    observers.each{ |o| o.begin_suite(suite) }
    run_thru(suite)
    observers.each{ |o| o.end_suite(suite) }
  end

  recorder.success?
end

#suiteObject

Test suite to run. This is a list of compliant test units and test cases.



36
37
38
# File 'lib/rubytest/runner.rb', line 36

def suite
  config.suite
end

#test_filesObject

TODO: Cache or not?



43
44
45
46
# File 'lib/rubytest/runner.rb', line 43

def test_files
  #@test_files ||= resolve_test_files
  resolve_test_files
end

#upon(type, &block) ⇒ Object

Define universal upon advice.

See Advice for valid join-points.



77
78
79
# File 'lib/rubytest/runner.rb', line 77

def upon(type, &block)
  advice.join(type, &block)
end

#verbose?Boolean

Show extra details in reports.

Returns:

  • (Boolean)


54
55
56
# File 'lib/rubytest/runner.rb', line 54

def verbose?
  config.verbose?
end