Topic: RSpec: calling original method from within a stub
I need to stub a method on a model instance that is going to be fetched by the code I'm speccing. I think I need something like this to implement it:
@original_object = ... #initialization code @original_object.save! MyModel.stub!(:find) do |*args| obj = yield(*args) if obj == @original_object obj.stub!(:my_method).and_return ... end obj end
Tho I ain't sure what yield does when called inside the block passed to stub! method. Any idea?
Or probably something like MyModel.any_instance.stub!(...) (like mocha's any_instance method) would work for me. But as far as I know rspec doesn't have similar functionality, and it is not going to ever appear there...
I'll appreciate any help with that.
Last edited by bluesman.alex (2010-09-16 04:08:36)