Class: Tst::Reporters::Plain
- Inherits:
-
Object
- Object
- Tst::Reporters::Plain
- Defined in:
- lib/tst/reporters/plain.rb
Direct Known Subclasses
Constant Summary collapse
- BACKTRACE_FILTER =
/lib\/tst\.rb|bin\/tst|\/(ruby|jruby|rbx)[-\/]([0-9\.])+|Rakefile/
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
Returns the value of attribute io.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
- #backtrace(trace) ⇒ Object
- #conclusion ⇒ Object
- #exception(result) ⇒ Object
- #exception_details(name, exception, i) ⇒ Object
- #exception_header(name, exception, i) ⇒ Object
- #exceptions ⇒ Object
- #expected_actual(exception) ⇒ Object
- #failed ⇒ Object
- #failure(result) ⇒ Object
- #failure_details(name, exception, i) ⇒ Object
- #failure_header(name, exception, i) ⇒ Object
- #failures ⇒ Object
- #filter_backtrace(backtrace) ⇒ Object
-
#initialize(io = $stdout) ⇒ Plain
constructor
A new instance of Plain.
- #passed ⇒ Object
- #raised ⇒ Object
- #success(result) ⇒ Object
- #summarize(results) ⇒ Object
Constructor Details
#initialize(io = $stdout) ⇒ Plain
Returns a new instance of Plain.
6 7 8 |
# File 'lib/tst/reporters/plain.rb', line 6 def initialize(io = $stdout) @io = io end |
Instance Attribute Details
#io ⇒ Object (readonly)
Returns the value of attribute io.
4 5 6 |
# File 'lib/tst/reporters/plain.rb', line 4 def io @io end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
4 5 6 |
# File 'lib/tst/reporters/plain.rb', line 4 def results @results end |
Instance Method Details
#backtrace(trace) ⇒ Object
61 62 63 |
# File 'lib/tst/reporters/plain.rb', line 61 def backtrace(trace) filter_backtrace(trace).map { |line| "* #{line}" }.join("\n") end |
#conclusion ⇒ Object
65 66 67 |
# File 'lib/tst/reporters/plain.rb', line 65 def conclusion [ "#{passed}, #{failed}, #{raised} in %.6fs" % results.elapsed ] end |
#exception(result) ⇒ Object
12 |
# File 'lib/tst/reporters/plain.rb', line 12 def exception(result) io.print('E') end |
#exception_details(name, exception, i) ⇒ Object
50 51 52 53 54 |
# File 'lib/tst/reporters/plain.rb', line 50 def exception_details(name, exception, i) [ exception_header(name, exception, i), backtrace(exception.backtrace), "" ] end |
#exception_header(name, exception, i) ⇒ Object
56 57 58 |
# File 'lib/tst/reporters/plain.rb', line 56 def exception_header(name, exception, i) "E#{i+1}: #{exception.inspect} - #{name.inspect}" end |
#exceptions ⇒ Object
44 45 46 47 48 |
# File 'lib/tst/reporters/plain.rb', line 44 def exceptions results.exceptions.each_with_index.flat_map do |exception, i| exception_details(exception.name, exception.exception, i) end end |
#expected_actual(exception) ⇒ Object
38 39 40 41 42 |
# File 'lib/tst/reporters/plain.rb', line 38 def expected_actual(exception) [" exp: #{exception.expected.inspect}", " got: #{exception.actual.inspect}" ].join("\n") end |
#failed ⇒ Object
70 |
# File 'lib/tst/reporters/plain.rb', line 70 def failed; "#{results.failures.count} failed" end |
#failure(result) ⇒ Object
11 |
# File 'lib/tst/reporters/plain.rb', line 11 def failure(result) io.print('F') end |
#failure_details(name, exception, i) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/tst/reporters/plain.rb', line 27 def failure_details(name, exception, i) [ failure_header(name, exception, i), expected_actual(exception), backtrace(exception.backtrace), "" ] end |
#failure_header(name, exception, i) ⇒ Object
34 35 36 |
# File 'lib/tst/reporters/plain.rb', line 34 def failure_header(name, exception, i) "F#{i+1}: #{exception.} - #{name.inspect}" end |
#failures ⇒ Object
21 22 23 24 25 |
# File 'lib/tst/reporters/plain.rb', line 21 def failures results.failures.each_with_index.flat_map do |failure, i| failure_details(failure.name, failure.exception, i) end end |
#filter_backtrace(backtrace) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/tst/reporters/plain.rb', line 73 def filter_backtrace(backtrace) backtrace.reject do |line| line =~ BACKTRACE_FILTER end.map do |line| line.gsub("#{Dir.pwd}/", "").gsub(/:in.*$/, '') end end |
#passed ⇒ Object
69 |
# File 'lib/tst/reporters/plain.rb', line 69 def passed; "#{results.successes.count} passed" end |
#raised ⇒ Object
71 |
# File 'lib/tst/reporters/plain.rb', line 71 def raised; "#{results.exceptions.count} raised" end |
#success(result) ⇒ Object
10 |
# File 'lib/tst/reporters/plain.rb', line 10 def success(result) io.print('.') end |
#summarize(results) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/tst/reporters/plain.rb', line 14 def summarize(results) @results = results summary = ["\n"] + failures + exceptions + conclusion summary.each { |line| io.puts(line) } nil end |