title: Keeping a track of sessions in Ruby and Capybara
body: <p>I am using the <code>parallel_tests</code> gem to be able to run multiple features at the same time, the problem I face with my scenario is that I have user based sessions (SSO) so only one user can be logged in at a time.</p>
  
  <p>To combat this I was thinking of being able to randomly select users if they are available, but tracking their <code>login</code> status globally presents an issue for me.</p>
  
  <h2>My setup</h2>
  
  <p>Before and after each scenario a user will login:</p>
  
  <pre><code>Before('@login_automated_user') do
    @user = FactoryGirl.attributes_for(:automated_user)
   login_steps("#{APP}")
  end
  
  After('@login_automated_user') do
   logout_steps
  end
  </code></pre>
  
  <p>I was thinking of having a pool of users in an array and randomly selecting one to use and once finished return the user to the pool:</p>
  
  <pre><code>module UserSession
    def choose_user
      user_array = factory_girl_users.values
      if user_array.length &gt; 0
       @user = user_array.pop
     end
    end
  
     def return_user
       user_array &lt;&lt; @user
     end
  
    def factory_girl_users
      Hash[:user_1 =&gt; FactoryGirl.attributes_for(:automated_user), :user_2 =&gt; FactoryGirl.attributes_for(:automated_user_1)]
   end
  end
  World(UserSession)
  </code></pre>
  
  <p>This would then make my Before and After hooks look like:</p>
  
  <pre><code>Before('@login_automated_user') do
   @user = choose_user
   login_steps("#{APP}")
  end
  
  After('@login_automated_user') do
   logout_steps
   return_user
  end
  </code></pre>
  
  <p>One issue I can see here is I'm using <code>@user</code> across two sessions (or more if I had more users) so do I need to separate them out?</p>
  
  <p>Would anyone offer some tips/solutions to contemplate please?</p>