File: mocha.rb

package info (click to toggle)
ruby-prawn 1.0.0~rc1%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,248 kB
  • sloc: ruby: 17,499; sh: 44; makefile: 17
file content (43 lines) | stat: -rw-r--r-- 1,133 bytes parent folder | download
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
# Allow speccing things when an expectation matcher runs. Similar to #with, but
# always succeeds.
#
#   @pdf.expects(:stroke_line).checking do |from, to|
#     @pdf.map_to_absolute(from).should == [0, 0]
#   end
#
# Note that the outer expectation does *not* fail only because the inner one
# does; in the above example, the outer expectation would only fail if
# stroke_line were not called.

class ParameterChecker < Mocha::ParametersMatcher
  def initialize(&matching_block)
    @matching_block = matching_block
  end

  def match?(actual_parameters = [])
    @matching_block.call(*actual_parameters)

    true # always succeed
  end
end

class Mocha::Expectation
  def checking(&block)
    @parameters_matcher = ParameterChecker.new(&block)
    self
  end
end


# Equivalent to expects(method_name).at_least(0). More useful when combined
# with parameter matchers to ignore certain calls for the sake of parameter
# matching.
#
#   @pdf.ignores(:stroke_color=).with("000000")
#   @pdf.expects(:stroke_color=).with("ff0000")
#
module Mocha::ObjectMethods
  def ignores(method_name)
    expects(method_name).at_least(0)
  end
end