Class: RSpec::Core::Formatters::DeprecationFormatter

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

Defined Under Namespace

Classes: DelayedPrinter, FileStream, GeneratedDeprecationMessage, ImmediatePrinter, RaiseErrorStream, SpecifiedDeprecationMessage

Constant Summary collapse

RAISE_ERROR_CONFIG_NOTICE =
<<-EOS.gsub(/^\s+\|/, '')
  |
  |If you need more of the backtrace for any of these deprecations to
  |identify where to make the necessary changes, you can configure
  |`config.raise_errors_for_deprecations!`, and it will turn the
  |deprecation warnings into errors, giving you the full backtrace.
EOS
DEPRECATION_STREAM_NOTICE =
"Pass `--deprecation-out` or set " \
"`config.deprecation_stream` to a file for full output."
TOO_MANY_WARNINGS_NOTICE =
"Too many similar deprecation messages " \
"reported, disregarding further reports. #{DEPRECATION_STREAM_NOTICE}"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(deprecation_stream, summary_stream) ⇒ DeprecationFormatter

Returns a new instance of DeprecationFormatter



12
13
14
15
16
17
# File 'lib/rspec/core/formatters/deprecation_formatter.rb', line 12

def initialize(deprecation_stream, summary_stream)
  @deprecation_stream = deprecation_stream
  @summary_stream = summary_stream
  @seen_deprecations = Set.new
  @count = 0
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count



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

def count
  @count
end

#deprecation_streamObject (readonly) Also known as: output

Returns the value of attribute deprecation_stream



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

def deprecation_stream
  @deprecation_stream
end

#summary_streamObject (readonly)

Returns the value of attribute summary_stream



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

def summary_stream
  @summary_stream
end

Instance Method Details

#deprecation(notification) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/rspec/core/formatters/deprecation_formatter.rb', line 32

def deprecation(notification)
  return if @seen_deprecations.include? notification

  @count += 1
  printer.print_deprecation_message notification
  @seen_deprecations << notification
end

#deprecation_message_for(data) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/rspec/core/formatters/deprecation_formatter.rb', line 44

def deprecation_message_for(data)
  if data.message
    SpecifiedDeprecationMessage.new(data)
  else
    GeneratedDeprecationMessage.new(data)
  end
end

#deprecation_summary(_notification) ⇒ Object



40
41
42
# File 'lib/rspec/core/formatters/deprecation_formatter.rb', line 40

def deprecation_summary(_notification)
  printer.deprecation_summary
end

#printerObject



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

def printer
  @printer ||= case deprecation_stream
               when File
                 ImmediatePrinter.new(FileStream.new(deprecation_stream),
                                      summary_stream, self)
               when RaiseErrorStream
                 ImmediatePrinter.new(deprecation_stream, summary_stream, self)
               else
                 DelayedPrinter.new(deprecation_stream, summary_stream, self)
               end
end