Sha256: 3725cd105d3f7ab3cd28a04299de70d8e21f033effe950107f1b640b41cb5483

Contents?: true

Size: 930 Bytes

Versions: 4

Compression:

Stored size: 930 Bytes

Contents

module RSpec
  module Matchers
    module BuiltIn
      # @api private
      # Provides the implementation for `be_a_kind_of`.
      # Not intended to be instantiated directly.
      class BeAKindOf < BaseMatcher
      private

        def match(expected, actual)
          if actual_object_respond_to?(actual, :kind_of?)
            actual.kind_of?(expected)
          elsif actual_object_respond_to?(actual, :is_a?)
            actual.is_a?(expected)
          else
            raise ::ArgumentError, "The #{matcher_name} matcher requires that " \
                                   "the actual object responds to either #kind_of? or #is_a? methods "\
                                   "but it responds to neigher of two methods."
          end
        end

        def actual_object_respond_to?(actual, method)
          ::Kernel.instance_method(:respond_to?).bind(actual).call(method)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
nabea2-0.1.2 vendor/bundle/ruby/2.6.0/gems/rspec-expectations-3.8.3/lib/rspec/matchers/built_in/be_kind_of.rb
nabea2-0.1.1 vendor/bundle/ruby/2.6.0/gems/rspec-expectations-3.8.3/lib/rspec/matchers/built_in/be_kind_of.rb
nabea2-0.1.0 vendor/bundle/ruby/2.6.0/gems/rspec-expectations-3.8.3/lib/rspec/matchers/built_in/be_kind_of.rb
rspec-expectations-3.8.3 lib/rspec/matchers/built_in/be_kind_of.rb