class 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
@return [String] the default formatter to setup, defaults to ‘progress`
@return [Array] the loaded formatters
@return [Reporter] the reporter
Public Class Methods
@api private
Internal formatters are stored here when loaded.
# File rspec-core/lib/rspec/core/formatters.rb, line 100 def self.formatters @formatters ||= {} end
@api private
# File rspec-core/lib/rspec/core/formatters.rb, line 105 def initialize(reporter) @formatters = [] @reporter = reporter self.default_formatter = 'progress' end
Public Instance Methods
@private
# File rspec-core/lib/rspec/core/formatters.rb, line 144 def add(formatter_to_use, *paths) # If a formatter instance was passed, we can register it directly, # with no need for any of the further processing that happens below. if Loader.formatters.key?(formatter_to_use.class) register formatter_to_use, notifications_for(formatter_to_use.class) return end formatter_class = find_formatter(formatter_to_use) args = paths.map { |p| p.respond_to?(:puts) ? p : open_stream(p) } if !Loader.formatters[formatter_class].nil? formatter = formatter_class.new(*args) register formatter, notifications_for(formatter_class) elsif defined?(RSpec::LegacyFormatters) formatter = RSpec::LegacyFormatters.load_formatter formatter_class, *args register formatter, formatter.notifications else call_site = "Formatter added at: #{::RSpec::CallerFilter.first_non_rspec_line}" RSpec.warn_deprecation <<-WARNING.gsub(/\s*\|/, ' ') |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} WARNING end end
@private
# File rspec-core/lib/rspec/core/formatters.rb, line 121 def prepare_default(output_stream, deprecation_stream) reporter.prepare_default(self, output_stream, deprecation_stream) end
@private
# File rspec-core/lib/rspec/core/formatters.rb, line 126 def setup_default(output_stream, deprecation_stream) add default_formatter, output_stream if @formatters.empty? unless @formatters.any? { |formatter| DeprecationFormatter === formatter } add DeprecationFormatter, deprecation_stream, output_stream end unless existing_formatter_implements?(:message) add FallbackMessageFormatter, output_stream end return unless RSpec.configuration.profile_examples? return if existing_formatter_implements?(:dump_profile) add RSpec::Core::Formatters::ProfileFormatter, output_stream end