# File lib/rspec/core/formatters/base_formatter.rb, line 15 def initialize(output) @output = output || StringIO.new @example_count = @pending_count = @failure_count = 0 @examples = [] @failed_examples = [] @pending_examples = [] @example_group = nil end
This method is invoked at the very end. Allows the formatter to clean up, like closing open streams.
# File lib/rspec/core/formatters/base_formatter.rb, line 95 def close restore_sync_output end
Dumps detailed information about each example failure.
# File lib/rspec/core/formatters/base_formatter.rb, line 76 def dump_failures end
This gets invoked after the summary if option is set to do so.
# File lib/rspec/core/formatters/base_formatter.rb, line 88 def dump_pending end
This method is invoked after the dumping of examples and failures.
# File lib/rspec/core/formatters/base_formatter.rb, line 80 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
# File lib/rspec/core/formatters/base_formatter.rb, line 60 def example_failed(example) @failed_examples << example end
This method is invoked at the end of the execution of each example group.
example_group
is the example_group.
# File lib/rspec/core/formatters/base_formatter.rb, line 46 def example_group_finished(example_group) end
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
# File lib/rspec/core/formatters/base_formatter.rb, line 40 def example_group_started(example_group) @example_group = example_group end
# File lib/rspec/core/formatters/base_formatter.rb, line 53 def example_passed(example) end
# File lib/rspec/core/formatters/base_formatter.rb, line 56 def example_pending(example) @pending_examples << example end
# File lib/rspec/core/formatters/base_formatter.rb, line 49 def example_started(example) examples << example end
# File lib/rspec/core/formatters/base_formatter.rb, line 99 def format_backtrace(backtrace, example) return "" unless backtrace return backtrace if example.metadata[: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
# File lib/rspec/core/formatters/base_formatter.rb, line 64 def message(message) end
# File lib/rspec/core/formatters/base_formatter.rb, line 91 def seed(number) end
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
# File lib/rspec/core/formatters/base_formatter.rb, line 30 def start(example_count) start_sync_output @example_count = example_count end
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),
# File lib/rspec/core/formatters/base_formatter.rb, line 72 def start_dump end
# File lib/rspec/core/formatters/base_formatter.rb, line 67 def stop end
# File lib/rspec/core/formatters/base_formatter.rb, line 117 def backtrace_line(line) return nil if configuration.cleaned_from_backtrace?(line) RSpec::Core::Metadata::relative_path(line) end
# File lib/rspec/core/formatters/base_formatter.rb, line 160 def color_enabled? configuration.color_enabled? end
# File lib/rspec/core/formatters/base_formatter.rb, line 113 def configuration RSpec.configuration end
# File lib/rspec/core/formatters/base_formatter.rb, line 136 def find_failed_line(backtrace, path) path = File.expand_path(path) backtrace.detect { |line| match = line.match(%r(.+?):(\d+)(|:\d+)/) match && match[1].downcase == path.downcase } end
# File lib/rspec/core/formatters/base_formatter.rb, line 152 def output_supports_sync output.respond_to?(:sync=) end
# File lib/rspec/core/formatters/base_formatter.rb, line 156 def profile_examples? configuration.profile_examples end
# File lib/rspec/core/formatters/base_formatter.rb, line 122 def read_failed_line(exception, example) unless matching_line = find_failed_line(exception.backtrace, example.file_path) return "Unable to find matching line from backtrace" end file_path, line_number = matching_line.match(%r(.+?):(\d+)(|:\d+)/)[1..2] if File.exist?(file_path) File.readlines(file_path)[line_number.to_i - 1] else "Unable to find #{file_path} to read failed line" end end
# File lib/rspec/core/formatters/base_formatter.rb, line 148 def restore_sync_output output.sync = @old_sync if output_supports_sync and !output.closed? end
# File lib/rspec/core/formatters/base_formatter.rb, line 144 def start_sync_output @old_sync, output.sync = output.sync, true if output_supports_sync end