class Turn::Reporter
There are two distinct way in which a report may be utilized by a Runner: per-call or per-file. The method pass, fail and error are generic, and will be used in either case. A per-call runner will use all the methods of a Reporter, while a per-file runner will use #start_case per file, and will not use the #start_test and #finish_test methods, since those are beyond it's grainularity.
Attributes
Where to send report, defaults to `$stdout`.
Public Class Methods
# File lib/turn/reporter.rb, line 20 def initialize(io, opts={}) @io = io || $stdout @trace = opts[:trace] @natural = opts[:natural] @verbose = opts[:verbose] @mark = opts[:mark].to_i end
Public Instance Methods
Invoked when a test raises an exception.
# File lib/turn/reporter.rb, line 51 def error(exception, message=nil) end
Invoked when a test raises an assertion.
# File lib/turn/reporter.rb, line 47 def fail(assertion, message=nil) end
Invoked after all tests in a testcase have ben run.
# File lib/turn/reporter.rb, line 63 def finish_case(test_case) end
After all tests are run, this is the last observable action.
# File lib/turn/reporter.rb, line 67 def finish_suite(test_suite) end
Invoked after a test has been run.
# File lib/turn/reporter.rb, line 59 def finish_test(test) end
Invoked when a test passes.
# File lib/turn/reporter.rb, line 43 def pass(message=nil) end
Invoked when a test is skipped.
# File lib/turn/reporter.rb, line 55 def skip(exception, message=nil) end
Invoked before a testcase is run.
# File lib/turn/reporter.rb, line 35 def start_case(test_case) end
At the very start, before any testcases are run, this is called.
# File lib/turn/reporter.rb, line 31 def start_suite(test_suite) end
Invoked before a test is run.
# File lib/turn/reporter.rb, line 39 def start_test(test) end
Private Instance Methods
Apply #filter_backtrace and #limit_backtrace in one go.
# File lib/turn/reporter.rb, line 73 def clean_backtrace(backtrace) limit_backtrace(filter_backtrace(backtrace)) end
Filter backtrace of unimportant entries, and applies count limit if set in configuration. Setting $DEBUG to true will deactivate filter, or if the filter happens to remove all backtrace entries it will revert to the full backtrace, as that probably means there was an issue with the test harness itself.
# File lib/turn/reporter.rb, line 92 def filter_backtrace(backtrace) return [] unless backtrace bt, pwd = backtrace.dup, Dir.pwd unless $DEBUG bt = bt.reject do |line| $RUBY_IGNORE_CALLERS.any?{|re| re =~ line} unless line.start_with?(pwd) end end bt = backtrace if bt.empty? # if empty just dump the whole thing bt.map{ |line| line.sub(pwd+'/', '') } end
Limit backtrace to number of lines if `trace` configuration option is set.
# File lib/turn/reporter.rb, line 105 def limit_backtrace(backtrace) return [] unless backtrace @trace ? backtrace[0, @trace.to_i] : backtrace end
Returns a more readable test name with spaces instead of underscores
# File lib/turn/reporter.rb, line 111 def naturalized_name(test) if @natural test.name.gsub("test_", "").gsub(/_/, " ") else test.name end end
# File lib/turn/reporter.rb, line 120 def ticktock t = Time.now - @time h, t = t.divmod(3600) m, t = t.divmod(60) s = t.truncate f = ((t - s) * 1000).to_i "%01d:%02d:%02d.%03d" % [h,m,s,f] end