Right now, #stub stubs a method even if it doesn't exist. Is there a
way to stub a method on an object, if and only if it already
#responds_to? that method? It would also be good if it raised an
ArgumentError or the like.

Example:

# this is how it works now:
#   - stubs the #bar method even if it doesn't exist
#   - always returns 'baz'
foo.stub(:bar).and_return('baz')

What I'd like is something like this:

# raise ArgumentError unless foo.respond_to? :bar
# otherwise, behaves as the regular #stub does
foo.stub!(:bar).and_return('baz')

Thoughts?

~ jf
--
John Feminella
Principal Consultant, BitsBuilder
LI: http://www.linkedin.com/in/johnxf
SO: http://stackoverflow.com/users/75170/
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to