Sha256: e5ac9bb5e6b4af950cad15aa071a407cf2e174fde4aaa1edd439ce68021c5a45

Contents?: true

Size: 1.32 KB

Versions: 6

Compression:

Stored size: 1.32 KB

Contents

module RSpec
  module Matchers
    # @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.
    module BaseMatcher
      include RSpec::Matchers::Pretty

      attr_reader :actual, :expected, :rescued_exception

      def initialize(expected=nil)
        @expected = expected
      end

      def matches?(actual)
        @actual = actual
      end

      def match_unless_raises(exception=Exception)
        begin
          yield
          true
        rescue exception => @rescued_exception
          false
        end
      end

      def failure_message_for_should
        "expected #{actual.inspect} to #{name_to_sentence}#{expected_to_sentence}"
      end

      def failure_message_for_should_not
        "expected #{actual.inspect} not to #{name_to_sentence}#{expected_to_sentence}"
      end

      def description
        expected ? "#{name_to_sentence} #{expected.inspect}" : name_to_sentence
      end

      def diffable?
        false
      end

      def ==(other)
        matches?(other)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
resque-pool-0.3.0 vendor/bundle/ruby/1.8/gems/rspec-expectations-2.8.0/lib/rspec/matchers/base_matcher.rb
resque-pool-0.3.0.beta.2 vendor/bundle/ruby/1.8/gems/rspec-expectations-2.8.0/lib/rspec/matchers/base_matcher.rb
horseman-0.0.4 vendor/ruby/1.9.1/gems/rspec-expectations-2.8.0/lib/rspec/matchers/base_matcher.rb
horseman-0.0.3 vendor/ruby/1.9.1/gems/rspec-expectations-2.8.0/lib/rspec/matchers/base_matcher.rb
rspec-expectations-2.8.0 lib/rspec/matchers/base_matcher.rb
rspec-expectations-2.8.0.rc2 lib/rspec/matchers/base_matcher.rb