Project

mock_proc

0.0
No commit activity in last 3 years
No release in over 3 years
An object that looks like a proc that can be used to verify a block was called (elegantly, of course).
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
>= 0
~> 2.10.0
 Project Readme

MockProc

Build Status

An attempt to create a mock Proc object, so expectations can be set on how it is called.

Ideal for testing callbacks; alternatives are discussed in Avdi's blog post.

mock_proc is meant to plug into other mocking libraries. Right now it supports rspec-mocks.

rspec-mocks

describe MockProc do
  it "expects an exact number of calls" do
    block = MockProc.new
    block.should_be_called.twice

    2.times { block.call }
  end
end

You can use all of the same predicates you expect:

describe MockProc do
  it "expects arguments" do
    block = MockProc.new
    block.should_be_called.with(:foo)

    block.call(:foo)
  end
end

It works any way you invoke the block:

describe MockProc do
  it "allows all methods that invoke a block" do
    block = MockProc.new
    block.should_be_called.exactly(2).times

    block[:foo]
    block === :foo
  end
end

TODO

  • Other mocking frameworks: mocha, ...?