Class: Micronaut::Formatters::DocumentationFormatter

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

Instance Attribute Summary collapse

Attributes inherited from BaseFormatter

#behaviour, #duration, #example_count, #total_example_failed, #total_example_pending

Instance Method Summary collapse

Methods inherited from BaseTextFormatter

#close, #colorise, #dump_failures, #dump_pending, #dump_summary, #example_started

Methods inherited from BaseFormatter

#close, #color_enabled?, #configuration, #dump_failures, #dump_pending, #dump_summary, #example_profiling_info, #example_started, #failed_examples, #format_backtrace, #output, #pending_examples, #profile_examples?, #start, #start_dump, #trace, #trace_override_flag

Constructor Details

#initializeDocumentationFormatter

Returns a new instance of DocumentationFormatter.



8
9
10
11
# File 'lib/micronaut/formatters/documentation_formatter.rb', line 8

def initialize
  super
  @previous_nested_behaviours = []
end

Instance Attribute Details

#previous_nested_behavioursObject (readonly)

Returns the value of attribute previous_nested_behaviours.



6
7
8
# File 'lib/micronaut/formatters/documentation_formatter.rb', line 6

def previous_nested_behaviours
  @previous_nested_behaviours
end

Instance Method Details

#add_behaviour(behaviour) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/micronaut/formatters/documentation_formatter.rb', line 13

def add_behaviour(behaviour)
  super

  described_behaviour_chain.each_with_index do |nested_behaviour, i|
    unless nested_behaviour == previous_nested_behaviours[i]
      at_root_level = (i == 0)
      desc_or_name = at_root_level ? nested_behaviour.name : nested_behaviour.description
      output.puts if at_root_level
      output.puts "#{'  ' * i}#{desc_or_name}"
    end
  end
  
  @previous_nested_behaviours = described_behaviour_chain
end

#current_indentationObject



54
55
56
# File 'lib/micronaut/formatters/documentation_formatter.rb', line 54

def current_indentation
  '  ' * previous_nested_behaviours.length
end

#described_behaviour_chainObject



58
59
60
# File 'lib/micronaut/formatters/documentation_formatter.rb', line 58

def described_behaviour_chain
  behaviour.ancestors
end

#example_failed(example, exception) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/micronaut/formatters/documentation_formatter.rb', line 28

def example_failed(example, exception)
  super
  expectation_not_met = exception.is_a?(Micronaut::Expectations::ExpectationNotMetError)
  
  message = if expectation_not_met
    "#{current_indentation}#{example.description} (FAILED)"
  else
    "#{current_indentation}#{example.description} (ERROR)"
  end

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

#example_passed(example) ⇒ Object



42
43
44
45
46
# File 'lib/micronaut/formatters/documentation_formatter.rb', line 42

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

#example_pending(example, message) ⇒ Object



48
49
50
51
52
# File 'lib/micronaut/formatters/documentation_formatter.rb', line 48

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