[rspec-users] Rspecing this simple controller it is driving me mad...

Jarkko Laine jarkko at jlaine.net
Sun Apr 13 13:01:27 EDT 2008


On 12.4.2008, at 14.06, roberto belardo wrote:

> Uhm ok, i understood your answer but autotest did not.
> Better, this do not solves the problem.
> If i simply remove the "stub" and the "should_receive"
> for the author field, autotest will complain like
> this:
>
> Spec::Mocks::MockExpectationError in
> 'CommentsController handling POST /comments should
> create a new comment'
> Mock 'Comment_1008' received unexpected message
> :author= with (#<User:0x..fdb98f624
> @name="User_1006">)
>
> and this was the reason why i put the "should_receive"
> and the "stub" on "author=" method, as someone told
> previously on this ml.
> :(
>
> Is there someone who knows how to spec this? Help
> needed.

Two ways:

1) either use Comment.new instead of mock_model(Comment) in your  
before block. This way your comment object has the ability to assign  
its author.
2) Use the mock model and your should_receive test. However, after  
that you cannot test that @comment.author.should be(@user) because you  
have stubbed author= and it doesn't really do anything. So you just  
have to rely on that it works (like you should since it's Rails code  
which you shouldn't really be testing).

//jarkko

--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2417 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/rspec-users/attachments/20080413/80699141/attachment-0001.bin 


More information about the rspec-users mailing list