[rspec-users] mocking errors
s.ross
cwdinfo at gmail.com
Sun Jun 24 12:34:23 EDT 2007
I'm doing this and overriding the last line if I want errors, but
yours should also work if you want a message. Dunno if mine is more
or less "correct".
@thing = mock_model(Thing, :title => 'my mock title')
@thing.should_receive(:errors).any_number_of_times.and_return
(@errors)
@errors = mock('errors')
@errors.should_receive(:size).any_number_of_times.and_return(0)
On Jun 24, 2007, at 6:22 AM, David Smalley wrote:
> What is the correct way to mock out the errors on a Rails model?
>
> I'm assuming i need to say
>
> @mock_thing = mock_model(Thing)
> @mock_thing_errors = mock("errors")
> @mock_thing_errors.should_receive(:full_messages).and_return("An
> error")
> @mock_thing.should_receive(:errors).and_return(@mock_thing_errors)
>
> Just wanted to check the best practice on this kind of thing and how
> other people handle it.
>
> Cheers,
>
> David
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
Steve Ross
sross at calicowebdev.com
http://www.calicowebdev.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070624/3274243c/attachment.html
More information about the rspec-users
mailing list