Class: RSpecDoc::MarkdownFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec-doc/markdown_formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ MarkdownFormatter

Returns a new instance of MarkdownFormatter.

Parameters:

  • output (IO)

    the formatter output

See Also:

  • RSpec::Core::Formatters::Protocol#initialize


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_groupObject

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

#outputObject (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

Parameters:

  • _notification (NullNotification)

    (Ignored)

See Also:

  • RSpec::Core::Formatters::Protocol#close


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.

Parameters:

  • notification (NullNotification)


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.

Parameters:

  • summary (SummaryNotification)

    containing duration, example_count, failure_count and pending_count



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.pending_message)
  output_doc(pending.example)
end

#message(notification) ⇒ Object

Used by the reporter to send messages to the output stream.

Parameters:

  • notification (MessageNotification)

    containing message



48
49
50
# File 'lib/rspec-doc/markdown_formatter.rb', line 48

def message(notification)
  output.puts "#{space_indentation}#{notification.message}"
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

Parameters:

  • notification (StartNotification)

See Also:

  • RSpec::Core::Formatters::Protocol#start


26
27
28
29
# File 'lib/rspec-doc/markdown_formatter.rb', line 26

def start(notification)
  start_sync_output
  @example_count = notification.count
end