# Testing multiple sessions in cucumber/webrat

**URL:** <https://www.ruby-forum.com/t/testing-multiple-sessions-in-cucumber-webrat/161673>\
**Category:** RSpec\
**Created:** [February 28, 2009, 9:16pm UTC](https://www.ruby-forum.com/t/testing-multiple-sessions-in-cucumber-webrat/161673 "2009-02-28T21:16:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [February 28, 2009, 9:16pm UTC](https://www.ruby-forum.com/t/testing-multiple-sessions-in-cucumber-webrat/161673/1 "2009-02-28T21:16:54Z")

</div>

Is it possible to have a scenario where you are testing the  
interaction between two different session?

i.e.

Given User A clicks this link  
Then User B should see this

It used to be possible, but don’t know if it still is.

Joe

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [March 1, 2009, 2:19am UTC](https://www.ruby-forum.com/t/testing-multiple-sessions-in-cucumber-webrat/161673/2 "2009-03-01T02:19:34Z")

</div>

Joe,I would test this in 2 steps.  
I’d first test that whatever state change (or whatever happens when you  
User  
A clicks the link) takes place.  
Then in another test, I’d check that, given a certain state (or again,  
whatever is supposed to happen), then User B sees whatever.

HTH,  
BJ Clark

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [March 2, 2009, 2:18am UTC](https://www.ruby-forum.com/t/testing-multiple-sessions-in-cucumber-webrat/161673/3 "2009-03-02T02:18:51Z")

</div>

So you’re saying no? 😃

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [March 2, 2009, 3:33am UTC](https://www.ruby-forum.com/t/testing-multiple-sessions-in-cucumber-webrat/161673/4 "2009-03-02T03:33:37Z")

</div>

On Sun, Mar 1, 2009 at 8:04 PM, Joe Van D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> So you’re saying no? 😃

It is possible, you simply have to logout from UserA and log in as  
UserB. Also, although it’s not exposed with webrat IIRC it is possible  
to have selenium run to separate browsers at the same time. You could  
theoretically have UserA and UserB logged in concurrently doing their  
thing,

Zach

> > > It used to be possible, but don’t know if it still is.  
> > > [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > > [http://rubyforge.org/mailman/listinfo/rspec-users](http://rubyforge.org/mailman/listinfo/rspec-users)
> 
> * * *
> 
> rspec-users mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [http://rubyforge.org/mailman/listinfo/rspec-users](http://rubyforge.org/mailman/listinfo/rspec-users)

–  
Zach D.  
[http://www.continuousthinking.com](http://www.continuousthinking.com)

> **[Homepage | Mutually Human](https://www.mutuallyhuman.com)**
>
> We empower businesses to overcome challenges with a holistic focus on People, Process, and Technology for lasting results and innovation.

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [March 2, 2009, 3:17pm UTC](https://www.ruby-forum.com/t/testing-multiple-sessions-in-cucumber-webrat/161673/5 "2009-03-02T15:17:24Z")

</div>

On 28-feb-2009, at 21:04, Joe Van D. wrote:

> Is it possible to have a scenario where you are testing the  
> interaction between two different session?

If you mean something along these lines:

User A uploads a picture,  
User B logs in to see the picture uploaded by User A

that is possible.

I use this construct a lot to test-drive some revisions code I came  
up with. Something like:

Given I am logged in  
And there is an article  
And the title of the article has been modified twice  
When I compare the revisions  
Then I should see the difference in title

GIven “the title of the article has been modified twice” do  
Given “I am logged in as an editor”

2.times do |i|  
visit edit\_article\_path(@article)  
fill\_in “Title”, :with =\> “Title #{i}”  
click\_button “Save”  
end

Given “I am logged in as a writer”  
end

cheers,  
bartz

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [March 2, 2009, 4:48am UTC](https://www.ruby-forum.com/t/testing-multiple-sessions-in-cucumber-webrat/161673/6 "2009-03-02T04:48:27Z")

</div>

Joe Van D. wrote:

> Joe
> 
> * * *
> 
> rspec-users mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [http://rubyforge.org/mailman/listinfo/rspec-users](http://rubyforge.org/mailman/listinfo/rspec-users)

Have you tried creating a new webrat session? I haven’t looked into it  
myself, but like you said it was possible. Not much has changed with  
the underling rails integration session so I imagine that if you just  
created a new webrat session and used that for user B then you should be  
fine. (So, you will have to store this second session as an instance  
var in the other session.. kinda odd but I would try it.) I would be  
interested to hear if this works, so please report back. BTW, you might  
get some better answers on the webrat mailing list.

-Ben

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [April 22, 2009, 10:50pm UTC](https://www.ruby-forum.com/t/testing-multiple-sessions-in-cucumber-webrat/161673/7 "2009-04-22T22:50:27Z")

</div>

Joe Van D. wrote:

> Is it possible to have a scenario where you are testing the  
> interaction between two different session?

Not sure if this is exactly what you need, but I found this technique to  
be very handy:

[http://erikonrails.snowedin.net/?p=159](http://erikonrails.snowedin.net/?p=159)

It involves mixing in a method to ActionController::Integration::Session  
so that you can create a step definition that happens “outside” the  
current session:

module ActionController  
module Integration  
class Session  
def in\_a\_separate\_session  
old = @response.clone  
yield  
@response = old  
end  
end  
end  
end

Here’s a sample usage from his page:

Then /^I should be logged in$/ do  
in\_a\_separate\_session do  
Given “I visit /users/me”  
Then “I should see "You are logged in"”  
end  
end
