Refactor saved state cucumber feature to be more consistent. (It was occasionally failing locally due to a timing issue.)

This commit is contained in:
Sarah Mei 2011-03-27 18:32:11 -07:00
parent 36a262a3ad
commit 59650c8104
3 changed files with 59 additions and 71 deletions

View file

@ -1,56 +1,46 @@
@javascript @javascript
Feature: saved state Feature: saved state
Background:
Given I sign in
And I have an aspect called "Closed 1"
And I have an aspect called "Closed 2"
Scenario: open aspects persist across sessions Scenario: open aspects persist across sessions
Given I am signed in Given I have an aspect called "Open 1"
And I have an aspect called "Open 1" And I have an aspect called "Open 2"
And I have an aspect called "Closed 1" And I go to the aspects page
And I have an aspect called "Closed 2"
And I have an aspect called "Open 2"
And I am on the aspects page
When I follow "Open 1"
And I follow "Open 2"
Then I should have aspect "Open 1" "selected" When I follow "Open 1"
Then I should have aspect "Open 2" "selected" And I follow "Open 2"
Then I should have aspect "Closed 1" "not selected" Then aspect "Open 1" should be selected
Then I should have aspect "Closed 2" "not selected" And aspect "Open 2" should be selected
But aspect "Closed 1" should not be selected
And aspect "Closed 2" should not be selected
And I click on my name in the header When I sign out
And I follow "logout" And I sign in
Then I should be on the aspects page
And aspect "Open 1" should be selected
And aspect "Open 2" should be selected
But aspect "Closed 1" should not be selected
And aspect "Closed 2" should not be selected
And I go to the new user session page When I follow "All Aspects"
Then aspect "All Aspects" should be selected
And I am signed in
Then I should be on the aspects page
Then I should have aspect "Open 1" "selected"
But I should have aspect "Open 2" "selected"
But I should have aspect "Closed 1" "not selected"
But I should have aspect "Closed 2" "not selected"
And I follow "All Aspects"
Then I should have aspect "All Aspects" "selected"
Scenario: home persists across sessions Scenario: home persists across sessions
Given I am signed in Given I am on the aspects page
And I have an aspect called "Closed 1"
And I have an aspect called "Closed 2"
And I am on the aspects page
When I follow "Closed 1"
When I follow "All Aspects"
Then I should have aspect "All Aspects" "selected" When I follow "Closed 1"
Then I should have aspect "Closed 1" "not selected" And I follow "All Aspects"
Then I should have aspect "Closed 2" "not selected" Then aspect "All Aspects" should be selected
But aspect "Closed 1" should not be selected
And aspect "Closed 2" should not be selected
And I click on my name in the header When I sign out
And I follow "logout" And I sign in
Then I should be on the aspects page
And I go to the new user session page And aspect "All Aspects" should be selected
But aspect "Closed 1" should not be selected
And I am signed in And aspect "Closed 2" should not be selected
Then I should be on the aspects page
Then I should have aspect "All Aspects" "selected"
Then I should have aspect "Closed 1" "not selected"
Then I should have aspect "Closed 2" "not selected"

View file

@ -9,11 +9,12 @@ Given /^I (?:am signed|sign) in as an? (\w+)$/ do |role|
Given 'I am signed in' Given 'I am signed in'
end end
Given "I try to sign in" do Given /^(?:I am signed in|I sign in)$/ do
Given "I am signed in" When %(I try to sign in)
wait_until { page.has_content?(@me.diaspora_handle) }
end end
Given 'I am signed in' do When /^I try to sign in$/ do
@me ||= Factory(:user_with_aspect, :getting_started => false) @me ||= Factory(:user_with_aspect, :getting_started => false)
When %(I go to the new user session page) When %(I go to the new user session page)
When %(I fill in "Username" with "#{@me.username}") When %(I fill in "Username" with "#{@me.username}")
@ -21,7 +22,6 @@ Given 'I am signed in' do
When %(I press "Sign in") When %(I press "Sign in")
end end
When /^I sign in as "([^"]*)"$/ do |email| When /^I sign in as "([^"]*)"$/ do |email|
@me = User.find_by_email(email) @me = User.find_by_email(email)
@me.password ||= 'password' @me.password ||= 'password'
@ -37,4 +37,7 @@ When /^I put in my password in "([^"]*)"$/ do |field|
When %(I fill in "#{field}" with "#{@me.password}") When %(I fill in "#{field}" with "#{@me.password}")
end end
When /^I (?:log|sign) out$/ do
When 'I click on my name in the header'
And 'I follow "logout"'
end

