Class: RSpecSystem::Formatter
- Inherits:
-
RSpec::Core::Formatters::BaseTextFormatter
- Object
- RSpec::Core::Formatters::BaseTextFormatter
- RSpecSystem::Formatter
- Defined in:
- lib/rspec-system/formatter.rb
Overview
This custom formatter is designed for rspec-system test presentation
Because rspec-system tests are often wordier and require lots of diagnostic information to be enabled for future debugging, the traditional document and progress formatters just simply aren’t sufficient.
This formatter instead treats each test as a document section, splitting up the output with obvious breaks so the user can clearly see when a test has started and finished. It also attempts to use color for visibility as well as listing test case information in a more verbose way.
Instance Method Summary collapse
-
#example_failed(example) ⇒ void
Display output when an example has failed.
-
#example_passed(example) ⇒ void
Display output when an example has passed.
-
#example_pending(example) ⇒ void
Display output when an example is pending.
-
#example_started(example) ⇒ void
Display output when an example has started.
-
#initialize(output) ⇒ Formatter
constructor
Initialize formatter.
-
#next_failure_index ⇒ Fixnum
private
Obtains next index value so we can keep a count of what test we are upto.
-
#start(count) ⇒ void
Display test start information.
Constructor Details
#initialize(output) ⇒ Formatter
Initialize formatter
16 17 18 |
# File 'lib/rspec-system/formatter.rb', line 16 def initialize(output) super(output) end |
Instance Method Details
#example_failed(example) ⇒ void
This method returns an undefined value.
Display output when an example has failed
65 66 67 68 69 70 71 |
# File 'lib/rspec-system/formatter.rb', line 65 def example_failed(example) super(example) msg = example.execution_result[:exception] output << "\n" << bold('Result: ') << failure_color('failed') << "\n" output << bold("Index: ") << "#{next_failure_index}\n" output << bold("Reason:\n") << "#{msg}\n\n" end |
#example_passed(example) ⇒ void
This method returns an undefined value.
Display output when an example has passed
45 46 47 48 |
# File 'lib/rspec-system/formatter.rb', line 45 def example_passed(example) super(example) output << "\n" << bold('Result: ') << success_color('passed') << "\n\n" end |
#example_pending(example) ⇒ void
This method returns an undefined value.
Display output when an example is pending
54 55 56 57 58 59 |
# File 'lib/rspec-system/formatter.rb', line 54 def example_pending(example) super(example) msg = example.execution_result[:pending_message] output << "\n" << bold('Result: ') << pending_color('pending') << "\n" output << bold("Reason: ") << "#{msg}\n\n" end |
#example_started(example) ⇒ void
This method returns an undefined value.
Display output when an example has started
35 36 37 38 39 |
# File 'lib/rspec-system/formatter.rb', line 35 def example_started(example) super(example) output << "=================================================================\n\n" output << bold("Running test:\n ") << color(example.full_description, :magenta) << "\n\n" end |
#next_failure_index ⇒ Fixnum
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Obtains next index value so we can keep a count of what test we are upto
77 78 79 80 |
# File 'lib/rspec-system/formatter.rb', line 77 def next_failure_index @next_failure_index ||= 0 @next_failure_index += 1 end |
#start(count) ⇒ void
This method returns an undefined value.
Display test start information
24 25 26 27 28 29 |
# File 'lib/rspec-system/formatter.rb', line 24 def start(count) super(count) output << "=================================================================\n\n" output << bold("Commencing rspec-system tests\n") output << bold("Total Test Count: ") << color(count, :cyan) << "\n\n" end |