Sha256: 07272527037522998e15b3bfab2fef1e16ff613f71d5dd497486e089503f1b2c

Contents?: true

Size: 1.31 KB

Versions: 42

Compression:

Stored size: 1.31 KB

Contents

require 'mocha/parameter_matchers/base'

module Mocha
  module ParameterMatchers
    # Matches any +Object+ that is a kind of +klass+.
    #
    # @param [Class] klass expected class.
    # @return [KindOf] parameter matcher.
    #
    # @see Expectation#with
    # @see Kernel#kind_of?
    #
    # @example Actual parameter is a kind of +Integer+.
    #   object = mock()
    #   object.expects(:method_1).with(kind_of(Integer))
    #   object.method_1(99)
    #   # no error raised
    #
    # @example Actual parameter is not a kind of +Integer+.
    #   object = mock()
    #   object.expects(:method_1).with(kind_of(Integer))
    #   object.method_1('string')
    #   # error raised, because method_1 was not called with a kind of Integer
    def kind_of(klass)
      KindOf.new(klass)
    end

    # Parameter matcher which matches when actual parameter is a kind of specified class.
    class KindOf < Base
      # @private
      def initialize(klass)
        @klass = klass
      end

      # @private
      def matches?(available_parameters)
        parameter = available_parameters.shift
        # rubocop:disable Style/ClassCheck
        parameter.kind_of?(@klass)
        # rubocop:enable Style/ClassCheck
      end

      # @private
      def mocha_inspect
        "kind_of(#{@klass.mocha_inspect})"
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 4 rubygems

Version Path
tailscale_middleware-0.0.3 vendor/cache/ruby/3.4.0/gems/mocha-2.7.1/lib/mocha/parameter_matchers/kind_of.rb
mocha-2.7.1 lib/mocha/parameter_matchers/kind_of.rb
mocha-2.7.0 lib/mocha/parameter_matchers/kind_of.rb
mocha-2.6.1 lib/mocha/parameter_matchers/kind_of.rb
mocha-2.6.0 lib/mocha/parameter_matchers/kind_of.rb
mocha-2.5.0 lib/mocha/parameter_matchers/kind_of.rb
mocha-2.4.5 lib/mocha/parameter_matchers/kind_of.rb
mocha-2.4.4 lib/mocha/parameter_matchers/kind_of.rb
mocha-2.4.3 lib/mocha/parameter_matchers/kind_of.rb
mocha-2.4.2 lib/mocha/parameter_matchers/kind_of.rb
mocha-2.4.1 lib/mocha/parameter_matchers/kind_of.rb
mocha-2.4.0 lib/mocha/parameter_matchers/kind_of.rb
mocha-2.2.0 lib/mocha/parameter_matchers/kind_of.rb
mocha-2.1.0 lib/mocha/parameter_matchers/kind_of.rb
mocha-2.0.4 lib/mocha/parameter_matchers/kind_of.rb
mocha-2.0.3 lib/mocha/parameter_matchers/kind_of.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/mocha-2.0.2/lib/mocha/parameter_matchers/kind_of.rb
mocha-2.0.2 lib/mocha/parameter_matchers/kind_of.rb
mocha-1.16.1 lib/mocha/parameter_matchers/kind_of.rb
mocha-1.15.1 lib/mocha/parameter_matchers/kind_of.rb