[rspec-users] Stubbing out method for all instances

aslak hellesoy aslak.hellesoy at gmail.com
Tue Mar 27 07:55:13 EDT 2007


On 3/27/07, David Smalley <david.smalley.lists at googlemail.com> wrote:
>
>
> On 27 Mar 2007, at 11:19, aslak hellesoy wrote:
>
>
>
>
>
> What's Test::Unit mocks?
>
> Ah sorry, by which I mean the
> /test/mocks/<env>/mocked_code.rb    setup in a default
> Rails skeleton - it lets you drop a replacement for a method that appears
> higher up in the search path and allows you to completely over-ride a
> method.
>

I see. Strictly speaking these are not mocks, but stubs.
http://www.martinfowler.com/articles/mocksArentStubs.html

Aslak

>
>
>
>
>
> and just replace the encoded? instance method for all objects that
>
> might use it to just return true.
>
>
>
>
> Any ideas?
>
>
>
>
>
>
>
> You can submit a feature request - ideally with a failing spec to
>
> illustrate what you want.
> After a bit of digging around it looks like David (Chelimsky) has already
> submitted such a feature request
>
> https://rubyforge.org/tracker/index.php?func=detail&aid=6791&group_id=797&atid=3152
> - looks a lot like what I want.
>
> Consider it similar to the syntax offered by mocha
>
> e.g.
> Order.any_instance.stubs(:shipped_on).returns(nil)
>
> I think it would be a very helpful addition to Rspec stub/mock framework -
> I'd be interested in helping to implement it but I fear I don't know enough
> about how mocking works. I'll dig into mocha and rspec code but if any of
> the Rspec developers want to take the lead that would be great!
>
> Cheers,
>
> David
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list