[rspec-users] any_instance

David Chelimsky dchelimsky at gmail.com
Thu Jun 5 07:21:39 EDT 2008

On Jun 4, 2008, at 9:05 PM, Scott Taylor 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.

This isn't really a framework issue - it's about TDD. Remember that  
BDD started off as another way of framing TDD - it's roots are still  
in TDD.

As you've read before, TDD is a design practice, not a testing  
practice. There is a testing benefit we get out of it, but the great  
benefit of writing tests first is that you start off thinking from a  
client's perspective. This and the fact that you're adding small bits  
at a time, doing the simplest thing that could possibly work,  
generally leads to more highly decoupled nuggets of code than back- 
filling tests.

> 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'm sure David would have specific examples, and I'd be curious to  
> see them.

any_instance is a global concept. Any time you're doing something  
global in an executable example you're making it harder for yourself  
to understand failures later.

I guess that it's a bit more harmless with stubs, so, as I said, I'm  
still open to adding a patch. I'm just not going to make it myself as  
it's low priority for me.


More information about the rspec-users mailing list