Class: Riot::IOReporter
Overview
An IOReporter is one that expects to use an IO object to output results to. Thus, whatever is available by an instance of an IO object should be available to whatever is given to this reporter to use.
This is an abstract class. You should use some other or define your own sub-class that knows how to handle pass
, fail
, and error
.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Reporter
#current_context, #errors, #failures, #passes
Instance Method Summary collapse
-
#filter_backtrace(backtrace, &line_handler) ⇒ Object
protected
Filters Riot and Rake method calls from an exception backtrace.
-
#format_error(e) ⇒ String
protected
Generates a message for assertions that error out.
- #green(str) ⇒ Object protected
-
#initialize(*args) ⇒ IOReporter
constructor
Creates a new IOReporter.
-
#line_info(line, file) ⇒ String
protected
Takes a line number, the file it corresponds to, and generates a formatted string for use in failure responses.
- #plain? ⇒ Boolean protected
-
#print(message) ⇒ Object
protected
Helper that knows how to write output to the writer without a newline.
-
#puts(message) ⇒ Object
protected
Helper that knows how to write output to the writer with a newline.
-
#red(str) ⇒ Object
protected
Color output.
-
#results(time_taken) ⇒ Object
Called after all contexts have finished.
-
#with_color(code, str) ⇒ Object
protected
for color reference: www.pixelbeat.org/docs/terminal_colours/.
- #yellow(str) ⇒ Object protected
Methods inherited from Reporter
#describe_context, #error, #fail, #new, #pass, #report, #success?, #summarize
Constructor Details
#initialize(*args) ⇒ IOReporter
Creates a new IOReporter. You can give it your own IO writer or it will default to STDOUT
. If you want to specifically turn colorization off in the output, pass the plain
option.
15 16 17 18 19 |
# File 'lib/riot/reporter/io.rb', line 15 def initialize(*args) super @options = args. @writer = (args.shift || STDOUT) end |
Instance Method Details
#filter_backtrace(backtrace, &line_handler) ⇒ Object (protected)
Filters Riot and Rake method calls from an exception backtrace.
63 64 65 66 67 |
# File 'lib/riot/reporter/io.rb', line 63 def filter_backtrace(backtrace, &line_handler) backtrace.reverse_each do |bt| yield bt unless (bt =~ /(\/lib\/riot|rake_test_loader)/) end end |
#format_error(e) ⇒ String (protected)
Generates a message for assertions that error out. However, in the additional stacktrace, any mentions of Riot and Rake framework methods calls are removed. Makes for a more readable error response.
53 54 55 56 57 |
# File 'lib/riot/reporter/io.rb', line 53 def format_error(e) format = [" #{e.class.name} occurred", "#{e.to_s}"] filter_backtrace(e.backtrace) { |line| format << " at #{line}" } format.join("\n") end |
#green(str) ⇒ Object (protected)
72 |
# File 'lib/riot/reporter/io.rb', line 72 def green(str); with_color(32, str); end |
#line_info(line, file) ⇒ String (protected)
Takes a line number, the file it corresponds to, and generates a formatted string for use in failure responses.
44 45 46 |
# File 'lib/riot/reporter/io.rb', line 44 def line_info(line, file) line ? "(on line #{line} in #{file})" : "" end |
#plain? ⇒ Boolean (protected)
74 75 76 |
# File 'lib/riot/reporter/io.rb', line 74 def plain? (@options[:plain] || @options["plain"]) end |
#print(message) ⇒ Object (protected)
Helper that knows how to write output to the writer without a newline.
36 |
# File 'lib/riot/reporter/io.rb', line 36 def print() @writer.print(); end |
#puts(message) ⇒ Object (protected)
Helper that knows how to write output to the writer with a newline.
31 |
# File 'lib/riot/reporter/io.rb', line 31 def puts() @writer.puts(); end |
#red(str) ⇒ Object (protected)
Color output
70 |
# File 'lib/riot/reporter/io.rb', line 70 def red(str); with_color(31, str); end |
#results(time_taken) ⇒ Object
Called after all contexts have finished. This is where the final results can be output.
22 23 24 25 |
# File 'lib/riot/reporter/io.rb', line 22 def results(time_taken) values = [passes, failures, errors, ("%0.6f" % time_taken)] puts "\n%d passes, %d failures, %d errors in %s seconds" % values end |
#with_color(code, str) ⇒ Object (protected)
for color reference: www.pixelbeat.org/docs/terminal_colours/
80 81 82 |
# File 'lib/riot/reporter/io.rb', line 80 def with_color(code,str) plain? ? str : "\e[#{code}m#{str}\e[0m" end |
#yellow(str) ⇒ Object (protected)
71 |
# File 'lib/riot/reporter/io.rb', line 71 def yellow(str); with_color(33, str); end |