Class: RSpec::Matchers::BuiltIn::BaseMatcher

### Home Classes Methods

### In Files

- lib/rspec/matchers/built_in/base_matcher.rb

### Parent

Object

### Methods

- ::new
- #==
- #description
- #diffable?
- #failure_message_for_should
- #failure_message_for_should_not
- #match_unless_raises
- #matches?

### Included Modules

- RSpec::Matchers::Pretty

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Expectations
- RSpec::Expectations::DeprecatedConstants
- RSpec::Expectations::Deprecation
- RSpec::Expectations::Differ
- RSpec::Expectations::ExpectationHandler
- RSpec::Expectations::ExpectationNotMetError
- RSpec::Expectations::ExpectationTarget
- RSpec::Expectations::NegativeExpectationHandler
- RSpec::Expectations::PositiveExpectationHandler
- RSpec::Expectations::Syntax
- RSpec::Expectations::Syntax::ExpectExpressionGenerator
- RSpec::Expectations::Syntax::ShouldExpressionGenerator
- RSpec::Expectations::Version
- RSpec::Matchers
- RSpec::Matchers::BuiltIn
- RSpec::Matchers::BuiltIn::BaseMatcher
- RSpec::Matchers::BuiltIn::Be
- RSpec::Matchers::BuiltIn::BeAKindOf
- RSpec::Matchers::BuiltIn::BeAnInstanceOf
- RSpec::Matchers::BuiltIn::BeComparedTo
- RSpec::Matchers::BuiltIn::BeFalse
- RSpec::Matchers::BuiltIn::BeHelpers
- RSpec::Matchers::BuiltIn::BeNil
- RSpec::Matchers::BuiltIn::BePredicate
- RSpec::Matchers::BuiltIn::BeTrue
- RSpec::Matchers::BuiltIn::BeWithin
- RSpec::Matchers::BuiltIn::Change
- 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::Has
- RSpec::Matchers::BuiltIn::Have
- RSpec::Matchers::BuiltIn::Include
- RSpec::Matchers::BuiltIn::Match
- RSpec::Matchers::BuiltIn::MatchArray
- RSpec::Matchers::BuiltIn::NegativeOperatorMatcher
- RSpec::Matchers::BuiltIn::PositiveOperatorMatcher
- RSpec::Matchers::BuiltIn::RaiseError
- RSpec::Matchers::BuiltIn::RespondTo
- RSpec::Matchers::BuiltIn::Satisfy
- RSpec::Matchers::BuiltIn::StartAndEndWith
- 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::Configuration
- RSpec::Matchers::DSL
- RSpec::Matchers::DSL::Matcher
- RSpec::Matchers::Extensions
- RSpec::Matchers::Extensions::InstanceEvalWithArgs
- RSpec::Matchers::OperatorMatcher
- RSpec::Matchers::Pretty
- Array

No matching classes.

# RSpec::Matchers::BuiltIn::BaseMatcher

@api private

Used internally as a base class for matchers that ship with rspec-expectations.

### Warning:

This class is for internal use, and subject to change without notice. We strongly recommend that you do not base your custom matchers on this class. If/when this changes, we will announce it and remove this warning.

### Attributes

actual[R]
expected[R]
rescued_exception[R]

### Public Class Methods

new(expected = nil) click to toggle source

    # File lib/rspec/matchers/built_in/base_matcher.rb, line 19
    def initialize(expected = nil)
      @expected = expected
    end

### Public Instance Methods

==(other) click to toggle source

    # File lib/rspec/matchers/built_in/base_matcher.rb, line 56
    def ==(other)
      matches?(other)
    end

description() click to toggle source

    # File lib/rspec/matchers/built_in/base_matcher.rb, line 48
    def description
      expected ? "#{name_to_sentence} #{@expected.inspect}" : name_to_sentence
    end

diffable?() click to toggle source

    # File lib/rspec/matchers/built_in/base_matcher.rb, line 52
    def diffable?
      false
    end

failure_message_for_should() click to toggle source

    # File lib/rspec/matchers/built_in/base_matcher.rb, line 38
    def failure_message_for_should
      assert_ivars :@actual, :@expected
      "expected #{@actual.inspect} to #{name_to_sentence}#{expected_to_sentence}"
    end

failure_message_for_should_not() click to toggle source

    # File lib/rspec/matchers/built_in/base_matcher.rb, line 43
    def failure_message_for_should_not
      assert_ivars :@actual, :@expected
      "expected #{@actual.inspect} not to #{name_to_sentence}#{expected_to_sentence}"
    end

match_unless_raises(*exceptions) click to toggle source

    # File lib/rspec/matchers/built_in/base_matcher.rb, line 28
    def match_unless_raises(*exceptions)
      exceptions.unshift Exception if exceptions.empty?
      begin
        yield
        true
      rescue *exceptions => @rescued_exception
        false
      end
    end

matches?(actual) click to toggle source

    # File lib/rspec/matchers/built_in/base_matcher.rb, line 23
    def matches?(actual)
      @actual = actual
      match(expected, actual)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.