Class: RSpec::ActiveSupport::Matchers::DeprecationMatcher

Inherits:
Object
  • Object
show all
Includes:
ActiveSupport::Testing::Deprecation, Matchers::Composable
Defined in:
lib/rspec/active_support/matchers/warn_deprecation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected, deprecator) ⇒ DeprecationMatcher

Returns a new instance of DeprecationMatcher.

Raises:

  • (ArgumentError)


15
16
17
18
19
20
# File 'lib/rspec/active_support/matchers/warn_deprecation.rb', line 15

def initialize(expected, deprecator)
  raise ArgumentError, "deprecator must be an instance, got: #{deprecator.inspect}" if deprecator in Class

  @expected = expected
  @deprecator = deprecator || RSpec.configuration.deprecator
end

Instance Attribute Details

#deprecationsObject (readonly)

Returns the value of attribute deprecations.



13
14
15
# File 'lib/rspec/active_support/matchers/warn_deprecation.rb', line 13

def deprecations
  @deprecations
end

#deprecatorObject (readonly)

Returns the value of attribute deprecator.



13
14
15
# File 'lib/rspec/active_support/matchers/warn_deprecation.rb', line 13

def deprecator
  @deprecator
end

#expectedObject (readonly)

Returns the value of attribute expected.



13
14
15
# File 'lib/rspec/active_support/matchers/warn_deprecation.rb', line 13

def expected
  @expected
end

Instance Method Details

#failure_messageObject



32
33
34
35
36
37
38
# File 'lib/rspec/active_support/matchers/warn_deprecation.rb', line 32

def failure_message
  if deprecations.nil? || deprecations.empty?
    "expected a deprecation warning within the block but received none"
  elsif expected
    "no deprecation warning matched #{expected.inspect}: #{deprecations.join(", ")}"
  end
end

#failure_message_when_negatedObject



40
41
42
43
44
45
46
# File 'lib/rspec/active_support/matchers/warn_deprecation.rb', line 40

def failure_message_when_negated
  return if deprecations.nil? || deprecations.empty?

  message = deprecations.map { |msg| "  #{msg}" }
  message.unshift("expected no deprecation warning within the block but received #{deprecations.size}:")
  message.join("\n")
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


22
23
24
25
26
27
28
29
30
# File 'lib/rspec/active_support/matchers/warn_deprecation.rb', line 22

def matches?(actual)
  raise ArgumentError, "warn_deprecation only work with block arguments" unless actual in Proc

  _, @deprecations = collect_deprecations(deprecator, &actual)
  return false if deprecations.empty?
  return false if expected && deprecations.none? { |msg| values_match?(expected, msg) }

  true
end

#supports_block_expectations?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


53
54
55
# File 'lib/rspec/active_support/matchers/warn_deprecation.rb', line 53

def supports_block_expectations?
  true
end

#supports_value_expectations?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/rspec/active_support/matchers/warn_deprecation.rb', line 48

def supports_value_expectations?
  false
end