[rspec-users] Stub an AR Model Instance Method

J. B. Rainsberger me at jbrains.ca
Sat Jun 11 21:08:57 EDT 2011


On Thu, Jun 9, 2011 at 14:33, Karl <threadhead at gmail.com> wrote:
> Obviously, I'm missing something very simple, can someone please
> explain how to stub an instance of an AR model method.
>
> This does not work:
> @widget = Widget.first # Widget has an instance method called
> 'next_seriel_number'
> @widget.stub(:next_serial_number).and_return(43, nil)
>
> I know I could use 'any_instance', and that does work, expect that I
> need to return multiple values. And 'any_instance' does not work with
> returning multiple values.
>
> This does not work:
> Widget.any_instance.stub(:next_serial_number).and_return(43, nil) #
> only returns 43

Google "rspec mock_model" and off you go. Good luck.
-- 
J. B. (Joe) Rainsberger :: http://www.jbrains.ca ::
http://blog.thecodewhisperer.com
Diaspar Software Services :: http://www.diasparsoftware.com
Author, JUnit Recipes
2005 Gordon Pask Award for contribution to Agile practice :: Agile
2010: Learn. Practice. Explore.


More information about the rspec-users mailing list