Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mock methods that receives a block as parameter

I have a scenario more or less like this

class A
  def initialize(&block)
    b = B.new(&block)
  end
end

I am unit testing class A and I want to know if B#new is receiving the block passed to A#new. I am using Mocha as mock framework.

Is it possible?

like image 637
rafaelss Avatar asked Jul 15 '10 02:07

rafaelss


1 Answers

I think you want:

l = lambda {}
B.expects(:new).with(l)
A.new(&l)

I know this works with RSpec, I'd be surprised if Mocha doesn't handle

like image 164
Bryan Ash Avatar answered Oct 20 '22 14:10

Bryan Ash