[rspec-users] mocking does not work

Hans de Graaff hans at degraaff.org
Thu Oct 30 03:02:45 EDT 2008

On Thu, 2008-10-30 at 14:47 +0800, Leon Du wrote:
> The spec
> --------------------------------------------------------------------------------------------------------------------------------------------------------
> it "should expose a newly created logo as @logo" do
>   Logo.should_receive(:new).with({'these' =>
> 'params'}).and_return(mock_logo(:save => true))
>   Logo.should_receive(:company=).with(mock_model(Company))
>   post :create, :logo => {:these => 'params'}
>   assigns(:logo).should equal(mock_logo)
> end

The instance of Logo should receive the company= method, not the class,

@logo = mock_logo

I would probably use stub! instead here and move this code into a before
block, and just keep the post and assigns lines in the it block.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081030/9d2168fe/attachment-0001.bin>

More information about the rspec-users mailing list