Sha256: 7e3a6c1592f0ebe6b9a22ee725a710f5f23498a63e3ba6d661ca9f3b03bbf344

Contents?: true

Size: 1.19 KB

Versions: 39

Compression:

Stored size: 1.19 KB

Contents

require 'mocha/parameter_matchers/base'

module Mocha

  module ParameterMatchers

    # Matches any object that responds with +true+ to +include?(item)+.
    #
    # @param [Object] item expected item.
    # @return [Includes] parameter matcher.
    #
    # @see Expectation#with
    #
    # @example Actual parameter includes item.
    #   object = mock()
    #   object.expects(:method_1).with(includes('foo'))
    #   object.method_1(['foo', 'bar'])
    #   # no error raised
    #
    # @example Actual parameter does not include item.
    #   object.method_1(['baz'])
    #   # error raised, because ['baz'] does not include 'foo'.
    def includes(item)
      Includes.new(item)
    end

    # Parameter matcher which matches when actual parameter includes expected value.
    class Includes < Base

      # @private
      def initialize(item)
        @item = item
      end

      # @private
      def matches?(available_parameters)
        parameter = available_parameters.shift
        return false unless parameter.respond_to?(:include?)
        return parameter.include?(@item)
      end

      # @private
      def mocha_inspect
        "includes(#{@item.mocha_inspect})"
      end

    end

  end

end

Version data entries

39 entries across 31 versions & 3 rubygems

Version Path
mocha-0.12.10 lib/mocha/parameter_matchers/includes.rb
mocha-0.12.9 lib/mocha/parameter_matchers/includes.rb
mocha-0.13.2 lib/mocha/parameter_matchers/includes.rb
mocha-0.12.8 lib/mocha/parameter_matchers/includes.rb
mocha-0.13.1 lib/mocha/parameter_matchers/includes.rb
challah-rolls-0.2.0 vendor/bundle/gems/mocha-0.12.2/lib/mocha/parameter_matchers/includes.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/mocha-0.13.0/lib/mocha/parameter_matchers/includes.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/mocha-0.12.3/lib/mocha/parameter_matchers/includes.rb
challah-rolls-0.2.0 vendor/bundle/gems/mocha-0.13.0/lib/mocha/parameter_matchers/includes.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/mocha-0.12.2/lib/mocha/parameter_matchers/includes.rb
challah-rolls-0.2.0 vendor/bundle/gems/mocha-0.12.3/lib/mocha/parameter_matchers/includes.rb
challah-0.8.3 vendor/bundle/gems/mocha-0.13.0/lib/mocha/parameter_matchers/includes.rb
challah-0.8.3 vendor/bundle/gems/mocha-0.12.3/lib/mocha/parameter_matchers/includes.rb
mocha-0.13.0 lib/mocha/parameter_matchers/includes.rb
mocha-0.12.7 lib/mocha/parameter_matchers/includes.rb
mocha-0.12.6 lib/mocha/parameter_matchers/includes.rb
mocha-0.12.5 lib/mocha/parameter_matchers/includes.rb
challah-0.8.1 vendor/bundle/gems/mocha-0.12.3/lib/mocha/parameter_matchers/includes.rb
mocha-0.12.4 lib/mocha/parameter_matchers/includes.rb
challah-rolls-0.1.0 vendor/bundle/gems/mocha-0.12.3/lib/mocha/parameter_matchers/includes.rb