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

Class Method 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.



22
23
24
25
26
27
28
29
# File 'lib/rspec/core/formatters/base_formatter.rb', line 22

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.



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

def duration
  @duration
end

#example_countObject (readonly)

Returns the value of attribute example_count.



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

def example_count
  @example_count
end

#example_groupObject

Returns the value of attribute example_group.



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

def example_group
  @example_group
end

#examplesObject (readonly)

Returns the value of attribute examples.



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

def examples
  @examples
end

#failed_examplesObject (readonly)

Returns the value of attribute failed_examples.



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

def failed_examples
  @failed_examples
end

#failure_countObject (readonly)

Returns the value of attribute failure_count.



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

def failure_count
  @failure_count
end

#outputObject (readonly)

Returns the value of attribute output.



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

def output
  @output
end

#pending_countObject (readonly)

Returns the value of attribute pending_count.



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

def pending_count
  @pending_count
end

#pending_examplesObject (readonly)

Returns the value of attribute pending_examples.



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

def pending_examples
  @pending_examples
end

Class Method Details

.relative_path(line) ⇒ Object



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

def self.relative_path(line)
  line = line.sub(File.expand_path("."), ".")
  line = line.sub(/\A([^:]+:\d+)$/, '\\1')
  return nil if line == '-e:1'
  line
end

Instance Method Details

#closeObject

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



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

def close
  restore_sync_output
end

#dump_failuresObject

Dumps detailed information about each example failure.



83
84
# File 'lib/rspec/core/formatters/base_formatter.rb', line 83

def dump_failures
end

#dump_pendingObject

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



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

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.



87
88
89
90
91
92
# File 'lib/rspec/core/formatters/base_formatter.rb', line 87

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



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

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.



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

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



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

def example_group_started(example_group)
  @example_group = example_group
end

#example_passed(example) ⇒ Object



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

def example_passed(example)
end

#example_pending(example) ⇒ Object



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

def example_pending(example)
  @pending_examples << example
end

#example_started(example) ⇒ Object



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

def example_started(example)
  examples << example
end

#format_backtrace(backtrace, example) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/rspec/core/formatters/base_formatter.rb', line 106

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

  if at_exit_index = backtrace.index(RSpec::Core::Runner::AT_EXIT_HOOK_BACKTRACE_LINE)
    backtrace = backtrace[0, at_exit_index]
  end

  cleansed = backtrace.map { |line| backtrace_line(line) }.compact
  cleansed.empty? ? backtrace : cleansed
end

#message(message) ⇒ Object



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

def message(message)
end

#seed(number) ⇒ Object



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

def seed(number)
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



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

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



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

def start_dump
end

#stopObject



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

def stop
end