Class: Micronaut::Formatters::BaseFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/micronaut/formatters/base_formatter.rb

Direct Known Subclasses

BaseTextFormatter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBaseFormatter

Returns a new instance of BaseFormatter.



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

def initialize
  @example_count = 0
  @examples = []
  @behaviour = nil
end

Instance Attribute Details

#behaviourObject

Returns the value of attribute behaviour.



5
6
7
# File 'lib/micronaut/formatters/base_formatter.rb', line 5

def behaviour
  @behaviour
end

#durationObject (readonly)

Returns the value of attribute duration.



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

def duration
  @duration
end

#example_countObject (readonly)

Returns the value of attribute example_count.



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

def example_count
  @example_count
end

#examplesObject (readonly)

Returns the value of attribute examples.



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

def examples
  @examples
end

Instance Method Details

#add_behaviour(behaviour) ⇒ Object

This method is invoked at the beginning of the execution of each behaviour. behaviour is the behaviour.

The next method to be invoked after this is #example_failed or #example_finished



65
66
67
# File 'lib/micronaut/formatters/base_formatter.rb', line 65

def add_behaviour(behaviour)
  @behaviour = behaviour
end

#closeObject

This method is invoked at the very end. Allows the formatter to clean up, like closing open streams.



88
89
# File 'lib/micronaut/formatters/base_formatter.rb', line 88

def close
end

#color_enabled?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/micronaut/formatters/base_formatter.rb', line 35

def color_enabled?
  configuration.color_enabled?
end

#configurationObject



14
15
16
# File 'lib/micronaut/formatters/base_formatter.rb', line 14

def configuration
  Micronaut.configuration
end

#dump_failuresObject

Dumps detailed information about each example failure.



76
77
# File 'lib/micronaut/formatters/base_formatter.rb', line 76

def dump_failures
end

#dump_pendingObject

This gets invoked after the summary if option is set to do so.



84
85
# File 'lib/micronaut/formatters/base_formatter.rb', line 84

def dump_pending
end

#dump_summaryObject

This method is invoked after the dumping of examples and failures.



80
81
# File 'lib/micronaut/formatters/base_formatter.rb', line 80

def dump_summary
end

#example_finished(example) ⇒ Object



57
58
59
# File 'lib/micronaut/formatters/base_formatter.rb', line 57

def example_finished(example)
  examples << example
end

#failed_examplesObject



43
44
45
# File 'lib/micronaut/formatters/base_formatter.rb', line 43

def failed_examples
  @failed_examples ||= ::Micronaut.world.find(examples, :execution_result => { :status => 'failed' })
end

#format_backtrace(backtrace, example) ⇒ Object



91
92
93
94
95
96
97
98
99
# File 'lib/micronaut/formatters/base_formatter.rb', line 91

def format_backtrace(backtrace, example)
  return "" unless backtrace
  return backtrace if example.[:full_backtrace] == true

  cleansed = backtrace.select { |line| backtrace_line(line) }
  # Kick the describe stack info off the list, just keep the line the problem happened on from that file
  # cleansed = [cleansed.detect { |line| line.split(':').first == example.metadata[:caller].split(':').first }] if cleansed.size > 1 
  cleansed.empty? ? backtrace : cleansed
end

#outputObject



18
19
20
# File 'lib/micronaut/formatters/base_formatter.rb', line 18

def output
  Micronaut.configuration.output
end

#pending_examplesObject



39
40
41
# File 'lib/micronaut/formatters/base_formatter.rb', line 39

def pending_examples
  @pending_examples ||= ::Micronaut.world.find(examples, :execution_result => { :status => 'pending' })
end

#profile_examples?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/micronaut/formatters/base_formatter.rb', line 31

def profile_examples?
  Micronaut.configuration.profile_examples
end

#start(example_count) ⇒ Object

This method is invoked before any examples are run, right after they have all been collected. This can be useful for special formatters that need to provide progress on feedback (graphical ones)

This method will only be invoked once, and the next one to be invoked is #add_behaviour



53
54
55
# File 'lib/micronaut/formatters/base_formatter.rb', line 53

def start(example_count)
  @example_count = example_count
end

#start_dump(duration) ⇒ Object

This method is invoked after all of the examples have executed. The next method to be invoked after this one is #dump_failure (once for each failed example),



71
72
73
# File 'lib/micronaut/formatters/base_formatter.rb', line 71

def start_dump(duration)
  @duration = duration
end

#trace(&blk) ⇒ Object



22
23
24
# File 'lib/micronaut/formatters/base_formatter.rb', line 22

def trace(&blk)
  Micronaut.configuration.trace(trace_override_flag, &blk)
end

#trace_override_flagObject

Allow setting trace at the behaviour level as well globally



27
28
29
# File 'lib/micronaut/formatters/base_formatter.rb', line 27

def trace_override_flag
  behaviour && behaviour.[:trace]
end