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

Sam Stokes lists at ruby-forum.com
Mon Sep 8 11:44:55 EDT 2008

Zach Dennis wrote:
> This thread may help give you some insight...
> http://www.mail-archive.com/rspec-users@rubyforge.org/msg05382.html

Thanks for pointing me there.  The first insight it's given me is that 
I'm actually asking two different (though related) questions:
1) What's the best way to build reusable steps, and is it a good idea?
2) What's the best way to share state between the steps in a single 

That thread addresses 1) directly, and sounds like there's some evidence 
that reusable steps aren't such a good idea.  In which case 2) pretty 
much drops out - if I don't try so hard to reuse my steps then there are 
fewer disadvantages to the obvious global @variable tactic.

If you take the view that reusable steps may be unhelpful, what do you 
find is a good way to organise them?  I can see an extreme case - each 
plain-text foo.story gets its own steps defined in foo.rb, so there are 
no cross-file @variable conventions to worry about.  In this way foo.rb 
is basically a clarification in code of foo.story, rather than part of 
an app-specific language (ASL?) for integration testing.  Does anyone do 
this, and do they find it a useful way of looking at the problem?
Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list