Sha256: ce2ebdd380576ba5b8a68eb3f71d2593d8ffff6c1a97ef04817aa6c4fec5634e

Contents?: true

Size: 1.2 KB

Versions: 16

Compression:

Stored size: 1.2 KB

Contents

# encoding: utf-8

# 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)
    @expected_parameters = [Mocha::ParameterMatchers::AnyParameters.new]
    @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

Version data entries

16 entries across 16 versions & 3 rubygems

Version Path
prawn-git-2.0.1 spec/extensions/mocha.rb
prawn-table-0.2.2 spec/extensions/mocha.rb
prawn-2.0.1 spec/extensions/mocha.rb
prawn-2.0.0 spec/extensions/mocha.rb
prawn-table-0.2.1 spec/extensions/mocha.rb
prawn-table-0.2.0 spec/extensions/mocha.rb
prawn-1.3.0 spec/extensions/mocha.rb
prawn-table-0.1.2 spec/extensions/mocha.rb
prawn-table-0.1.1 spec/extensions/mocha.rb
prawn-table-0.1.0 spec/extensions/mocha.rb
prawn-1.2.1 spec/extensions/mocha.rb
prawn-table-0.0.4 spec/extensions/mocha.rb
prawn-table-0.0.3 spec/extensions/mocha.rb
prawn-table-0.0.2 spec/extensions/mocha.rb
prawn-table-0.0.1 spec/extensions/mocha.rb
prawn-1.1.0 spec/extensions/mocha.rb