Class: RSpec::Matchers::AliasedMatcher Private
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
RSpec::Matchers::AliasedMatcherWithOperatorSupport, RSpec::Matchers::AliasedNegatedMatcher
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
MatcherDelegator ,
BaseDelegator
|
|
Instance Chain:
|
|
Inherits: |
RSpec::Matchers::MatcherDelegator
|
Defined in: | rspec-expectations/lib/rspec/matchers/aliased_matcher.rb |
Overview
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.
Class Method Summary
- .new(base_matcher, description_block) ⇒ AliasedMatcher constructor Internal use only
MatcherDelegator
- Inherited
Instance Attribute Summary
MatcherDelegator
- Inherited
Instance Method Summary
-
#description
Internal use only
Provides the description of the aliased matcher.
-
#failure_message
Internal use only
Provides the failure_message of the aliased matcher.
-
#failure_message_when_negated
Internal use only
Provides the failure_message_when_negated of the aliased matcher.
-
#method_missing
Internal use only
Forward messages on to the wrapped matcher.
MatcherDelegator
- Inherited
Composable
- Included
#& | Alias for Composable#and. |
#=== | Delegates to |
#and | Creates a compound |
#description_of | Returns the description of the given object in a way that is aware of composed matchers. |
#or | Creates a compound |
#values_match? | This provides a generic way to fuzzy-match an expected value against an actual value. |
#| | Alias for Composable#or. |
#should_enumerate? | We should enumerate arrays as long as they are not recursive. |
#surface_descriptions_in | Transforms the given data structure (typically a hash or array) into a new data structure that, when |
#unreadable_io?, | |
#with_matchers_cloned | Historically, a single matcher instance was only checked against a single value. |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing
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.
# File 'rspec-expectations/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
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.
# File 'rspec-expectations/lib/rspec/matchers/aliased_matcher.rb', line 36
def description @description_block.call(super) end
#failure_message
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.
# File 'rspec-expectations/lib/rspec/matchers/aliased_matcher.rb', line 46
def @description_block.call(super) end
#failure_message_when_negated
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.
# File 'rspec-expectations/lib/rspec/matchers/aliased_matcher.rb', line 56
def @description_block.call(super) end