On Jul 27, 2011, at 2:32 PM, John Feminella wrote:
> 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?
This has come up many times before. Please check out
http://groups.google.com/group/rspec/browse_thread/thread/c344c898c278cd2b and
https://github.com/rspec/rspec-mocks/issues/15 to see where the conversation is
at this point.
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users