Class: RSpec::ActiveSupport::Matchers::DeprecationMatcher
- Inherits:
-
Object
- Object
- RSpec::ActiveSupport::Matchers::DeprecationMatcher
- Includes:
- ActiveSupport::Testing::Deprecation, Matchers::Composable
- Defined in:
- lib/rspec/active_support/matchers/warn_deprecation.rb
Instance Attribute Summary collapse
-
#deprecations ⇒ Object
readonly
Returns the value of attribute deprecations.
-
#deprecator ⇒ Object
readonly
Returns the value of attribute deprecator.
-
#expected ⇒ Object
readonly
Returns the value of attribute expected.
Instance Method Summary collapse
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(expected, deprecator) ⇒ DeprecationMatcher
constructor
A new instance of DeprecationMatcher.
- #matches?(actual) ⇒ Boolean
- #supports_block_expectations? ⇒ Boolean private
- #supports_value_expectations? ⇒ Boolean
Constructor Details
#initialize(expected, deprecator) ⇒ DeprecationMatcher
Returns a new instance of DeprecationMatcher.
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.is_a?(Class) @expected = expected @deprecator = deprecator || RSpec.configuration.deprecator end |
Instance Attribute Details
#deprecations ⇒ Object (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 |
#deprecator ⇒ Object (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 |
#expected ⇒ Object (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_message ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/rspec/active_support/matchers/warn_deprecation.rb', line 32 def 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_negated ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/rspec/active_support/matchers/warn_deprecation.rb', line 40 def return if deprecations.nil? || deprecations.empty? = deprecations.map { |msg| " #{msg}" } .unshift("expected no deprecation warning within the block but received #{deprecations.size}:") .join("\n") end |
#matches?(actual) ⇒ Boolean
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.is_a?(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.
53 54 55 |
# File 'lib/rspec/active_support/matchers/warn_deprecation.rb', line 53 def supports_block_expectations? true end |
#supports_value_expectations? ⇒ Boolean
48 49 50 |
# File 'lib/rspec/active_support/matchers/warn_deprecation.rb', line 48 def supports_value_expectations? false end |