class 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
Calls superclass method
# 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

Calls superclass method
# 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

Calls superclass method
# 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

Calls superclass method
# 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.

Calls superclass method
# 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