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
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
Given I am signed in
And I have an aspect called "Open 1"
And I have an aspect called "Closed 1"
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"
Given I have an aspect called "Open 1"
And I have an aspect called "Open 2"
And I go to the aspects page
Then I should have aspect "Open 1" "selected"
Then I should have aspect "Open 2" "selected"
Then I should have aspect "Closed 1" "not selected"
Then I should have aspect "Closed 2" "not selected"
When I follow "Open 1"
And I follow "Open 2"
Then 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 click on my name in the header
And I follow "logout"
When I sign out
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
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"
When I follow "All Aspects"
Then aspect "All Aspects" should be selected
Scenario: home persists across sessions
Given I am signed in
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"
Given I am 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"
When I follow "Closed 1"
And I follow "All Aspects"
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
And I follow "logout"
And I go to the new user session page
And I am signed in
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"
When I sign out
And I sign in
Then I should be on the aspects page
And aspect "All Aspects" should be selected
But aspect "Closed 1" should not be selected
And aspect "Closed 2" should not be selected

View file

@ -9,11 +9,12 @@ Given /^I (?:am signed|sign) in as an? (\w+)$/ do |role|
Given 'I am signed in'
end
Given "I try to sign in" do
Given "I am signed in"
Given /^(?:I am signed in|I sign in)$/ do
When %(I try to sign in)
wait_until { page.has_content?(@me.diaspora_handle) }
end
Given 'I am signed in' do
When /^I try to sign in$/ do
@me ||= Factory(:user_with_aspect, :getting_started => false)
When %(I go to the new user session page)
When %(I fill in "Username" with "#{@me.username}")
@ -21,7 +22,6 @@ Given 'I am signed in' do
When %(I press "Sign in")
end
When /^I sign in as "([^"]*)"$/ do |email|
@me = User.find_by_email(email)
@me.password ||= 'password'
@ -37,4 +37,7 @@ When /^I put in my password in "([^"]*)"$/ do |field|
When %(I fill in "#{field}" with "#{@me.password}")
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|
@me ||= Factory(:user, :username => username, :password => password,
:password_confirmation => password, :getting_started => false)
@me ||= Factory(:user, :username => username, :password => password,
:password_confirmation => password, :getting_started => false)
@me.aspects.create(:name => "Besties")
@me.aspects.create(:name => "Unicorns")
end
@ -40,7 +40,7 @@ end
Given /^I have been invited by a user$/ do
@inviter = Factory(:user)
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
When /^I click on my name$/ do
@ -60,7 +60,7 @@ end
Given /^I have one contact request$/ do
other_user = Factory(:user)
other_user = Factory(:user)
other_aspect = other_user.aspects.create!(:name => "meh")
other_user.send_contact_request_to(@me.person, other_aspect)
@ -112,15 +112,11 @@ end
Given /^I have no open aspects saved$/ do
@me.aspects.update_all(:open => false)
end
Then /^I should have aspect "([^"]*)" "([^"]*)"$/ do |arg1, arg2|
val = evaluate_script("$('a:contains(\"#{arg1}\")').parent('li').hasClass('selected');") #
if arg2 == "selected"
val.should == true
elsif arg2 == "not selected"
val.should == false
else
raise "Aspect state should either be 'selected' or 'not selected'"
end
Then /^aspect "([^"]*)" should (not )?be selected$/ do |aspect_name, not_selected|
link_is_selected = evaluate_script("$('a:contains(\"#{aspect_name}\")').parent('li').hasClass('selected');")
expected_value = !not_selected
link_is_selected.should == expected_value
end
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|
user = User.where(:email => arg1).first
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)
status_message.save!
bob = User.where(:email => "bob@bob.bob").first
raise bob.visible_posts.inspect
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|
username = full_name.gsub(/\W/,"").underscore
username = full_name.gsub(/\W/, "").underscore
Given "a user named \"#{full_name}\" with email \"#{username}@example.com\""
user = User.find_by_username(username)
user.profile.tag_string = tag