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
  @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

#add_example_group(example_group) ⇒ Object



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

def add_example_group(example_group)
  RSpec.deprecate("add_example_group", "example_group_started")
  example_group_started(example_group)
end

#closeObject

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



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

def close
  restore_sync_output
end

#dump_failuresObject

Dumps detailed information about each example failure.



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

def dump_failures
end

#dump_pendingObject

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



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

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.



84
85
86
87
88
89
# File 'lib/rspec/core/formatters/base_formatter.rb', line 84

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



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

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



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

def example_passed(example)
end

#example_pending(example) ⇒ Object



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

def example_pending(example)
  @pending_examples << example
end

#example_started(example) ⇒ Object



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

def example_started(example)
  examples << example
end

#format_backtrace(backtrace, example) ⇒ Object



100
101
102
103
104
105
# File 'lib/rspec/core/formatters/base_formatter.rb', line 100

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



68
69
# File 'lib/rspec/core/formatters/base_formatter.rb', line 68

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),



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

def start_dump
end

#stopObject



71
72
# File 'lib/rspec/core/formatters/base_formatter.rb', line 71

def stop
end