RSpec - use double test as block argument

I have a Ruby code that looks like this:

Something.create do |x|
    x.foo = bar
end 

I would like to write a test that uses double instead of the argument of the x block, so that I can then call:

x_double.should_receive(:foo).with("whatever").

Is it possible?

+5
source share
1 answer
 specify 'something' do
   x = double
   x.should_receive(:foo=).with("whatever")
   Something.should_receive(:create).and_yield(x)
   # call the relevant method
 end
+8
source

All Articles