[rspec-users] stub calls to an instance method before it is created?

Shane Wolf shane.wolf at zvents.com
Fri Nov 2 02:36:02 EDT 2007

I am desperately in need of functionality such as Mocha offers with their
any_instance method.  I see that there is an open ticket for a similar
feature in RSpec, but it does not look like anything have been done. Is
there any other way around this?


Here is what I am doing, and why I feel I need this (maybe my design is
inherently wrong)

Given a model called Foo

def Foo.create_from_form
  foo = Foo.new
  # Do all kinds of crazy stuff here

In my specs I want to stub the foo.save call to return true or false
depending on the case, so that it doesn't actually try and save to the DB...
is there any way around this since I do not actually know the instance of
the class I am trying to stub?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071101/91a75ce4/attachment.html 

More information about the rspec-users mailing list