[Rspec-devel] What is a context?

Jay Levitt lists-rspec at shopwatch.org
Sun Jul 16 09:48:43 EDT 2006

David Chelimsky wrote:

> context and specify work well for class level use cases, but It does
> occur to me that there is room for some other structures for higher
> level specs that a customer might understand. Maybe context and
> specify are enough. Thoughts?

I've been wondering about this while writing rails specs.  For my model, 
I end up with specs like

An otherwise valid receipt
- should start out valid
- should disallow an empty vendor field
- should disallow future purchases
- should allow an empty image

So, as you say, that maps well.  But when I get into the controller 
specs, they start looking funnier:

The ReceiptController
- should be a ReceiptController

To create a receipt,
- get the new receipt form
- post a good receipt
- post a bad receipt

Elsewhere in the receipts controller,
- check the receipts list

Some of the specs are more like task-lists.  Many of the actual specs 
are now buried down at the should-be level, where they aren't seen in 
the specdoc.  I can't push them up to the specification level, or else I 
end up with specs depending on other specs - and each spec is executed 
in a fully-rolled-back context with transactional fixtures, so that 
doesn't work.

The simplest solution would be to allow the "shoulds" to optionally 
appear in the specdoc.  I'm not sure what a more complex solution would 
look like.


> _______________________________________________
> Rspec-devel mailing list
> Rspec-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-devel

More information about the Rspec-devel mailing list