[mocha-developer] Block trap

Dustin Tinney tinney at gmail.com
Sat May 3 11:31:04 EDT 2008


Sorry if this is a duplicate post.

I'm trying to test this the couldn't figure out if it was possible to  
trap the block that was being passed in:

def do_something(foo)
  Bar.transaction do
    foo.baz()
  end
end

I'd like my test to prove that foo.baz() is executed inside the  
block.  Normally I would have written something like this:

def test
   foo = mock("foo")	
   trapped_block = Bar.expects(:transaction).trap
   target.do_something(foo)

   foo.expects(:baz)
   trapped_block.execute()
end


More information about the mocha-developer mailing list