Sha256: 5013958e356eac1a727bff9b62ab605379edb013f95dc13d0ae3f3c10ec94f62

Contents?: true

Size: 1.32 KB

Versions: 12

Compression:

Stored size: 1.32 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
    # rubocop:disable Naming/MethodName
    def Not(matcher)
      Not.new(matcher)
    end
    # rubocop:enable Naming/MethodName

    # 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

12 entries across 12 versions & 2 rubygems

Version Path
mocha-1.11.1 lib/mocha/parameter_matchers/not.rb
mocha-1.11.0 lib/mocha/parameter_matchers/not.rb
mocha-1.10.2 lib/mocha/parameter_matchers/not.rb
mocha-1.10.1 lib/mocha/parameter_matchers/not.rb
mocha-1.10.0 lib/mocha/parameter_matchers/not.rb
mocha-1.10.0.beta.1 lib/mocha/parameter_matchers/not.rb
mocha-1.10.0.alpha lib/mocha/parameter_matchers/not.rb
mocha-1.9.0 lib/mocha/parameter_matchers/not.rb
cocoapods-dependency-html-0.0.2 vendor/bundle/gems/mocha-1.8.0/lib/mocha/parameter_matchers/not.rb
cocoapods-dependency-html-0.0.1 vendor/bundle/gems/mocha-1.8.0/lib/mocha/parameter_matchers/not.rb
mocha-1.8.0 lib/mocha/parameter_matchers/not.rb
mocha-1.7.0 lib/mocha/parameter_matchers/not.rb