Class: RSpec::Core::Formatters::DocumentationFormatter

Inherits:
BaseTextFormatter show all
Defined in:
lib/rspec/legacy_formatters/documentation_formatter.rb

Constant Summary

Constants inherited from BaseTextFormatter

BaseTextFormatter::VT100_COLORS, BaseTextFormatter::VT100_COLOR_CODES

Constants included from Helpers

Helpers::DEFAULT_PRECISION, Helpers::SUB_SECOND_PRECISION

Instance Attribute Summary

Attributes inherited from BaseFormatter

#duration, #example_count, #example_group, #examples, #failed_examples, #failure_count, #output, #pending_count, #pending_examples

Instance Method Summary collapse

Methods inherited from BaseTextFormatter

#close, #color_code_for, #colorise_summary, #colorize, #dump_commands_to_rerun_failed_examples, #dump_failures, #dump_pending, #dump_profile, #dump_profile_slowest_example_groups, #dump_profile_slowest_examples, #dump_summary, #message, #seed, #summary_line

Methods inherited from BaseFormatter

#close, #dump_failures, #dump_pending, #dump_summary, #example_started, #format_backtrace, #message, #start, #start_dump, #stop

Methods included from Helpers

#format_duration, #format_seconds, #pluralize, #strip_trailing_zeroes

Methods included from LegacyBacktraceFormatter

#format_backtrace

Constructor Details

#initialize(output) ⇒ DocumentationFormatter

Returns a new instance of DocumentationFormatter.


9
10
11
12
# File 'lib/rspec/legacy_formatters/documentation_formatter.rb', line 9

def initialize(output)
  super(output)
  @group_level = 0
end

Instance Method Details

#current_indentationvoid


59
60
61
# File 'lib/rspec/legacy_formatters/documentation_formatter.rb', line 59

def current_indentation
  '  ' * @group_level
end

#example_failed(example) ⇒ void


37
38
39
40
# File 'lib/rspec/legacy_formatters/documentation_formatter.rb', line 37

def example_failed(example)
  super(example)
  output.puts failure_output(example, example.execution_result.exception)
end

#example_group_chainvoid


63
64
65
# File 'lib/rspec/legacy_formatters/documentation_formatter.rb', line 63

def example_group_chain
  example_group.parent_groups.reverse
end

#example_group_finished(example_group) ⇒ void


23
24
25
# File 'lib/rspec/legacy_formatters/documentation_formatter.rb', line 23

def example_group_finished(example_group)
  @group_level -= 1
end

#example_group_started(example_group) ⇒ void


14
15
16
17
18
19
20
21
# File 'lib/rspec/legacy_formatters/documentation_formatter.rb', line 14

def example_group_started(example_group)
  super(example_group)

  output.puts if @group_level == 0
  output.puts "#{current_indentation}#{example_group.description.strip}"

  @group_level += 1
end

#example_passed(example) ⇒ void


27
28
29
30
# File 'lib/rspec/legacy_formatters/documentation_formatter.rb', line 27

def example_passed(example)
  super(example)
  output.puts passed_output(example)
end

#example_pending(example) ⇒ void


32
33
34
35
# File 'lib/rspec/legacy_formatters/documentation_formatter.rb', line 32

def example_pending(example)
  super(example)
  output.puts pending_output(example, example.execution_result.pending_message)
end

#failure_output(example, exception) ⇒ void


42
43
44
# File 'lib/rspec/legacy_formatters/documentation_formatter.rb', line 42

def failure_output(example, exception)
  failure_color("#{current_indentation}#{example.description.strip} (FAILED - #{next_failure_index})")
end

#next_failure_indexvoid


46
47
48
49
# File 'lib/rspec/legacy_formatters/documentation_formatter.rb', line 46

def next_failure_index
  @next_failure_index ||= 0
  @next_failure_index += 1
end

#passed_output(example) ⇒ void


51
52
53
# File 'lib/rspec/legacy_formatters/documentation_formatter.rb', line 51

def passed_output(example)
  success_color("#{current_indentation}#{example.description.strip}")
end

#pending_output(example, message) ⇒ void


55
56
57
# File 'lib/rspec/legacy_formatters/documentation_formatter.rb', line 55

def pending_output(example, message)
  pending_color("#{current_indentation}#{example.description.strip} (PENDING: #{message})")
end