Class: RSpec::Matchers::AliasedMatcher Private
- Inherits:
-
MatcherDelegator
- Object
- MatcherDelegator
- RSpec::Matchers::AliasedMatcher
- Defined in:
- lib/rspec/matchers/aliased_matcher.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Decorator that wraps a matcher and overrides description
using the provided block in order to support an alias
of a matcher. This is intended for use when composing
matchers, so that you can use an expression like
include( a_value_within(0.1).of(3) )
rather than
include( be_within(0.1).of(3) )
, and have the corresponding
description read naturally.
Instance Method Summary (collapse)
-
- (Object) description
private
Provides the description of the aliased matcher.
-
- (Object) failure_message
private
Provides the failure_message of the aliased matcher.
-
- (Object) failure_message_when_negated
private
Provides the failure_message_when_negated of the aliased matcher.
-
- (AliasedMatcher) initialize(base_matcher, description_block)
constructor
private
A new instance of AliasedMatcher.
-
- (Object) method_missing
private
Forward messages on to the wrapped matcher.
Methods included from Composable
#===, #and, #description_of, enumerable?, #or, surface_descriptions_in, #values_match?
Constructor Details
- (AliasedMatcher) initialize(base_matcher, description_block)
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 a new instance of AliasedMatcher
13 14 15 16 |
# File 'lib/rspec/matchers/aliased_matcher.rb', line 13 def initialize(base_matcher, description_block) @description_block = description_block super(base_matcher) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing
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.
Forward messages on to the wrapped matcher.
Since many matchers provide a fluent interface
(e.g. a_value_within(0.1).of(3)
), we need to wrap
the returned value if it responds to description
,
so that our override can be applied when it is eventually
used.
24 25 26 27 28 |
# File 'lib/rspec/matchers/aliased_matcher.rb', line 24 def method_missing(*) return_val = super return return_val unless RSpec::Matchers.is_a_matcher?(return_val) self.class.new(return_val, @description_block) end |
Instance Method Details
- (Object) description
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.
Provides the description of the aliased matcher. Aliased matchers are designed to behave identically to the original matcher except for the description and failure messages. The description is different to reflect the aliased name.
36 37 38 |
# File 'lib/rspec/matchers/aliased_matcher.rb', line 36 def description @description_block.call(super) end |
- (Object) failure_message
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.
Provides the failure_message of the aliased matcher. Aliased matchers are designed to behave identically to the original matcher except for the description and failure messages. The failure_message is different to reflect the aliased name.
46 47 48 |
# File 'lib/rspec/matchers/aliased_matcher.rb', line 46 def @description_block.call(super) end |
- (Object) failure_message_when_negated
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.
Provides the failure_message_when_negated of the aliased matcher. Aliased matchers are designed to behave identically to the original matcher except for the description and failure messages. The failure_message_when_negated is different to reflect the aliased name.
56 57 58 |
# File 'lib/rspec/matchers/aliased_matcher.rb', line 56 def @description_block.call(super) end |