Class: Riot::IOReporter

Inherits:
Reporter show all
Defined in:
lib/riot/reporter/io.rb

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

DotMatrixReporter, StoryReporter

Instance Attribute Summary

Attributes inherited from Reporter

#current_context, #errors, #failures, #passes

Instance Method Summary (collapse)

Methods inherited from Reporter

#describe_context, #error, #fail, #new, #pass, #report, #success?, #summarize

Constructor Details

- (IOReporter) initialize(*args)

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.extract_options!
  @writer = (args.shift || STDOUT)
end

Instance Method Details

- (Object) filter_backtrace(backtrace, &line_handler) (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

- (String) format_error(e) (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

- (Object) green(str) (protected)



72
# File 'lib/riot/reporter/io.rb', line 72

def green(str);  with_color(32, str); end

- (String) line_info(line, file) (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

- (Boolean) plain? (protected)



74
75
76
# File 'lib/riot/reporter/io.rb', line 74

def plain?
  (@options[:plain] || @options["plain"])
end

Helper that knows how to write output to the writer without a newline.



36
# File 'lib/riot/reporter/io.rb', line 36

def print(message) @writer.print(message); end

- (Object) puts(message) (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(message) @writer.puts(message); end

- (Object) red(str) (protected)

Color output



70
# File 'lib/riot/reporter/io.rb', line 70

def red(str);    with_color(31, str); end

- (Object) results(time_taken)

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

- (Object) with_color(code, str) (protected)



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

- (Object) yellow(str) (protected)



71
# File 'lib/riot/reporter/io.rb', line 71

def yellow(str); with_color(33, str); end