Class: Rutidy::Formatter
- Inherits:
-
RSpec::Core::Formatters::BaseFormatter
- Object
- RSpec::Core::Formatters::BaseFormatter
- Rutidy::Formatter
- Defined in:
- lib/rutidy/formatter.rb
Overview
A real RSpec formatter (registered the same way RSpec's own built-in
DocumentationFormatter is), not a post-processor of some other
formatter's text output. example_group_started/example_group_finished
fire as the runner actually descends/ascends the real describe/context
tree, so @hierarchy always reflects genuine nesting -- unlike stock
rspec --format json, whose full_description field is every group's
description concatenated with plain spaces and no separator, which
can't be split back into a tree without guessing. This formatter never
needs to guess: every example gets its own hierarchy array straight
from the stack RSpec itself maintains.
Load with rspec --require rutidy/formatter --format Rutidy::Formatter,
or let rutidy's own CLI wrap that invocation for you.
Instance Method Summary collapse
- #close(_notification) ⇒ Object
- #dump_summary(summary) ⇒ Object
- #example_failed(notification) ⇒ Object
- #example_group_finished(_notification) ⇒ Object
- #example_group_started(notification) ⇒ Object
- #example_passed(notification) ⇒ Object
- #example_pending(notification) ⇒ Object
-
#initialize(output) ⇒ Formatter
constructor
A new instance of Formatter.
- #message(notification) ⇒ Object
- #seed(notification) ⇒ Object
Constructor Details
Instance Method Details
#close(_notification) ⇒ Object
74 75 76 |
# File 'lib/rutidy/formatter.rb', line 74 def close(_notification) output.write JSON.generate(@output_hash) end |
#dump_summary(summary) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/rutidy/formatter.rb', line 58 def dump_summary(summary) @output_hash[:summary] = { duration: summary.duration, example_count: summary.example_count, failure_count: summary.failure_count, pending_count: summary.pending_count } @output_hash[:summary_line] = summary.totals_line end |
#example_failed(notification) ⇒ Object
54 55 56 |
# File 'lib/rutidy/formatter.rb', line 54 def example_failed(notification) record(notification.example, notification) end |
#example_group_finished(_notification) ⇒ Object
42 43 44 |
# File 'lib/rutidy/formatter.rb', line 42 def example_group_finished(_notification) @hierarchy.pop end |
#example_group_started(notification) ⇒ Object
38 39 40 |
# File 'lib/rutidy/formatter.rb', line 38 def example_group_started(notification) @hierarchy << notification.group.description.strip end |
#example_passed(notification) ⇒ Object
46 47 48 |
# File 'lib/rutidy/formatter.rb', line 46 def example_passed(notification) record(notification.example) end |
#example_pending(notification) ⇒ Object
50 51 52 |
# File 'lib/rutidy/formatter.rb', line 50 def example_pending(notification) record(notification.example) end |
#message(notification) ⇒ Object
34 35 36 |
# File 'lib/rutidy/formatter.rb', line 34 def (notification) (@output_hash[:messages] ||= []) << notification. end |
#seed(notification) ⇒ Object
68 69 70 71 72 |
# File 'lib/rutidy/formatter.rb', line 68 def seed(notification) return unless notification.seed_used? @output_hash[:seed] = notification.seed end |