On Tue, Sep 8, 2009 at 2:53 PM, Philippe Creux<[email protected]> 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
> [email protected]
> http://rubyforge.org/mailman/listinfo/rspec-users
>
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to