[Rspec-devel] What is a context?

David Chelimsky dchelimsky at gmail.com
Sun Jul 16 14:02:17 EDT 2006

On 7/16/06, Jay Levitt <lists-rspec at shopwatch.org> wrote:
> 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"

Glad you like this. I think story is higher level - a story contains
several scenarios (each of which might be in a different context, so
it's not a direct hierarchical mapping).

> > 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.

I'd really like to avoid rollback and go straight for "tomorrow". The
term rollback brings all sorts of implications that I'd rather avoid,
for one. The other thing is that I don't want to start gumming up the
DSL with attributes like that - especially if it's only temporary!

> 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.


It's a bit too easy to make that joke, and I've fallen into the same
trap many times before.

> 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.

That's what it's there for. Glad it's proving helpful as intended!

Thanks Jay,

More information about the Rspec-devel mailing list