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

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

Constant Summary

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, #colorise_summary, #dump_commands_to_rerun_failed_examples, #dump_failures, #dump_pending, #dump_profile, #dump_summary, #message, #summary_line

Methods inherited from BaseFormatter

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

Methods included from Helpers

#format_seconds, #strip_trailing_zeroes

Constructor Details

#initialize(output) ⇒ DocumentationFormatter

Returns a new instance of DocumentationFormatter.



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

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

Instance Method Details

#current_indentationObject



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

def current_indentation
  '  ' * @group_level
end

#example_failed(example) ⇒ Object



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

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

#example_group_chainObject



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

def example_group_chain
  example_group.ancestors.reverse
end

#example_group_finished(example_group) ⇒ Object



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

def example_group_finished(example_group)
  @group_level -= 1
end

#example_group_started(example_group) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/rspec/core/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}"

  @group_level += 1
end

#example_passed(example) ⇒ Object



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

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

#example_pending(example) ⇒ Object



32
33
34
35
# File 'lib/rspec/core/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) ⇒ Object



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

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

#next_failure_indexObject



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

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

#passed_output(example) ⇒ Object



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

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

#pending_output(example, message) ⇒ Object



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

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