[rspec-users] stubbing gets undone?

Fearless Fool lists at ruby-forum.com
Wed Feb 16 00:54:43 EST 2011

I'm looking at an example where a stub seems to work sometimes, and
sometimes appears to become "unstubbed".  I haven't boiled it down to a
minimal example, but it goes something like this:
---- the model:
class Premise << ActiveRecord::Base
  def lookup_stuff_on_the_web
    $stderr.puts("entering lookup_stuff_on_the_web with #{self}")
---- the rspec test file:
describe Analysis do
  before(:each) do
    @premise = Factory(:premise)
    $stderr.puts("just stubbed #{@premise.inspect}")

  it "should not hit the web" do
    @premise.lookup_things_on_the_web.should_not raise_exception
When I run the test, I see:

just stubbed #<Premise id: 1, user_id: 1, ...>
entering lookup_stuff_on_the_web with #<Premise id: 1, user_id: 1, ...>
Failure/Error: ...

As far as I can see, the Premise that's being stubbed and the Premise
whose lookup_stuff_on_the_web method is getting called are one and the
same.  What I can't figure out is why the stub isn't being honored.
(FWIW, the same setup code is working in other tests.)

Are there any known gotchas I should be looking for?  Or specific things
I should try to uncover the cause?


- ff

Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list