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
-
#description ⇒ Object
private
Provides the description of the aliased matcher.
-
#failure_message ⇒ Object
private
Provides the failure_message of the aliased matcher.
-
#failure_message_when_negated ⇒ Object
private
Provides the failure_message_when_negated of the aliased matcher.
-
#initialize(base_matcher, description_block) ⇒ AliasedMatcher
constructor
private
A new instance of AliasedMatcher.
-
#method_missing ⇒ Object
private
Forward messages on to the wrapped matcher.
Methods included from Composable
#===, #and, #description_of, #or, should_enumerate?, surface_descriptions_in, unreadable_io?, #values_match?
Constructor Details
#initialize(base_matcher, description_block) ⇒ AliasedMatcher
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
#method_missing ⇒ Object
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
#description ⇒ Object
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 |
#failure_message ⇒ Object
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 |
#failure_message_when_negated ⇒ Object
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 |