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

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/deprecation_formatter.rb

Constant Summary collapse

TOO_MANY_USES_LIMIT =
4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(deprecation_stream, summary_stream, deprecation_formatter) ⇒ DelayedPrinter

Returns a new instance of DelayedPrinter.



140
141
142
143
144
145
146
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/deprecation_formatter.rb', line 140

def initialize(deprecation_stream, summary_stream, deprecation_formatter)
  @deprecation_stream = deprecation_stream
  @summary_stream = summary_stream
  @deprecation_formatter = deprecation_formatter
  @seen_deprecations = Hash.new { 0 }
  @deprecation_messages = Hash.new { |h, k| h[k] = [] }
end

Instance Attribute Details

#deprecation_formatterObject (readonly)

Returns the value of attribute deprecation_formatter.



138
139
140
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/deprecation_formatter.rb', line 138

def deprecation_formatter
  @deprecation_formatter
end

#deprecation_streamObject (readonly)

Returns the value of attribute deprecation_stream.



138
139
140
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/deprecation_formatter.rb', line 138

def deprecation_stream
  @deprecation_stream
end

#summary_streamObject (readonly)

Returns the value of attribute summary_stream.



138
139
140
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/deprecation_formatter.rb', line 138

def summary_stream
  @summary_stream
end

Instance Method Details

#deprecation_summaryObject



163
164
165
166
167
168
169
170
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/deprecation_formatter.rb', line 163

def deprecation_summary
  return unless @deprecation_messages.any?

  print_deferred_deprecation_warnings
  deprecation_stream.puts RAISE_ERROR_CONFIG_NOTICE

  summary_stream.puts "\n#{Helpers.pluralize(deprecation_formatter.count, 'deprecation warning')} total"
end


172
173
174
175
176
177
178
179
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/deprecation_formatter.rb', line 172

def print_deferred_deprecation_warnings
  deprecation_stream.puts "\nDeprecation Warnings:\n\n"
  @deprecation_messages.keys.sort_by(&:type).each do |deprecation|
    messages = @deprecation_messages[deprecation]
    messages.each { |msg| deprecation_stream.puts msg }
    deprecation_stream.puts
  end
end


148
149
150
151
152
153
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/deprecation_formatter.rb', line 148

def print_deprecation_message(data)
  deprecation_message = deprecation_formatter.deprecation_message_for(data)
  @seen_deprecations[deprecation_message] += 1

  stash_deprecation_message(deprecation_message)
end

#stash_deprecation_message(deprecation_message) ⇒ Object



155
156
157
158
159
160
161
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/deprecation_formatter.rb', line 155

def stash_deprecation_message(deprecation_message)
  if @seen_deprecations[deprecation_message] < TOO_MANY_USES_LIMIT
    @deprecation_messages[deprecation_message] << deprecation_message.to_s
  elsif @seen_deprecations[deprecation_message] == TOO_MANY_USES_LIMIT
    @deprecation_messages[deprecation_message] << deprecation_message.too_many_warnings_message
  end
end