Class: Test::Runner
- Inherits:
-
Object
- Object
- Test::Runner
- 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
-
#config ⇒ Object
readonly
Handle all configuration via the config instance.
-
#observers ⇒ Object
readonly
Array of observers, typically this just contains the recorder and reporter instances.
-
#recorder ⇒ Object
readonly
Record pass, fail, error and pending tests.
-
#reporter ⇒ Object
readonly
The reporter to use for ouput.
Class Method Summary collapse
-
.run(config = nil, &config_proc) ⇒ Object
TODO: Wrap run in at_exit ?.
Instance Method Summary collapse
-
#advice ⇒ Object
Instance of Advice is a special customizable observer.
-
#after(type, &block) ⇒ Object
Define universal after advice.
-
#before(type, &block) ⇒ Object
Define universal before advice.
-
#format ⇒ Object
Reporter format name, or name fragment, used to look up reporter class.
-
#initialize(config = nil, &block) ⇒ Runner
constructor
New Runner.
-
#run ⇒ Boolean
Run test suite.
-
#suite ⇒ Object
Test suite to run.
-
#test_files ⇒ Object
TODO: Cache or not?.
-
#upon(type, &block) ⇒ Object
Define universal upon advice.
-
#verbose? ⇒ Boolean
Show extra details in reports.
Constructor Details
#initialize(config = nil, &block) ⇒ Runner
New Runner.
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
#config ⇒ Object (readonly)
Handle all configuration via the config instance.
33 34 35 |
# File 'lib/rubytest/runner.rb', line 33 def config @config end |
#observers ⇒ Object (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 |
#recorder ⇒ Object (readonly)
Record pass, fail, error and pending tests.
102 103 104 |
# File 'lib/rubytest/runner.rb', line 102 def recorder @recorder end |
#reporter ⇒ Object (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
#advice ⇒ Object
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 |
#format ⇒ Object
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 |
#run ⇒ Boolean
Run test suite.
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 |
#suite ⇒ Object
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_files ⇒ Object
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.
54 55 56 |
# File 'lib/rubytest/runner.rb', line 54 def verbose? config.verbose? end |