Class: RSpec::Matchers::AliasedMatcher

### Home Classes Methods

### In Files

- lib/rspec/matchers/aliased_matcher.rb

### Parent

MatcherDelegator

### Methods

- ::new
- #description
- #failure_message
- #failure_message_when_negated
- #method_missing

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Expectations
- RSpec::Expectations::BlockExpectationTarget
- RSpec::Expectations::Configuration
- RSpec::Expectations::ExpectationHelper
- RSpec::Expectations::ExpectationNotMetError
- RSpec::Expectations::ExpectationTarget
- RSpec::Expectations::FailureAggregator
- RSpec::Expectations::LegacyMacherAdapter
- RSpec::Expectations::LegacyMatcherAdapter
- RSpec::Expectations::LegacyMatcherAdapter::RSpec1
- RSpec::Expectations::LegacyMatcherAdapter::RSpec2
- RSpec::Expectations::MultipleExpectationsNotMetError
- RSpec::Expectations::NegativeExpectationHandler
- RSpec::Expectations::PositiveExpectationHandler
- RSpec::Expectations::Syntax
- RSpec::Expectations::Version
- RSpec::Matchers
- RSpec::Matchers::AliasedMatcher
- RSpec::Matchers::AliasedMatcherWithOperatorSupport
- RSpec::Matchers::AliasedNegatedMatcher
- RSpec::Matchers::BuiltIn
- RSpec::Matchers::BuiltIn::All
- RSpec::Matchers::BuiltIn::BaseMatcher
- RSpec::Matchers::BuiltIn::BaseMatcher::DefaultFailureMessages
- RSpec::Matchers::BuiltIn::BaseMatcher::HashFormatting
- RSpec::Matchers::BuiltIn::Be
- RSpec::Matchers::BuiltIn::BeAKindOf
- RSpec::Matchers::BuiltIn::BeAnInstanceOf
- RSpec::Matchers::BuiltIn::BeBetween
- RSpec::Matchers::BuiltIn::BeComparedTo
- RSpec::Matchers::BuiltIn::BeFalsey
- RSpec::Matchers::BuiltIn::BeHelpers
- RSpec::Matchers::BuiltIn::BeNil
- RSpec::Matchers::BuiltIn::BePredicate
- RSpec::Matchers::BuiltIn::BeTruthy
- RSpec::Matchers::BuiltIn::BeWithin
- RSpec::Matchers::BuiltIn::CaptureStderr
- RSpec::Matchers::BuiltIn::CaptureStdout
- RSpec::Matchers::BuiltIn::CaptureStreamToTempfile
- RSpec::Matchers::BuiltIn::Change
- RSpec::Matchers::BuiltIn::ChangeDetails
- RSpec::Matchers::BuiltIn::ChangeFromValue
- RSpec::Matchers::BuiltIn::ChangeRelatively
- RSpec::Matchers::BuiltIn::ChangeToValue
- RSpec::Matchers::BuiltIn::Compound
- RSpec::Matchers::BuiltIn::Compound::And
- RSpec::Matchers::BuiltIn::Compound::NestedEvaluator
- RSpec::Matchers::BuiltIn::Compound::Or
- RSpec::Matchers::BuiltIn::Compound::SequentialEvaluator
- RSpec::Matchers::BuiltIn::ContainExactly
- RSpec::Matchers::BuiltIn::ContainExactly::PairingsMaximizer
- RSpec::Matchers::BuiltIn::Cover
- RSpec::Matchers::BuiltIn::EndWith
- RSpec::Matchers::BuiltIn::Eq
- RSpec::Matchers::BuiltIn::Eql
- RSpec::Matchers::BuiltIn::Equal
- RSpec::Matchers::BuiltIn::Exist
- RSpec::Matchers::BuiltIn::Exist::ExistenceTest
- RSpec::Matchers::BuiltIn::Has
- RSpec::Matchers::BuiltIn::HaveAttributes
- RSpec::Matchers::BuiltIn::Include
- RSpec::Matchers::BuiltIn::Match
- RSpec::Matchers::BuiltIn::NegativeOperatorMatcher
- RSpec::Matchers::BuiltIn::NullCapture
- RSpec::Matchers::BuiltIn::OperatorMatcher
- RSpec::Matchers::BuiltIn::Output
- RSpec::Matchers::BuiltIn::PositiveOperatorMatcher
- RSpec::Matchers::BuiltIn::RaiseError
- RSpec::Matchers::BuiltIn::RespondTo
- RSpec::Matchers::BuiltIn::Satisfy
- RSpec::Matchers::BuiltIn::SpecificValuesChange
- RSpec::Matchers::BuiltIn::StartAndEndWith
- RSpec::Matchers::BuiltIn::StartOrEndWith
- RSpec::Matchers::BuiltIn::StartWith
- RSpec::Matchers::BuiltIn::ThrowSymbol
- RSpec::Matchers::BuiltIn::YieldControl
- RSpec::Matchers::BuiltIn::YieldProbe
- RSpec::Matchers::BuiltIn::YieldSuccessiveArgs
- RSpec::Matchers::BuiltIn::YieldWithArgs
- RSpec::Matchers::BuiltIn::YieldWithNoArgs
- RSpec::Matchers::Composable
- RSpec::Matchers::DSL
- RSpec::Matchers::DSL::DefaultImplementations
- RSpec::Matchers::DSL::Macros
- RSpec::Matchers::DSL::Macros::Deprecated
- RSpec::Matchers::DSL::Matcher
- RSpec::Matchers::EnglishPhrasing
- RSpec::Matchers::ExpectedsForMultipleDiffs
- RSpec::Matchers::FailMatchers
- RSpec::Matchers::MatcherDelegator
- RSpec::Matchers::MatcherProtocol
- BasicObject
- Object

No matching classes.

# RSpec::Matchers::AliasedMatcher

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.

@api private

### Public Class Methods

new(base_matcher, description_block) click to toggle source

    # File lib/rspec/matchers/aliased_matcher.rb, line 13
    def initialize(base_matcher, description_block)
      @description_block = description_block
      super(base_matcher)
    end

### Public Instance Methods

description() click to toggle source

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.

@api private

    # File lib/rspec/matchers/aliased_matcher.rb, line 36
    def description
      @description_block.call(super)
    end

failure_message() click to toggle source

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.

@api private

    # File lib/rspec/matchers/aliased_matcher.rb, line 46
    def failure_message
      @description_block.call(super)
    end

failure_message_when_negated() click to toggle source

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.

@api private

    # File lib/rspec/matchers/aliased_matcher.rb, line 56
    def failure_message_when_negated
      @description_block.call(super)
    end

method_missing(*) click to toggle source

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 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.