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) {|@config| ... } ⇒ Runner

New Runner.

Parameters:

  • config (Config)

    Config instance.

Yields:



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

def initialize(config) #:yield:
  @config = case config
    when Config then config
    when Hash   then Config.new(config)
    else Test.configuration(config)
  end

  @config.apply!  # apply lazy config block

  yield(@config) if block_given?

  @advice = Advice.new
end

Instance Attribute Details

#configObject (readonly)

Handle all configuration via the config instance.



66
67
68
# File 'lib/rubytest/runner.rb', line 66

def config
  @config
end

#observersObject (readonly)

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



122
123
124
# File 'lib/rubytest/runner.rb', line 122

def observers
  @observers
end

#recorderObject (readonly)

Record pass, fail, error and pending tests.



118
119
120
# File 'lib/rubytest/runner.rb', line 118

def recorder
  @recorder
end

#reporterObject (readonly)

The reporter to use for ouput.



115
116
117
# File 'lib/rubytest/runner.rb', line 115

def reporter
  @reporter
end

Class Method Details

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

Run tests.

Parameters:

  • config (Config, Hash, String, Symbol) (defaults to: nil)

    Either a Config instance, a hash to construct a Config instance with, or a name of a configuration profile.

Returns:

  • (Boolean)

    Success of test run.



38
39
40
41
# File 'lib/rubytest/runner.rb', line 38

def self.run(config=nil, &config_proc) #:yield:
  runner = Runner.new(config, &config_proc)
  runner.run
end

Instance Method Details

#adviceObject

Instance of Advice is a special customizable observer.



92
93
94
# File 'lib/rubytest/runner.rb', line 92

def advice
  @advice
end

#after(type, &block) ⇒ Object

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



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

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

#before(type, &block) ⇒ Object

Define universal before advice.



97
98
99
# File 'lib/rubytest/runner.rb', line 97

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

#formatObject

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



82
83
84
# File 'lib/rubytest/runner.rb', line 82

def format
  config.format
end

#runBoolean

Run test suite.

Returns:

  • (Boolean)

    That the tests ran without error or failure.



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/rubytest/runner.rb', line 129

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

    ignore_callers

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

    # Config before advice occurs after loadpath and require are
    # applied and before test files are required.
    config.before.call if config.before

    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) }

    config.after.call if config.after
  end

  recorder.success?
end

#suiteObject

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



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

def suite
  config.suite
end

#test_filesObject

TODO: Cache or not?



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

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.



110
111
112
# File 'lib/rubytest/runner.rb', line 110

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

#verbose?Boolean

Show extra details in reports.

Returns:

  • (Boolean)


87
88
89
# File 'lib/rubytest/runner.rb', line 87

def verbose?
  config.verbose?
end