Class: RSpec::Matchers::DSL::Matcher

### Home Classes Methods

### In Files

- lib/rspec/matchers/dsl.rb

### Parent

Object

### Methods

- ::new
- #expected
- #inspect
- #respond_to?
- #respond_to_missing?

### Included Modules

- RSpec::Matchers::DSL::DefaultImplementations
- RSpec::Matchers
- RSpec::Matchers::Pretty
- RSpec::Matchers::Composable

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Expectations
- RSpec::Expectations::BlockExpectationTarget
- RSpec::Expectations::Configuration
- RSpec::Expectations::ExpectationHelper
- RSpec::Expectations::ExpectationNotMetError
- RSpec::Expectations::ExpectationTarget
- RSpec::Expectations::LegacyMacherAdapter
- RSpec::Expectations::LegacyMatcherAdapter
- RSpec::Expectations::LegacyMatcherAdapter::RSpec1
- RSpec::Expectations::LegacyMatcherAdapter::RSpec2
- 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::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::ExpectedsForMultipleDiffs
- RSpec::Matchers::MatcherDelegator
- RSpec::Matchers::MatcherProtocol
- RSpec::Matchers::Pretty
- BasicObject
- Object

No matching classes.

# RSpec::Matchers::DSL::Matcher

The class used for custom matchers. The block passed to `RSpec::Matchers.define` will be evaluated in the context of the singleton class of an instance, and will have the {RSpec::Matchers::DSL::Macros Macros} methods available.

### Attributes

actual[R]

Exposes the value being matched against -- generally the object object wrapped by `expect`.

block_arg[R]

The block parameter used in the expectation

expected_as_array[R]

Returns the expected value as an an array. This exists primarily to aid in upgrading from RSpec 2.x, since in RSpec 2, `expected` always returned an array. @see expected

rescued_exception[R]

Exposes the exception raised during the matching by `match_unless_raises`. Could be useful to extract details for a failure message.

### Public Class Methods

new(name, declarations, matcher_execution_context, *expected, &block_arg) click to toggle source

@api private

    # File lib/rspec/matchers/dsl.rb, line 361
    def initialize(name, declarations, matcher_execution_context, *expected, &block_arg)
      @name     = name
      @actual   = nil
      @expected_as_array = expected
      @matcher_execution_context = matcher_execution_context
      @chained_method_clauses = []
      @block_arg = block_arg

      class << self
        # See `Macros#define_user_override` above, for an explanation.
        include(@user_method_defs = Module.new)
        self
      end.class_exec(*expected, &declarations)
    end

### Public Instance Methods

expected() click to toggle source

Provides the expected value. This will return an array if multiple arguments were passed to the matcher; otherwise it will return a single value. @see expected_as_array

    # File lib/rspec/matchers/dsl.rb, line 380
    def expected
      if expected_as_array.size == 1
        expected_as_array[0]
      else
        expected_as_array
      end
    end

inspect() click to toggle source

Adds the name (rather than a cryptic hex number) so we can identify an instance of the matcher in error messages (e.g. for `NoMethodError`)

    # File lib/rspec/matchers/dsl.rb, line 397
    def inspect
      "#<#{self.class.name} #{name}>"
    end

respond_to?(method, include_private=false) click to toggle source

Indicates that this matcher responds to messages from the `@matcher_execution_context` as well.

    # File lib/rspec/matchers/dsl.rb, line 411
    def respond_to?(method, include_private=false)
      super || @matcher_execution_context.respond_to?(method, include_private)
    end

respond_to_missing?(method, include_private=false) click to toggle source

Indicates that this matcher responds to messages from the `@matcher_execution_context` as well. Also, supports getting a method object for such methods.

    # File lib/rspec/matchers/dsl.rb, line 405
    def respond_to_missing?(method, include_private=false)
      super || @matcher_execution_context.respond_to?(method, include_private)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.