[rspec-users] Stub an AR Model Instance Method

Karl threadhead at gmail.com
Thu Jun 9 13:33:01 EDT 2011

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
@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

More information about the rspec-users mailing list