Class: Spec::Runner::Formatter::NestedTextFormatter

Inherits:
BaseTextFormatter show all
Defined in:
lib/spec/runner/formatter/nested_text_formatter.rb

Instance Attribute Summary

Attributes inherited from BaseTextFormatter

#output, #pending_examples

Attributes inherited from BaseFormatter

#example_group, #options, #where

Instance Method Summary collapse

Methods inherited from BaseTextFormatter

#close, #colorize_failure, #colourise, #dump_failure, #dump_pending, #dump_summary, #format_backtrace

Methods inherited from BaseFormatter

#close, #dump_failure, #dump_pending, #dump_summary, #example_started, #start, #start_dump

Constructor Details

#initialize(options, where) ⇒ NestedTextFormatter

Returns a new instance of NestedTextFormatter.



7
8
9
10
# File 'lib/spec/runner/formatter/nested_text_formatter.rb', line 7

def initialize(options, where)
  super
  @last_nested_descriptions = []
end

Instance Method Details

#add_example_group(example_group) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/spec/runner/formatter/nested_text_formatter.rb', line 12

def add_example_group(example_group)
  super

  example_group.nested_descriptions.each_with_index do |nested_description, i|
    unless nested_description == @last_nested_descriptions[i]
      output.puts "#{'  ' * i}#{nested_description}"
    end
  end

  @last_nested_descriptions = example_group.nested_descriptions
end

#current_indentationObject



41
42
43
# File 'lib/spec/runner/formatter/nested_text_formatter.rb', line 41

def current_indentation
  '  ' * @last_nested_descriptions.length
end

#example_failed(example, counter, failure) ⇒ Object



24
25
26
27
# File 'lib/spec/runner/formatter/nested_text_formatter.rb', line 24

def example_failed(example, counter, failure)
  output.puts(red("#{current_indentation}#{example.description} (FAILED - #{counter})"))
  output.flush
end

#example_passed(example) ⇒ Object



29
30
31
32
33
# File 'lib/spec/runner/formatter/nested_text_formatter.rb', line 29

def example_passed(example)
  message = "#{current_indentation}#{example.description}"
  output.puts green(message)
  output.flush
end

#example_pending(example, message, pending_caller) ⇒ Object



35
36
37
38
39
# File 'lib/spec/runner/formatter/nested_text_formatter.rb', line 35

def example_pending(example, message, pending_caller)
  super
  output.puts yellow("#{current_indentation}#{example.description} (PENDING: #{message})")
  output.flush
end