5

私は次のようなRubyコードを持っています:

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

ブロック引数xの代わりにdoubleを使用するテストを作成したいので、次のように呼び出すことができます。

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

これは可能ですか?

4

1 に答える 1

8
 specify 'something' do
   x = double
   x.should_receive(:foo=).with("whatever")
   Something.should_receive(:create).and_yield(x)
   # call the relevant method
 end
于 2012-09-28T14:20:10.933 に答える