Sha256: afa021b8b1b260dab9210e8597ec7ef0c2c8516903c616c287f80f4ba3cc4766

Contents?: true

Size: 1.07 KB

Versions: 118

Compression:

Stored size: 1.07 KB

Contents

require 'mocha/parameter_matchers/base'

module Mocha
  
  module ParameterMatchers

    # :call-seq: all_of(*parameter_matchers) -> parameter_matcher
    #
    # Matches if all +parameter_matchers+ match.
    #   object = mock()
    #   object.expects(:method_1).with(all_of(includes(1), includes(3)))
    #   object.method_1([1, 3])
    #   # no error raised
    #
    #   object = mock()
    #   object.expects(:method_1).with(all_of(includes(1), includes(3)))
    #   object.method_1([1, 2])
    #   # error raised, because method_1 was not called with object including 1 and 3
    def all_of(*matchers)
      AllOf.new(*matchers)
    end
    
    class AllOf < Base # :nodoc:
      
      def initialize(*matchers)
        @matchers = matchers
      end
    
      def matches?(available_parameters)
        parameter = available_parameters.shift
        @matchers.all? { |matcher| matcher.to_matcher.matches?([parameter]) }
      end
      
      def mocha_inspect
        "all_of(#{@matchers.map { |matcher| matcher.mocha_inspect }.join(", ") })"
      end
      
    end
    
  end
  
end

Version data entries

118 entries across 113 versions & 13 rubygems

Version Path
dradis-mediawiki-4.15.0 test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/all_of.rb
dradis-mediawiki-4.14.0 test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/all_of.rb
dradis-mediawiki-4.13.0 test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/all_of.rb
dradis-mediawiki-4.11.0 test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/all_of.rb
dradis-mediawiki-4.10.0 test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/all_of.rb
dradis-mediawiki-4.9.0 test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/all_of.rb
dradis-mediawiki-4.8.0 test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/all_of.rb
dradis-mediawiki-4.7.0 test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/all_of.rb
dradis-mediawiki-4.6.0 test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/all_of.rb
dradis-mediawiki-4.5.0 test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/all_of.rb
dradis-mediawiki-4.4.0 test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/all_of.rb
dradis-mediawiki-4.3.0 test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/all_of.rb
dradis-mediawiki-4.2.0 test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/all_of.rb
dradis-mediawiki-4.1.0 test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/all_of.rb
dradis-mediawiki-4.0.0 test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/all_of.rb
dradis-mediawiki-3.22.0 test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/all_of.rb
dradis-mediawiki-3.21.0 test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/all_of.rb
dradis-mediawiki-3.20.0 test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/all_of.rb
dradis-mediawiki-3.19.0 test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/all_of.rb
dradis-mediawiki-3.18.0 test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/all_of.rb