[rspec-users] How to spec code with multiple (interacting) paths

Ashley Moran work at ashleymoran.me.uk
Thu Feb 22 10:54:05 EST 2007


On 20 Feb 2007, at 16:57, David Chelimsky wrote:

> AND watch it fail. That is key!!!!!! The cycle (from TDD) is:
>
> 1. write a failing spec

Oh I've been caught out by writing incorrectly passing specs because  
I didn't run them before I wrote the code.  It happened today to the  
guy I'm working with on some RJS code.

> 2. make it pass with the simplest thing that could possibly work
> 3. refactor to eliminate duplication
>
> Note that "duplication" here refers to duplication either in the
> subject code or between the spec and the subject code. IMO, some
> duplication is OK in specs.
>
> As to Ashley's initial post, I agree with Jerry in that the first
> thing I'd look to do is see how I could break up some of these
> responsibilities. FWIW, whenever I find that something is hard to
> spec/test, I look at that as a design problem. But sometimes the
> simplest thing that could possibly work isn't all that simple and you
> have to find trade-offs between complexity in the system and
> complexity in the specs.

I suspect I'm getting far too much duplication in specs.  I'm forced  
to generate contexts in a loop, or copy-and-paste whole contexts far  
too often.  I'll try and modularise some of the application logic in  
my  controllers and see if it sorts itself out.

I never thought before about refactoring to eliminate duplication in  
specs, but it makes sense really.

Ashley


More information about the rspec-users mailing list