File: any_parameters.rb

package info (click to toggle)
ruby-mocha 1.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,400 kB
  • ctags: 2,016
  • sloc: ruby: 10,921; makefile: 12
file content (47 lines) | stat: -rw-r--r-- 1,045 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require 'mocha/parameter_matchers/base'

module Mocha

  module ParameterMatchers

    # Matches any parameters. This is used as the default for a newly built expectation.
    #
    # @return [AnyParameters] parameter matcher.
    #
    # @see Expectation#with
    #
    # @example Any parameters will match.
    #   object = mock()
    #   object.expects(:method_1).with(any_parameters)
    #   object.method_1(1, 2, 3, 4)
    #   # no error raised
    #
    #   object = mock()
    #   object.expects(:method_1).with(any_parameters)
    #   object.method_1(5, 6, 7, 8, 9, 0)
    #   # no error raised
    def any_parameters
      AnyParameters.new
    end

    # Parameter matcher which always matches whatever the parameters.
    class AnyParameters < Base

      # @private
      def matches?(available_parameters)
        while available_parameters.length > 0 do
          available_parameters.shift
        end
        return true
      end

      # @private
      def mocha_inspect
        "any_parameters"
      end

    end

  end

end