[rspec-users] [cucumber] accessing session variables

Matt Wynne matt at mattwynne.net
Sat Mar 14 16:29:40 EDT 2009

On 14 Mar 2009, at 19:11, Balint Erdi wrote:

> Hey Matt,
> Thanks a lot for your elaborated response!
> After reading this excellent thread about how to pass state between
> steps:
> http://www.mail-archive.com/rspec-users@rubyforge.org/msg06296.html
> I realized
> 1. I am not alone in this boat :)
> 2. that if I write "I go to", "my profile page" there is an implicit
> assumption -as you note below- that there is only one user so there is
> no harm in using this assumption in my steps. If there are several  
> users
> in a scenario then I have to explicitly name users ("when Alice goes  
> to
> her profile page", "when Bob presses the "Send" button, etc.)
> In both cases my steps remain reusable, in fact. What does not seem  
> nice
> to me -and what I wanted to evade- is to write this kind of feature:
> Scenario: Create album from scratch
>    Given I am logged in as "pepito"
>    When "pepito" goes to his photos page
>    And "pepito" follows "New album"
> It seems redundant. Once I know I am pepito in the feature I should  
> not
> have to define it in each step. It's like with spoken language.
> 3. using instance variables to pass state in the course of a features
> makes step definitions too coupled. (I have not experienced this but
> read it in the thread and it seems logical)

I think you have to be pragmatic about this. We have a @user variable  
in our steps that represents 'me' and that has worked OK for us. I  
think that's just about the only time we've had to use instance  
variables in 900 or so scenarios, but there are certainly times when  
it makes sense. You just have to be aware of the risks and not use  
them too cheaply.

Matt Wynne

More information about the rspec-users mailing list