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:



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rubytest/runner.rb', line 69

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

#config ⇒ Object (readonly)

Handle all configuration via the config instance.



84
85
86
# File 'lib/rubytest/runner.rb', line 84

def config
  @config
end

#observers ⇒ Object (readonly)

Execution hooks and the reporting pipeline entry point.



139
140
141
# File 'lib/rubytest/runner.rb', line 139

def observers
  @observers
end

#recorder ⇒ Object (readonly)

Record pass, fail, error and pending tests.



136
137
138
# File 'lib/rubytest/runner.rb', line 136

def recorder
  @recorder
end

#reporter ⇒ Object (readonly)

The reporter to use for ouput.



133
134
135
# File 'lib/rubytest/runner.rb', line 133

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.



56
57
58
59
# File 'lib/rubytest/runner.rb', line 56

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

Instance Method Details

#advice ⇒ Object

Instance of Advice is a special customizable observer.



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

def advice
  @advice
end

#after(type, &block) ⇒ Object

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



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

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

#before(type, &block) ⇒ Object

Define universal before advice.



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

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

#format ⇒ Object

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



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

def format
  config.format
end

#run ⇒ Boolean

Run test suite.

Returns:

  • (Boolean) —

    That the tests ran without error or failure.



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/rubytest/runner.rb', line 146

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

    begin
      test_files.each do |test_file|
        require test_file
      end

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

      @observers = [advice, @recorder]

      started = false
      begin
        advice.begin_suite(suite)
        recorder.begin_suite(suite)
        started = true
        run_thru(suite)
      ensure
        if started
          begin
            advice.end_suite(suite)
          ensure
            recorder.end_suite(suite)
          end
        end
      end
    ensure
      config.after.call if config.after
    end
  end

  recorder.success?
end

#suite ⇒ Object

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



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

def suite
  config.suite
end

#test_files ⇒ Object

TODO: Cache or not?



94
95
96
97
# File 'lib/rubytest/runner.rb', line 94

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.



128
129
130
# File 'lib/rubytest/runner.rb', line 128

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

#verbose? ⇒ Boolean

Show extra details in reports.

Returns:

  • (Boolean)


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

def verbose?
  config.verbose?
end