Class: RSpecDoc::MarkdownFormatter
- Inherits:
-
Object
- Object
- RSpecDoc::MarkdownFormatter
- Defined in:
- lib/rspec-doc/markdown_formatter.rb
Instance Attribute Summary collapse
-
#example_group ⇒ Object
All formatters inheriting from this formatter will receive these notifications.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
- #close(_notification) ⇒ Object
-
#dump_failures(notification) ⇒ Object
Dumps detailed information about each example failure.
- #dump_pending(notification) ⇒ Object
-
#dump_summary(summary) ⇒ Object
This method is invoked after the dumping of examples and failures.
- #example_failed(failure) ⇒ Object
- #example_finished(notification) ⇒ Object
- #example_group_finished(_notification) ⇒ Object
- #example_group_started(notification) ⇒ Object
- #example_passed(passed) ⇒ Object
- #example_pending(pending) ⇒ Object
-
#initialize(output) ⇒ MarkdownFormatter
constructor
A new instance of MarkdownFormatter.
-
#message(notification) ⇒ Object
Used by the reporter to send messages to the output stream.
- #output_doc(example) ⇒ Object
- #seed(notification) ⇒ Object
- #start(notification) ⇒ Object
Constructor Details
#initialize(output) ⇒ MarkdownFormatter
Returns a new instance of MarkdownFormatter.
16 17 18 19 20 |
# File 'lib/rspec-doc/markdown_formatter.rb', line 16 def initialize(output) @output = output || StringIO.new @example_group = nil @group_level = 0 end |
Instance Attribute Details
#example_group ⇒ Object
All formatters inheriting from this formatter will receive these notifications.
10 11 12 |
# File 'lib/rspec-doc/markdown_formatter.rb', line 10 def example_group @example_group end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
11 12 13 |
# File 'lib/rspec-doc/markdown_formatter.rb', line 11 def output @output end |
Instance Method Details
#close(_notification) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/rspec-doc/markdown_formatter.rb', line 35 def close(_notification) return if output.closed? output.puts output.flush end |
#dump_failures(notification) ⇒ Object
Dumps detailed information about each example failure.
57 58 59 60 |
# File 'lib/rspec-doc/markdown_formatter.rb', line 57 def dump_failures(notification) return if notification.failure_notifications.empty? output.puts notification.fully_formatted_failed_examples end |
#dump_pending(notification) ⇒ Object
74 75 76 77 |
# File 'lib/rspec-doc/markdown_formatter.rb', line 74 def dump_pending(notification) return if notification.pending_examples.empty? output.puts notification.fully_formatted_pending_examples end |
#dump_summary(summary) ⇒ Object
This method is invoked after the dumping of examples and failures. Each parameter is assigned to a corresponding attribute.
69 70 71 |
# File 'lib/rspec-doc/markdown_formatter.rb', line 69 def dump_summary(summary) output.puts summary.fully_formatted end |
#example_failed(failure) ⇒ Object
122 123 124 125 |
# File 'lib/rspec-doc/markdown_formatter.rb', line 122 def example_failed(failure) output.puts failure_output(failure.example) output_doc(failure.example) end |
#example_finished(notification) ⇒ Object
95 96 |
# File 'lib/rspec-doc/markdown_formatter.rb', line 95 def example_finished(notification) end |
#example_group_finished(_notification) ⇒ Object
91 92 93 |
# File 'lib/rspec-doc/markdown_formatter.rb', line 91 def example_group_finished(_notification) @group_level -= 1 if @group_level > 0 end |
#example_group_started(notification) ⇒ Object
85 86 87 88 89 |
# File 'lib/rspec-doc/markdown_formatter.rb', line 85 def example_group_started(notification) output.puts if @group_level == 0 output.puts "#{current_indentation}#{notification.group.description.strip}" @group_level += 1 end |
#example_passed(passed) ⇒ Object
111 112 113 114 |
# File 'lib/rspec-doc/markdown_formatter.rb', line 111 def example_passed(passed) output.puts passed_output(passed.example) output_doc(passed.example) end |
#example_pending(pending) ⇒ Object
116 117 118 119 120 |
# File 'lib/rspec-doc/markdown_formatter.rb', line 116 def example_pending(pending) output.puts pending_output(pending.example, pending.example.execution_result.) output_doc(pending.example) end |
#message(notification) ⇒ Object
Used by the reporter to send messages to the output stream.
48 49 50 |
# File 'lib/rspec-doc/markdown_formatter.rb', line 48 def (notification) output.puts "#{space_indentation}#{notification.}" end |
#output_doc(example) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/rspec-doc/markdown_formatter.rb', line 98 def output_doc(example) return unless example.[:md_doc].is_a? Hash output.puts example.[:md_doc].each do |key, items| output.puts " #{space_indentation}#### #{key.to_s.split('_').map(&:capitalize).join(' ')}" items.each do |item| output.puts item.each_line { |line| output.puts " #{space_indentation}#{line}" } end end example.[:md_doc] = {} end |
#seed(notification) ⇒ Object
80 81 82 83 |
# File 'lib/rspec-doc/markdown_formatter.rb', line 80 def seed(notification) return unless notification.seed_used? output.puts notification.fully_formatted end |
#start(notification) ⇒ Object
26 27 28 29 |
# File 'lib/rspec-doc/markdown_formatter.rb', line 26 def start(notification) start_sync_output @example_count = notification.count end |