search for: mock_receipt

Displaying 1 result from an estimated 1 matches for "mock_receipt".

2007 Apr 20
7
Stubbing Model.new w/ block?
...y model code creates a receipt object and sets some values on it: @receipt = Receipt.new do |r| r.x = 1 r.y = 2 # etc end I wanted to be able to stub out Receipt.new so that I could set expectations on the methods called on the resulting Receipt object. If in my test setup I do: @receipt = mock_receipt Receipt.stub!(:new).and_return(@receipt) The block part of the code will never be called. If I do: Receipt.stub!(:new).and_yield(@receipt) Then @receipt in my model will be set to the return value of the block. I also tried something along the lines of: Receipt.stub!(:new) do yield @receipt...