Class: RSpec::Core::Formatters::BaseFormatter

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/rspec/core/formatters/base_formatter.rb

Direct Known Subclasses

BaseTextFormatter

Constant Summary

Constants included from Helpers

Helpers::DEFAULT_PRECISION, Helpers::SUB_SECOND_PRECISION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#format_seconds, #strip_trailing_zeroes

Constructor Details

#initialize(output) ⇒ BaseFormatter

Returns a new instance of BaseFormatter.



14
15
16
17
18
19
20
21
# File 'lib/rspec/core/formatters/base_formatter.rb', line 14

def initialize(output)
  @output = output || StringIO.new
  @example_count = @pending_count = @failure_count = 0
  @examples = []
  @failed_examples = []
  @pending_examples = []
  @example_group = nil
end

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.



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

def duration
  @duration
end

#example_countObject (readonly)

Returns the value of attribute example_count.



11
12
13
# File 'lib/rspec/core/formatters/base_formatter.rb', line 11

def example_count
  @example_count
end

#example_groupObject

Returns the value of attribute example_group.



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

def example_group
  @example_group
end

#examplesObject (readonly)

Returns the value of attribute examples.



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

def examples
  @examples
end

#failed_examplesObject (readonly)

Returns the value of attribute failed_examples.



12
13
14
# File 'lib/rspec/core/formatters/base_formatter.rb', line 12

def failed_examples
  @failed_examples
end

#failure_countObject (readonly)

Returns the value of attribute failure_count.



11
12
13
# File 'lib/rspec/core/formatters/base_formatter.rb', line 11

def failure_count
  @failure_count
end

#outputObject (readonly)

Returns the value of attribute output.



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

def output
  @output
end

#pending_countObject (readonly)

Returns the value of attribute pending_count.



11
12
13
# File 'lib/rspec/core/formatters/base_formatter.rb', line 11

def pending_count
  @pending_count
end

#pending_examplesObject (readonly)

Returns the value of attribute pending_examples.



12
13
14
# File 'lib/rspec/core/formatters/base_formatter.rb', line 12

def pending_examples
  @pending_examples
end

Instance Method Details

#closeObject

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



91
92
93
# File 'lib/rspec/core/formatters/base_formatter.rb', line 91

def close
  restore_sync_output
end

#dump_failuresObject

Dumps detailed information about each example failure.



75
76
# File 'lib/rspec/core/formatters/base_formatter.rb', line 75

def dump_failures
end

#dump_pendingObject

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



87
88
# File 'lib/rspec/core/formatters/base_formatter.rb', line 87

def dump_pending
end

#dump_summary(duration, example_count, failure_count, pending_count) ⇒ Object

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



79
80
81
82
83
84
# File 'lib/rspec/core/formatters/base_formatter.rb', line 79

def dump_summary(duration, example_count, failure_count, pending_count)
  @duration = duration
  @example_count = example_count
  @failure_count = failure_count
  @pending_count = pending_count
end

#example_failed(example) ⇒ Object



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

def example_failed(example)
  @failed_examples << example
end

#example_group_finished(example_group) ⇒ Object

This method is invoked at the end of the execution of each example group. example_group is the example_group.



45
46
# File 'lib/rspec/core/formatters/base_formatter.rb', line 45

def example_group_finished(example_group)
end

#example_group_started(example_group) ⇒ Object

This method is invoked at the beginning of the execution of each example group. example_group is the example_group.

The next method to be invoked after this is example_passed, example_pending, or example_finished



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

def example_group_started(example_group)
  @example_group = example_group
end

#example_passed(example) ⇒ Object



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

def example_passed(example)
end

#example_pending(example) ⇒ Object



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

def example_pending(example)
  @pending_examples << example
end

#example_started(example) ⇒ Object



48
49
50
# File 'lib/rspec/core/formatters/base_formatter.rb', line 48

def example_started(example)
  examples << example
end

#format_backtrace(backtrace, example) ⇒ Object



95
96
97
98
99
100
# File 'lib/rspec/core/formatters/base_formatter.rb', line 95

def format_backtrace(backtrace, example)
  return "" unless backtrace
  return backtrace if example.[:full_backtrace] == true
  cleansed = backtrace.map { |line| backtrace_line(line) }.compact
  cleansed.empty? ? backtrace : cleansed
end

#message(message) ⇒ Object



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

def message(message)
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 will only be invoked once, and the next one to be invoked is #example_group_started



29
30
31
32
# File 'lib/rspec/core/formatters/base_formatter.rb', line 29

def start(example_count)
  start_sync_output
  @example_count = example_count
end

#start_dumpObject

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
# File 'lib/rspec/core/formatters/base_formatter.rb', line 71

def start_dump
end

#stopObject



66
67
# File 'lib/rspec/core/formatters/base_formatter.rb', line 66

def stop
end