[rspec-users] Stub an AR Model Instance Method

J. B. Rainsberger me at jbrains.ca
Sun Jun 19 08:55:02 EDT 2011

On Sat, Jun 18, 2011 at 21:10, Karl <threadhead at gmail.com> wrote:

> Found my problem... mostly due to my misunderstanding of mocks. Joe's
> suggestion above led me down the right path. This worked:
> @account = mock_model(Account)
> @account.stub!(:next_serial_number).and_return(43, nil)
> Widget.any_instance.stub(:account).and_return(@account)

I'm glad you found something that did what you wanted. Now what are
you trying to do with it? I've never wanted to stub
:next_serial_number before, so I'd like to understand the situation
you find yourself in, for when that happens to me.
J. B. (Joe) Rainsberger :: http://www.jbrains.ca ::
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