View file

@ -1,6 +1,6 @@
Given /^a user with username "([^\"]*)" and password "([^\"]*)"$/ do |username, password| Given /^a user with username "([^\"]*)" and password "([^\"]*)"$/ do |username, password|
@me ||= Factory(:user, :username => username, :password => password, @me ||= Factory(:user, :username => username, :password => password,
:password_confirmation => password, :getting_started => false) :password_confirmation => password, :getting_started => false)
@me.aspects.create(:name => "Besties") @me.aspects.create(:name => "Besties")
@me.aspects.create(:name => "Unicorns") @me.aspects.create(:name => "Unicorns")
end end
@ -40,7 +40,7 @@ end
Given /^I have been invited by a user$/ do Given /^I have been invited by a user$/ do
@inviter = Factory(:user) @inviter = Factory(:user)
aspect = @inviter.aspects.create(:name => "Rocket Scientists") aspect = @inviter.aspects.create(:name => "Rocket Scientists")
@me = @inviter.invite_user(aspect.id, 'email', "new_invitee@example.com", "Hey, tell me about your rockets!") @me = @inviter.invite_user(aspect.id, 'email', "new_invitee@example.com", "Hey, tell me about your rockets!")
end end
When /^I click on my name$/ do When /^I click on my name$/ do
@ -60,7 +60,7 @@ end
Given /^I have one contact request$/ do Given /^I have one contact request$/ do
other_user = Factory(:user) other_user = Factory(:user)
other_aspect = other_user.aspects.create!(:name => "meh") other_aspect = other_user.aspects.create!(:name => "meh")
other_user.send_contact_request_to(@me.person, other_aspect) other_user.send_contact_request_to(@me.person, other_aspect)
@ -112,15 +112,11 @@ end
Given /^I have no open aspects saved$/ do Given /^I have no open aspects saved$/ do
@me.aspects.update_all(:open => false) @me.aspects.update_all(:open => false)
end end
Then /^I should have aspect "([^"]*)" "([^"]*)"$/ do |arg1, arg2|
val = evaluate_script("$('a:contains(\"#{arg1}\")').parent('li').hasClass('selected');") # Then /^aspect "([^"]*)" should (not )?be selected$/ do |aspect_name, not_selected|
if arg2 == "selected" link_is_selected = evaluate_script("$('a:contains(\"#{aspect_name}\")').parent('li').hasClass('selected');")
val.should == true expected_value = !not_selected
elsif arg2 == "not selected" link_is_selected.should == expected_value
val.should == false
else
raise "Aspect state should either be 'selected' or 'not selected'"
end
end end
Given /^a user with email "([^"]*)" is connected with "([^"]*)"$/ do |arg1, arg2| Given /^a user with email "([^"]*)" is connected with "([^"]*)"$/ do |arg1, arg2|
@ -138,20 +134,19 @@ end
Given /^a user with email "([^\"]*)" has posted a status message "([^\"]*)" in all aspects$/ do |arg1, arg2| Given /^a user with email "([^\"]*)" has posted a status message "([^\"]*)" in all aspects$/ do |arg1, arg2|
user = User.where(:email => arg1).first user = User.where(:email => arg1).first
status_message = user.build_post(:status_message, :text => arg2) status_message = user.build_post(:status_message, :text => arg2)
def status_message.socket_to_user(a1, a2); end
def status_message.socket_to_user(a1, a2)
;
end
user.add_to_streams(status_message, user.aspects) user.add_to_streams(status_message, user.aspects)
status_message.save! status_message.save!
bob = User.where(:email => "bob@bob.bob").first bob = User.where(:email => "bob@bob.bob").first
raise bob.visible_posts.inspect raise bob.visible_posts.inspect
end end
When /^I log out$/ do
When "I click on my name in the header"
When "I follow \"logout\""
end
Given /^there is a user "([^\"]*)" who's tagged "([^\"]*)"$/ do |full_name, tag| Given /^there is a user "([^\"]*)" who's tagged "([^\"]*)"$/ do |full_name, tag|
username = full_name.gsub(/\W/,"").underscore username = full_name.gsub(/\W/, "").underscore
Given "a user named \"#{full_name}\" with email \"#{username}@example.com\"" Given "a user named \"#{full_name}\" with email \"#{username}@example.com\""
user = User.find_by_username(username) user = User.find_by_username(username)
user.profile.tag_string = tag user.profile.tag_string = tag