Sha256: 89a7a7eaaf37045c41bb07e9b6a6cfea96aa1d954df5ee503d19c8eff86ec9f1

Contents?: true

Size: 1.25 KB

Versions: 61

Compression:

Stored size: 1.25 KB

Contents

require 'mocha/parameter_matchers/base'

module Mocha

  module ParameterMatchers

    # Matches if +matcher+ does *not* match.
    #
    # @param [Base] matcher matcher whose logic to invert.
    # @return [Not] parameter matcher.
    #
    # @see Expectation#with
    #
    # @example Actual parameter does not include the value +1+.
    #   object = mock()
    #   object.expects(:method_1).with(Not(includes(1)))
    #   object.method_1([0, 2, 3])
    #   # no error raised
    #
    # @example Actual parameter does include the value +1+.
    #   object = mock()
    #   object.expects(:method_1).with(Not(includes(1)))
    #   object.method_1([0, 1, 2, 3])
    #   # error raised, because method_1 was not called with object not including 1
    def Not(matcher)
      Not.new(matcher)
    end

    # Parameter matcher which inverts the logic of the specified matcher using a logical NOT operation.
    class Not < Base

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

      # @private
      def matches?(available_parameters)
        parameter = available_parameters.shift
        !@matcher.matches?([parameter])
      end

      # @private
      def mocha_inspect
        "Not(#{@matcher.mocha_inspect})"
      end

    end

  end

end

Version data entries

61 entries across 50 versions & 5 rubygems

Version Path
mocha-1.6.0 lib/mocha/parameter_matchers/not.rb
mocha-1.5.0 lib/mocha/parameter_matchers/not.rb
mocha-1.4.0 lib/mocha/parameter_matchers/not.rb
mocha-1.3.0 lib/mocha/parameter_matchers/not.rb
mocha-1.2.1 lib/mocha/parameter_matchers/not.rb
mocha-1.2.0 lib/mocha/parameter_matchers/not.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/mocha-1.0.0/lib/mocha/parameter_matchers/not.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/mocha-1.0.0/lib/mocha/parameter_matchers/not.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/mocha-1.0.0/lib/mocha/parameter_matchers/not.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/mocha-1.0.0/lib/mocha/parameter_matchers/not.rb
mocha-1.1.0 lib/mocha/parameter_matchers/not.rb
mocha-1.0.0 lib/mocha/parameter_matchers/not.rb
mocha-1.0.0.alpha lib/mocha/parameter_matchers/not.rb
tnargav-1.3.3 vendor/bundle/ruby/1.9.1/gems/mocha-0.14.0/lib/mocha/parameter_matchers/not.rb
challah-1.0.0 vendor/bundle/gems/mocha-0.14.0/lib/mocha/parameter_matchers/not.rb
tnargav-1.2.3 vendor/bundle/ruby/1.9.1/gems/mocha-0.14.0/lib/mocha/parameter_matchers/not.rb
mocha-0.14.0 lib/mocha/parameter_matchers/not.rb
challah-1.0.0.beta3 vendor/bundle/gems/mocha-0.13.3/lib/mocha/parameter_matchers/not.rb
mocha-0.14.0.alpha lib/mocha/parameter_matchers/not.rb
challah-1.0.0.beta2 vendor/bundle/gems/mocha-0.13.3/lib/mocha/parameter_matchers/not.rb