Class: RSpec::Core::Formatters::BaseTextFormatter

Inherits:
BaseFormatter
  • Object
show all
Defined in:
lib/rspec/core/formatters/base_text_formatter.rb

Overview

Base for all of RSpec's built-in formatters. See RSpec::Core::Formatters::BaseFormatter to learn more about all of the methods called by the reporter.

See Also:

Constant Summary

Instance Attribute Summary

Attributes inherited from BaseFormatter

#example_group, #examples, #failed_examples, #output, #pending_examples

Instance Method Summary (collapse)

Methods inherited from BaseFormatter

#example_failed, #example_group_finished, #example_group_started, #example_passed, #example_pending, #example_started, #format_backtrace, #initialize, #start, #start_dump, #stop

Methods included from Helpers

#format_duration, #format_seconds, #pluralize, #strip_trailing_zeroes

Constructor Details

This class inherits a constructor from RSpec::Core::Formatters::BaseFormatter

Instance Method Details

- (void) close(notification)

Invoked at the very end, close allows the formatter to clean up resources, e.g. open streams, etc.

Parameters:

  • notification (NullNotification)


142
143
144
# File 'lib/rspec/core/formatters/base_text_formatter.rb', line 142

def close(notification)
  output.close if IO === output && output != $stdout
end

- (void) dump_commands_to_rerun_failed_examples

Outputs commands which can be used to re-run failed examples.



64
65
66
67
68
69
70
71
72
73
# File 'lib/rspec/core/formatters/base_text_formatter.rb', line 64

def dump_commands_to_rerun_failed_examples
  return if failed_examples.empty?
  output.puts
  output.puts("Failed examples:")
  output.puts

  failed_examples.each do |example|
    output.puts(failure_color("rspec #{RSpec::Core::Metadata::relative_path(example.location)}") + " " + detail_color("# #{example.full_description}"))
  end
end

- (void) dump_failures

Dumps detailed information about each example failure.

Parameters:

  • notification (NullNotification)


33
34
35
36
37
38
39
40
41
42
# File 'lib/rspec/core/formatters/base_text_formatter.rb', line 33

def dump_failures(notification)
  return if failed_examples.empty?
  output.puts
  output.puts "Failures:"
  failed_examples.each_with_index do |example, index|
    output.puts
    pending_fixed?(example) ? dump_pending_fixed(example, index) : dump_failure(example, index)
    dump_backtrace(example)
  end
end

- (void) dump_profile

Outputs the slowest examples and example groups in a report when using --profile COUNT (default 10).



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

def dump_profile
  dump_profile_slowest_examples
  dump_profile_slowest_example_groups
end

- (void) dump_summary

This method is invoked after the dumping of examples and failures. Each parameter is assigned to a corresponding attribute.

Parameters:

  • summary (SummaryNotification)

    containing duration, example_count, failure_count and pending_count



52
53
54
55
56
57
58
# File 'lib/rspec/core/formatters/base_text_formatter.rb', line 52

def dump_summary(summary)
  dump_profile unless mute_profile_output?(summary.failure_count)
  output.puts "\nFinished in #{format_duration(summary.duration)}" +
              " (files took #{format_duration(summary.load_time)} to load)\n"
  output.puts summary.colorize_with ConsoleCodes
  dump_commands_to_rerun_failed_examples
end

- (void) message

Used by the reporter to send messages to the output stream.

Parameters:

  • notification (MessageNotification)

    containing message



23
24
25
# File 'lib/rspec/core/formatters/base_text_formatter.rb', line 23

def message(notification)
  output.puts notification.message
end