[rspec-users] Best practices for sharing state between story steps?

Sam Stokes lists at ruby-forum.com
Mon Sep 8 12:17:42 EDT 2008


Jonathan Linowes wrote:
> I make some limited use of global (instance) variables that
> correspond to english language pronouns. I have things like
> @current_user (corresponds to "I"), @current_project (corresponds to
> "the project"), etc. I am careful to be consistent. There's only a
> handful of these, but I find it extremely convenient. Note, these
> also tend correspond to 'states' in my app, which might be in the
> session or part of a nested URL.

So could I summarise this approach as, "use @variables, with good names 
and consistent principles for use"?

One problem I've had is that some steps implicitly have to be preceded 
by other steps, so that the @variables get set up right (e.g. "Given 
some comments" refers to @post, which has to be set beforehand by "Given 
a post").  I can make the wording of the steps more explicit, but then I 
end up with clunky steps like "Given some existing comments by the user 
for the post".

Generally I've found with this sort of approach I end up writing fairly 
imperative-style scenarios (as in 
http://www.benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories/), 
and they're quite brittle with respect to small changes to steps.

Do you encounter these problems at all?
-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list