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

Inherits:
BaseTextFormatter show all
Defined in:
lib/gems/rspec-1.1.11/lib/spec/runner/formatter/nested_text_formatter.rb

Instance Attribute Summary collapse

Attributes inherited from BaseTextFormatter

#output, #pending_examples

Attributes inherited from BaseFormatter

#example_group, #options, #where

Instance Method Summary collapse

Methods inherited from BaseTextFormatter

#close, #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.



8
9
10
11
# File 'lib/gems/rspec-1.1.11/lib/spec/runner/formatter/nested_text_formatter.rb', line 8

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

Instance Attribute Details

#previous_nested_example_groupsObject (readonly)

Returns the value of attribute previous_nested_example_groups.



7
8
9
# File 'lib/gems/rspec-1.1.11/lib/spec/runner/formatter/nested_text_formatter.rb', line 7

def previous_nested_example_groups
  @previous_nested_example_groups
end

Instance Method Details

#add_example_group(example_group) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gems/rspec-1.1.11/lib/spec/runner/formatter/nested_text_formatter.rb', line 13

def add_example_group(example_group)
  super

  current_nested_example_groups = described_example_group_chain
  current_nested_example_groups.each_with_index do |nested_example_group, i|
    unless nested_example_group == previous_nested_example_groups[i]
      output.puts "#{'  ' * i}#{nested_example_group.description_args}"
    end
  end

  @previous_nested_example_groups = described_example_group_chain
end

#current_indentationObject



49
50
51
# File 'lib/gems/rspec-1.1.11/lib/spec/runner/formatter/nested_text_formatter.rb', line 49

def current_indentation
  '  ' * previous_nested_example_groups.length
end

#described_example_group_chainObject



53
54
55
56
57
58
59
60
61
# File 'lib/gems/rspec-1.1.11/lib/spec/runner/formatter/nested_text_formatter.rb', line 53

def described_example_group_chain
  example_group_chain = []
  example_group.__send__(:each_ancestor_example_group_class) do |example_group_class|
    unless example_group_class.description_args.empty?
      example_group_chain << example_group_class
    end
  end
  example_group_chain
end

#example_failed(example, counter, failure) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/gems/rspec-1.1.11/lib/spec/runner/formatter/nested_text_formatter.rb', line 26

def example_failed(example, counter, failure)
  message = if failure.expectation_not_met?
    "#{current_indentation}#{example.description} (FAILED - #{counter})"
  else
    "#{current_indentation}#{example.description} (ERROR - #{counter})"
  end

  output.puts(failure.expectation_not_met? ? red(message) : magenta(message))
  output.flush
end

#example_passed(example) ⇒ Object



37
38
39
40
41
# File 'lib/gems/rspec-1.1.11/lib/spec/runner/formatter/nested_text_formatter.rb', line 37

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

#example_pending(example, message, pending_caller) ⇒ Object



43
44
45
46
47
# File 'lib/gems/rspec-1.1.11/lib/spec/runner/formatter/nested_text_formatter.rb', line 43

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