Skip to content

Commit

Permalink
Add two-way conversation feature
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehodgkiss committed Apr 13, 2011
1 parent 6c868db commit 8a8e8cc
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 7 deletions.
24 changes: 19 additions & 5 deletions features/chat.feature
Expand Up @@ -4,11 +4,25 @@ Feature: Chat
As a User As a User
I want to have a conversation online 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 Scenario: Chatting to myself
Given I am signed in as "Steve"
When I fill in "Message" with "Hello?" When I fill in "Message" with "Hello?"
And I press "Send" 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"
2 changes: 1 addition & 1 deletion features/identity.feature
Expand Up @@ -13,7 +13,7 @@ Feature: Identity
And I should see "Sign out" And I should see "Sign out"


Scenario: Sign out Scenario: Sign out
Given I have signed in as "Steve" Given I am signed in as "Steve"
When I follow "Sign out" When I follow "Sign out"
Then I should see "Sign in" Then I should see "Sign in"
And I should not see "Steve" And I should not see "Steve"
4 changes: 4 additions & 0 deletions features/step_definitions/chat_steps.rb
@@ -0,0 +1,4 @@
When /^I say "([^"]*)"$/ do |message|
fill_in "Message", :with => message
click_button "Send"
end
3 changes: 2 additions & 1 deletion features/step_definitions/identity_steps.rb
@@ -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 fill_in "Name", :with => name
click_button "Go" click_button "Go"
end end
8 changes: 8 additions & 0 deletions features/step_definitions/session_steps.rb
@@ -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
28 changes: 28 additions & 0 deletions features/support/sessions.rb
@@ -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.