Class: Rocha::Formatter
- Inherits:
-
Object
- Object
- Rocha::Formatter
- Defined in:
- lib/rocha/formatter.rb
Instance Attribute Summary collapse
-
#examples ⇒ Object
readonly
Returns the value of attribute examples.
-
#io ⇒ Object
readonly
Returns the value of attribute io.
Instance Method Summary collapse
- #close ⇒ Object
- #dump_failures ⇒ Object
- #dump_pending ⇒ Object
- #dump_summary(duration, example_count, failure_count, pending_count) ⇒ Object
- #example_failed(example) ⇒ Object
- #example_group_finished(group) ⇒ Object
- #example_group_started(group) ⇒ Object
- #example_passed(example) ⇒ Object
- #example_pending(example) ⇒ Object
- #example_started(example) ⇒ Object
-
#initialize(io) ⇒ Formatter
constructor
A new instance of Formatter.
- #seed(seed) ⇒ Object
- #start(expected_example_count = nil) ⇒ Object
- #start_dump ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(io) ⇒ Formatter
Returns a new instance of Formatter.
7 8 9 10 |
# File 'lib/rocha/formatter.rb', line 7 def initialize(io) @io = io @examples = [] end |
Instance Attribute Details
#examples ⇒ Object (readonly)
Returns the value of attribute examples.
5 6 7 |
# File 'lib/rocha/formatter.rb', line 5 def examples @examples end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
5 6 7 |
# File 'lib/rocha/formatter.rb', line 5 def io @io end |
Instance Method Details
#close ⇒ Object
63 64 65 |
# File 'lib/rocha/formatter.rb', line 63 def close io.close if IO === io && io != $stdout end |
#dump_failures ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/rocha/formatter.rb', line 46 def dump_failures failed_examples = examples.select(&:failed?) if failed_examples.present? io.puts "" io.puts(failed_examples.map {|example| (example)}.join("\n\n")) end end |
#dump_pending ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/rocha/formatter.rb', line 38 def dump_pending pending_examples = examples.select(&:pending?) if pending_examples.present? io.puts "" io.puts(pending_examples.map {|example| (example)}.join("\n\n")) end end |
#dump_summary(duration, example_count, failure_count, pending_count) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/rocha/formatter.rb', line 54 def dump_summary(duration, example_count, failure_count, pending_count) seconds = "%.2f" % duration io.puts "" io.puts "Finished in #{seconds} seconds" io.puts "#{example_count} examples, #{failure_count} failed, #{pending_count} pending" end |
#example_failed(example) ⇒ Object
21 22 23 24 |
# File 'lib/rocha/formatter.rb', line 21 def example_failed(example) @examples << example io.write("F".red) end |
#example_group_finished(group) ⇒ Object
31 |
# File 'lib/rocha/formatter.rb', line 31 def example_group_finished(group); end |
#example_group_started(group) ⇒ Object
13 |
# File 'lib/rocha/formatter.rb', line 13 def example_group_started(group); end |
#example_passed(example) ⇒ Object
16 17 18 19 |
# File 'lib/rocha/formatter.rb', line 16 def example_passed(example) @examples << example io.write(".".green) end |
#example_pending(example) ⇒ Object
26 27 28 29 |
# File 'lib/rocha/formatter.rb', line 26 def example_pending(example) @examples << example io.write("P".yellow) end |
#example_started(example) ⇒ Object
14 |
# File 'lib/rocha/formatter.rb', line 14 def example_started(example); end |
#seed(seed) ⇒ Object
61 |
# File 'lib/rocha/formatter.rb', line 61 def seed(seed); end |
#start(expected_example_count = nil) ⇒ Object
12 |
# File 'lib/rocha/formatter.rb', line 12 def start(expected_example_count=nil); end |
#start_dump ⇒ Object
34 35 36 |
# File 'lib/rocha/formatter.rb', line 34 def start_dump io.puts "" end |
#stop ⇒ Object
32 |
# File 'lib/rocha/formatter.rb', line 32 def stop; end |