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

David Chelimsky dchelimsky at gmail.com
Thu Feb 22 12:05:54 EST 2007

On 2/22/07, Ashley Moran <work at ashleymoran.me.uk> wrote:
> 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.

My only bit of unsolicited advice w/ this is that you keep reminding
yourself that specs are not the same as production code. Eliminating
duplication is helpful, but it's equally (if not more) important that
you don't have to debug your specs (i.e. trace paths through several
files, etc). Everything you need to know for a given spec should be
right in front of you.

Hope that is helpful.


> Ashley
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list