我有一些Ruby代码,如下所示:
Something.create do |x|
x.foo = bar
end
Run Code Online (Sandbox Code Playgroud)
我想编写一个使用double代替块参数x的测试,以便我可以调用:
x_double.should_receive(:foo).with("whatever").
Run Code Online (Sandbox Code Playgroud)
这可能吗?
specify 'something' do
x = double
x.should_receive(:foo=).with("whatever")
Something.should_receive(:create).and_yield(x)
# call the relevant method
end
Run Code Online (Sandbox Code Playgroud)