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

Inherits:
BaseTextFormatter show all
Defined in:
lib/rspec/core/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 BacktraceFormatter

#format_backtrace

Constructor Details

#initialize(output) ⇒ DocumentationFormatter

Returns a new instance of DocumentationFormatter.


7
8
9
10
# File 'lib/rspec/core/formatters/documentation_formatter.rb', line 7

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

Instance Method Details

#current_indentationObject


57
58
59
# File 'lib/rspec/core/formatters/documentation_formatter.rb', line 57

def current_indentation
  '  ' * @group_level
end

#example_failed(example) ⇒ Object


35
36
37
38
# File 'lib/rspec/core/formatters/documentation_formatter.rb', line 35

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

#example_group_chainObject


61
62
63
# File 'lib/rspec/core/formatters/documentation_formatter.rb', line 61

def example_group_chain
  example_group.parent_groups.reverse
end

#example_group_finished(example_group) ⇒ Object


21
22
23
# File 'lib/rspec/core/formatters/documentation_formatter.rb', line 21

def example_group_finished(example_group)
  @group_level -= 1
end

#example_group_started(example_group) ⇒ Object


12
13
14
15
16
17
18
19
# File 'lib/rspec/core/formatters/documentation_formatter.rb', line 12

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) ⇒ Object


25
26
27
28
# File 'lib/rspec/core/formatters/documentation_formatter.rb', line 25

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

#example_pending(example) ⇒ Object


30
31
32
33
# File 'lib/rspec/core/formatters/documentation_formatter.rb', line 30

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

#failure_output(example, exception) ⇒ Object


40
41
42
# File 'lib/rspec/core/formatters/documentation_formatter.rb', line 40

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

#next_failure_indexObject


44
45
46
47
# File 'lib/rspec/core/formatters/documentation_formatter.rb', line 44

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

#passed_output(example) ⇒ Object


49
50
51
# File 'lib/rspec/core/formatters/documentation_formatter.rb', line 49

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

#pending_output(example, message) ⇒ Object


53
54
55
# File 'lib/rspec/core/formatters/documentation_formatter.rb', line 53

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