[rspec-users] any_instance

Matt Mower self at mattmower.com
Thu Jun 5 06:07:55 EDT 2008

HI Scott.

On Thu, Jun 5, 2008 at 3:05 AM, Scott Taylor
<mailing_lists at railsnewbie.com> wrote:
> There's a general idea with rspec (and one which probably isn't present in
> other testing frameworks) that says that testing *should* influence your
> design.  I'm sure this is one of the reasons that David considers it an
> "anti-pattern" - as it does not influence your design in any way.  In fact,
> I developed the the stub_any_instance patch because I needed to test legacy
> code (legacy because it wasn't designed well), and it was the only way to
> get to the object.

I guess that's how I see this. My code, that I am writing specs for,
depends upon a lower-level library that does not expose the details of
it's implementation to it's clients.

The use of any_instance allows me to test my code simply. Without it I
seem to be forced to build complex arrangements of mocks to,
essentially, emulate the behaviour of the underlying library. This
feels like busy work.

Whilst it would be possible to re-write the underlying library I do
not feel that's a worthwhile investment of my time right now.
Especially not when I have a spec suite that already works but for the
lack of any_instance.

I'm all for encouraging good practice and wrapping any_instance in the
shame of your peers. But I'm also all for being pragmatic. Does your
patch work? I wasn't clear whether David was saying that it doesn't.



Matt Mower :: http://matt.blogs.it/

More information about the rspec-users mailing list