Philippe Creux
2009-Sep-08 19:53 UTC
[rspec-users] Issue with the "class" method of a mocked model
Hi everybody,
I run into an issue with the "class" method of a mocked model. The
following
expectation fails:
@user = mock_model(Author)
is_author(user).should == true
def is_author(user)
case user
when Author
return true
else
return false
end
end
However, it works well when running the app. I guess that the problem comes
from the mock as it compares the mocked-model.class with the
real-model.class. Do you have any idea to fix that?
For now, I use "Author.class.to_s" but I don''t like to make
my code ugly for
the mock to work. :)
Cheers,
?
http://pcreux.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/rspec-users/attachments/20090908/fc0f5394/attachment.html>
David Chelimsky
2009-Sep-08 21:50 UTC
[rspec-users] Issue with the "class" method of a mocked model
On Tue, Sep 8, 2009 at 2:53 PM, Philippe Creux<pcreux at gmail.com> wrote:> Hi everybody, > > I run into an issue with the "class" method of a mocked model. The following > expectation fails: > > @user = mock_model(Author) > is_author(user).should == true > > def is_author(user) > ? case user > ??? when Author > ????? return true > ? else > ??? return false > ? end > end > > However, it works well when running the app. I guess that the problem comes > from the mock as it compares the mocked-model.class with the > real-model.class. Do you have any idea to fix that?First, don''t use mock_model. It is an RSpec mock object, not an Author. You can either use a real Author, or stub_model(Author), which is actually an Author, but decorated with some additional stub-friendly behaviour. HTH, David> > For now, I use "Author.class.to_s" but I don''t like to make my code ugly for > the mock to work. :) > > Cheers, > > ? > http://pcreux.com > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >