Sha256: c10f023c6914fc732c00913eb8ae18feb8c49d4a9041b38c1ca3da5687cb6297

Contents?: true

Size: 1.81 KB

Versions: 50

Compression:

Stored size: 1.81 KB

Contents

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

        attr_reader :actual, :expected, :rescued_exception

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

        def matches?(actual)
          @actual = actual
          match(expected, actual)
        end

        def match_unless_raises(*exceptions)
          exceptions.unshift Exception if exceptions.empty?
          begin
            yield
            true
          rescue *exceptions => @rescued_exception
            false
          end
        end

        def failure_message_for_should
          assert_ivars :@actual, :@expected
          "expected #{@actual.inspect} to #{name_to_sentence}#{expected_to_sentence}"
        end

        def failure_message_for_should_not
          assert_ivars :@actual, :@expected
          "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

        private

        def assert_ivars *ivars
          raise "#{self.class.name} needs to supply #{to_sentence ivars}" unless ivars.all? { |v| instance_variables.map(&:intern).include? v }
        end
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 17 rubygems

Version Path
opal-rspec-cj-0.4.4 vendor_lib/rspec/matchers/built_in/base_matcher.rb
opal-rspec-0.4.3 vendor_lib/rspec/matchers/built_in/base_matcher.rb
opal-rspec-0.4.2 vendor_lib/rspec/matchers/built_in/base_matcher.rb
opal-rspec-0.4.1 vendor_lib/rspec/matchers/built_in/base_matcher.rb
opal-rspec-0.4.0 vendor_lib/rspec/matchers/built_in/base_matcher.rb
opal-rspec-0.4.0.beta4 vendor_lib/rspec/matchers/built_in/base_matcher.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/rspec-expectations-2.13.0/lib/rspec/matchers/built_in/base_matcher.rb
dxruby_rp5-0.0.4 spec/vendor/rspec-expectations-2.14.4/lib/rspec/matchers/built_in/base_matcher.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/rspec-expectations-2.14.4/lib/rspec/matchers/built_in/base_matcher.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/rspec-expectations-2.14.4/lib/rspec/matchers/built_in/base_matcher.rb
dxruby_rp5-0.0.3 spec/vendor/rspec-expectations-2.14.4/lib/rspec/matchers/built_in/base_matcher.rb
tuktuk-rails-0.0.10 vendor/bundle/ruby/2.0.0/gems/rspec-expectations-2.14.4/lib/rspec/matchers/built_in/base_matcher.rb
tuktuk-rails-0.0.9 vendor/bundle/ruby/2.0.0/gems/rspec-expectations-2.14.4/lib/rspec/matchers/built_in/base_matcher.rb
tuktuk-rails-0.0.8 vendor/bundle/ruby/2.0.0/gems/rspec-expectations-2.14.4/lib/rspec/matchers/built_in/base_matcher.rb
tuktuk-rails-0.0.7 vendor/bundle/ruby/2.0.0/gems/rspec-expectations-2.14.4/lib/rspec/matchers/built_in/base_matcher.rb
dxruby_rp5-0.0.2 spec/vendor/rspec-expectations-2.14.4/lib/rspec/matchers/built_in/base_matcher.rb
dxruby_rp5-0.0.1 spec/vendor/rspec-expectations-2.14.4/lib/rspec/matchers/built_in/base_matcher.rb
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/rspec-expectations-2.14.4/lib/rspec/matchers/built_in/base_matcher.rb
rspec-expectations-3.0.0.beta1 lib/rspec/matchers/built_in/base_matcher.rb
rspec-expectations-2.99.0.beta1 lib/rspec/matchers/built_in/base_matcher.rb