Permalink
Browse files

Add two-way conversation feature

  • Loading branch information...
1 parent 6c868db commit 8a8e8cc6dee3b8cefbacfdf507ea737a8d45bef2 @stevehodgkiss committed Apr 13, 2011
View
@@ -4,11 +4,25 @@ Feature: Chat
As a User
I want to have a conversation online
- Background: Signed in
- Given I am on the homepage
- And I have signed in as "Steve"
-
Scenario: Chatting to myself
+ Given I am signed in as "Steve"
When I fill in "Message" with "Hello?"
And I press "Send"
- Then I should see "Hello?" within the chat log
+ Then I should see "Hello?" within the chat log
+
+ Scenario: Two-way conversation
+ Given I have a browser with "Ashley" signed in
+ And I switch browsers to "Steve"
+ And I am signed in as "Steve"
+
+ When I say "Hello Ashley"
+
+ When I switch browsers to "Ashley"
+ Then I should see "Hi Ashley"
+ Then I should see "Hello Ashley"
+
+ When I say "Yo"
+ And I switch browsers to "Steve"
+
+ Then I should see "Steve"
+ Then I should see "Yo"
@@ -13,7 +13,7 @@ Feature: Identity
And I should see "Sign out"
Scenario: Sign out
- Given I have signed in as "Steve"
+ Given I am signed in as "Steve"
When I follow "Sign out"
Then I should see "Sign in"
And I should not see "Steve"
@@ -0,0 +1,4 @@
+When /^I say "([^"]*)"$/ do |message|
+ fill_in "Message", :with => message
+ click_button "Send"
+end
@@ -1,4 +1,5 @@
-Given /^I have signed in as "([^"]*)"$/ do |name|
+Given /^I am signed in as "([^"]*)"$/ do |name|
+ visit "/sign_in"
fill_in "Name", :with => name
click_button "Go"
end
@@ -0,0 +1,8 @@
+Given /^I have a browser with "([^"]*)" signed in$/ do |name|
+ switch_session(name)
+ And %{I am signed in as "#{name}"}
+end
+
+When /^I switch browsers to "([^"]*)"$/ do |name|
+ switch_session(name)
+end
@@ -0,0 +1,28 @@
+# Author: Eric Pierce
+# http://www.automation-excellence.com/blog/racking-my-brains
+module Capybara
+ module Driver
+ module Sessions
+ def set_session(id)
+ Capybara.instance_variable_set('@session_pool', {
+ "#{Capybara.current_driver}#{Capybara.app.object_id}" => $sessions[id]
+ })
+ end
+
+ def switch_session(id)
+ $sessions ||= {}
+ $sessions[:default] ||= Capybara.current_session
+ $sessions[id] ||= Capybara::Session.new(Capybara.current_driver, Capybara.app)
+ set_session(id)
+ end
+
+ def in_session(id, &block)
+ switch_session(id)
+ yield
+ set_session(:default)
+ end
+ end
+ end
+end
+
+World(Capybara::Driver::Sessions)

0 comments on commit 8a8e8cc

Please sign in to comment.