Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rspec yield block, but call original

So I have the following:

foo.each do |f|
  f.begin
    do_stuff
    do_more_stuff
  end
end

And I mock the f object with an and_yield() call. I want to be able to test the begin method by passing it the original block { do_stuff do_more_stuff }, not a mock implementation.... I cant just let the begin method be called on the mock without at least stubbing it, so what do I do?

like image 358
Nicholas Terry Avatar asked Oct 14 '14 17:10

Nicholas Terry


1 Answers

Again, an undocumented feature that i found:

allow(thing).to receive(:foo) do |_, &block|
  block.call
end

le sigh....

like image 177
Nicholas Terry Avatar answered Nov 15 '22 02:11

Nicholas Terry