Parent

Class/Module Index [+]

Quicksearch

RSpec::Core::Formatters::Loader

@api private

`RSpec::Core::Formatters::Loader` is an internal class for managing formatters used by a particular configuration. It is not expected to be used directly, but only through the configuration interface.

Attributes

default_formatter[RW]

@return [String] the default formatter to setup, defaults to `progress`

formatters[R]

@return [Array] the loaded formatters

reporter[R]

@return [Reporter] the reporter

Public Class Methods

formatters() click to toggle source

@api private

Internal formatters are stored here when loaded

# File lib/rspec/core/formatters.rb, line 91
def self.formatters
  @formatters ||= {}
end
new(reporter) click to toggle source

@api private

# File lib/rspec/core/formatters.rb, line 96
def initialize(reporter)
  @formatters = []
  @reporter = reporter
  self.default_formatter = 'progress'
end

Public Instance Methods

add(formatter_to_use, *paths) click to toggle source

@private

# File lib/rspec/core/formatters.rb, line 125
def add(formatter_to_use, *paths)
  formatter_class = find_formatter(formatter_to_use)

  args = paths.map { |p| p.respond_to?(:puts) ? p : file_at(p) }

  if !Loader.formatters[formatter_class].nil?
    formatter = formatter_class.new(*args)
    @reporter.register_listener formatter, *notifications_for(formatter_class)
  elsif defined?(RSpec::LegacyFormatters)
    formatter = RSpec::LegacyFormatters.load_formatter formatter_class, *args
    @reporter.register_listener formatter, *formatter.notifications
  else
    line = ::RSpec::CallerFilter.first_non_rspec_line
    if line
      call_site = "Formatter added at: #{line}"
    else
      call_site = "The formatter was added via command line flag or your "+
                  "`.rspec` file."
    end

    RSpec.warn_deprecation           |The #{formatter_class} formatter uses the deprecated formatter          |interface not supported directly by RSpec 3.          |          |To continue to use this formatter you must install the          |`rspec-legacy_formatters` gem, which provides support          |for legacy formatters or upgrade the formatter to a          |compatible version.          |          |#{call_site}.gsub(/\s*\|/,' ')
    return
  end
  @formatters << formatter unless duplicate_formatter_exists?(formatter)
  formatter
end
setup_default(output_stream, deprecation_stream) click to toggle source

@private

# File lib/rspec/core/formatters.rb, line 112
def setup_default(output_stream, deprecation_stream)
  if @formatters.empty?
    add default_formatter, output_stream
  end
  unless @formatters.any? { |formatter| DeprecationFormatter === formatter }
    add DeprecationFormatter, deprecation_stream, output_stream
  end
  if RSpec.configuration.profile_examples? && !existing_formatter_implements?(:dump_profile)
    add RSpec::Core::Formatters::ProfileFormatter, output_stream
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.