[Rspec-devel] What is a context?

Jay Levitt lists-rspec at shopwatch.org
Sun Jul 16 13:55:00 EDT 2006


David Chelimsky wrote:

> That said, this is something that could be very useful for scenario
> testing. I think I'd rather come up w/ a different structure - one
> that more explicit in stating that we're dealing w/ a sequence of
> events. Something like this:
> 
> context "new session" do
>   setup do
>   end
>   scenario "new user registration" do
>     step "user navigates to registration page" do
>     end
>     step "user submits registration form" do
>     end
>   end
> end

I like that a LOT.  I wonder if it should be called "story" - is that a 
more common term for BDD? - but either one sounds good, actually.  I 
especially like calling them "steps".

> The problem I see is how this maps to expectations and how we print
> out the documentation. 

Howbout this:

Today, a context calls setup, teardown, and rollback.  Tomorrow, a 
context calls setup and teardown, but a scenario calls rollback.  A step 
is just a synonym for a specification.  A context has an anonymous 
scenario by default, so that if we hit a spec with no explicit scenario, 
rollback still works the way it does today.

Mind you, I have yet to get brave enough to look at RSpec's internals, 
and I'm still a Ruby novice, so that might make no sense in this.. 
well... context.


As important as it is to have clear and DRY
> ways to express different levels of specs, it is every bit as
> important that the resulting docs are clear as well.

Oh, I agree.  That's the thing that attracted me to rspec in the first 
place, even though I'm the only one I'm printing specdocs for.  It shows 
me how far I've got in the design.

Jay



More information about the Rspec-devel mailing list