[rspec-users] Are you writing "imperative" or "declarative" scenarios in your stories?

Kyle Hargraves philodespotos at gmail.com
Sun May 11 18:05:04 EDT 2008


On Sun, May 11, 2008 at 4:01 PM, Ben Mabey <ben at benmabey.com> wrote:
> I'm curious what everyone else on this list has been doing in this regard.
>  Are you writing declarative scenarios all the time?  Or are you reusing a
> lot of your steps with detailed scenarios?  A little bit of both maybe?  If
> so, how do you decide which type of scenario to use in a given case?  Any
> other thoughts on this matter?

When I first started writing stories for rails apps, I primarily used
the declarative form, just because they were easier to implement and
reusing steps was generally difficult anyhow. It was just the natural
style that I'd hit upon when writing them for small projects I used to
play with rbehave / the story runner.

Once webrat came about, I moved toward the imperative form, with a lot
of steps that were just english forms of the webrat helpers ("When I
click the link ...", "When I select Foo from the Bar menu", etc). This
was really nice, since I was able to write a number of scenarios
almost entirely without implementing any steps. Mix in some
GivenScenario and you could get fairly detailed paths through the
application with minimal effort.

But then, I'd come back to a story and have to, god forbid, think
about what the meaning was. The story description and scenario name
will hint at it, but the meat was tough to pick out of the steps. Too
many times, I'd had to sit down with a coworker while we figured out,
"why did we write this?"

So for the past few months I've come full circle, and I prefer short,
high-level scenarios that describe the *feature*, not the particular
way it might be performed within the current interface. I don't get to
reuse steps as often, but with a few helper methods mixed into
Spec::Story::World, it hasn't been an issue. The scenarios themselves
are terse and get right to the point.

It has made a *big* difference in how useful my stories are as
documentation, and maintenance is significantly easier when the UI is
tweaked. It hasn't really affected my level of confidence in them
serving as tests -- it either fails or it doesn't -- but the other
wins have been worth it.

That said, some of my scenarios, especially when first tinkering on a
new feature, still read like a howto manual for a web browser. "Click
this button", "Type XYZ in this field", etc. One or two of those don't
bother me, but I move on to more abstract language -- Bryan's "When I
add Zed Shaw" -- once it's solid enough to elide the details.
Sometimes I go back and edit the initial scenarios, sometimes I don't.

Kyle


More information about the rspec-users mailing list