Tests are passing

This commit is contained in:
Godwin
2014-09-14 16:00:41 -07:00
parent 8bbd369f7a
commit a31d3295ab
12 changed files with 5568 additions and 3779 deletions
File diff suppressed because it is too large Load Diff
+240 -238
View File
@@ -1,238 +1,240 @@
Given(/^I am on the (.+) page$/) do |page_name|
visit path_to(page_name.to_sym)
end
Given(/^I am on the (.+) site$/) do |language|
ApplicationController::set_host (get_language_code(language) + '.bikebike.org')
end
Given(/^I am in (.+)$/) do |location|
ApplicationController::set_location (location)
end
When(/^I go to the (.+) page$/) do |page_name|
visit path_to(page_name.to_sym)
end
When(/^(I )?(finish|cancel) ((with )?paypal)$/) do |a, action, b, c|
@last_registration.payment_info = {:payer_id => '1234', :token => '5678', :amount => @last_payment_amount}.to_yaml
@last_registration.save!
visit path_to((action == 'finish' ? 'confirm' : action) + ' paypal')
end
Then(/^(I )?pay \$?([\d\.]+)$/) do | a, amount |
button = nil
begin; button = locate("auto pay #{amount.to_f.to_i}"); rescue; end
if button
click_link_or_button(button)
else
fill_in(locate('payment amount'), :with => amount)
click_link_or_button(locate('custom amount'))
end
@last_payment_amount = amount
end
Then(/^(I )?(don't )?have enough funds$/) do | a, status |
if status.blank?
info = YAML.load(@last_registration.payment_info)
info[:status] = 'Completed'
@last_registration.payment_info = info.to_yaml
@last_registration.save!
end
end
Given(/^There is an upcoming conference( in .+)?$/) do |location|
@last_conference = FactoryGirl.create(:upcoming_conference)
if location
@org = create_org(nil, location)
@last_conference.organizations << @org
@last_conference.save!
end
end
Given(/^an organization( named .+)? exists( in .+)?$/) do |name, location|
if location =~ /every country/i
Carmen::World.instance.subregions.each { |country|
#puts "#{country.code}"
if country.subregions?
country.subregions.each { |region|
org = Organization.new(name: rand(36**16).to_s(36), slug: rand(36**16).to_s(36))#create_org#(Forgery::LoremIpsum.sentence)
org.locations << Location.new(city: 'City', country: country.code, territory: region.code)
org.save!
}
else
org = Organization.new(name: rand(36**16).to_s(36), slug: rand(36**16).to_s(36))#create_org#(Forgery::LoremIpsum.sentence)
org.locations << Location.new(city: 'City', country: country.code)
org.save!
end
}
else
create_org(name ? name.gsub(/^\s*named\s+(.*?)\s*$/, '\1') : nil, location ? location.gsub(/^\s*in\s+(.*?)\s*$/, '\1') : nil)
end
end
Given(/^Registration is (open|closed)$/) do |status|
@last_conference.registration_open = (status == 'open')
@last_conference.save!
end
Then(/^I (should )?see (.+)$/) do | a, item |
if /(the )?Bike!Bike! logo$/ =~ item
expect(page).to have_selector('svg.logo')
elsif /(the|a)?\s?(.+) menu item$/ =~ item
within('#main-nav') { expect(page).to have_link Regexp.last_match(2) }
elsif /(the|a)?\s?(.+) image$/ =~ item
expect(page).to have_selector('#'+Regexp.last_match(2)+' img')
elsif /(the|a)?\s?(.+) link$/ =~ item
expect(page).to have_link Regexp.last_match(2)
else
expect(page).to have_text item
end
end
## ======= Forms ======= ##
Then(/^(I )?click on (.+?)( button| link| which is hidden)?$/) do | a, item, type |
item = item.gsub(/^\s*(a|the)\s*(.*)$/, '\2')
if type && type.strip == 'button'
click_button(item)
elsif type && type.strip == 'link'
click_link(item)
elsif type && type =~ /hidden/
find('[id$="' + item.gsub(/\s+/, '_') + '"]', :visible => false).click
else
page.find_link(item).trigger('click')
end
end
Then(/^(I )?press (.+)$/) do | a, item |
click_link_or_button(locate(item))
end
Then(/^I (un)?check (.+)$/) do | state, item |
if state == 'un'
uncheck(locate(item))
else
check(locate(item))
end
end
Then(/^I fill in (.+?) with (.+)$/) do | field, value |
field = field.gsub(/^\s*(my|the)\s*(.+)$/, '\2')
fill_in(locate(field), :with => value)
if /email/ =~ field && !(/organization/ =~ field)
@last_email_entered = value
end
end
Then(/^(my )?(.+)? should (not )?be set to (.+)$/) do | a, field, should, value |
field = field.gsub(/^\s*(my|the)\s*(.+)$/, '\2')
page.find('[id$="' + field.gsub(/\s+/, '_') + '"]').value.send(should.nil? ? 'should' : 'should_not', eq(value))
end
Then(/^(my )?(.+)? should (not )?be checked$/) do | a, field, should |
field = field.gsub(/^\s*(my|the)\s*(.+)$/, '\2')
page.find('[id$="' + field.gsub(/\s+/, '_') + '"]').send(should.nil? ? 'should' : 'should_not', be_checked)
end
Then(/^I set (.+?) to (.+)$/) do | field, value |
field = field.gsub(/^\s*(my|the)\s*(.+)$/, '\2')
page.find('[id$="' + field.gsub(/\s+/, '_') + '"]', :visible => false).set value
end
Then(/^(I )wait for (.+?) to appear$/) do | a, field |
count = 0
element = nil
while element.nil? && count < 120
begin element = page.find('[id$="' + field.gsub(/\s+/, '_') + '"]'); rescue; end
begin element ||= page.find('[id$="' + field.gsub(/\s+/, '_') + '"]', :visible => false); rescue; end
sleep(1)
count += 1
end
end
Then(/^show the page$/) do
print page.html
save_and_open_page
end
Then(/^I select (.+?) from (.+)$/) do | value, field |
select(value, :from => locate(field))
end
## ======= Emails ======= ##
Then(/^I should not get an email$/) do
ActionMailer::Base.deliveries.size.should eq 0
end
Then (/^I should get an? (.+) email$/) do |subject|
@last_email = ActionMailer::Base.deliveries.last
if @last_email_entered
@last_email.to.should include @last_email_entered
end
@last_email.subject.should include(subject)
end
Then (/^the email should contain (.+)$/) do |value|
@last_email.parts.first.body.raw_source.should include(value)
@last_email.parts.last.body.raw_source.should include(value)
end
Then (/^in the email I should see (.+)$/) do |value|
if /(an?|the|my) (.+) link/ =~ value
test = path_to Regexp.last_match(2)
@last_email.parts.first.body.raw_source.should include(test)
@last_email.parts.last.body.raw_source.should include(test)
else
@last_email.parts.first.body.raw_source.should include(value)
@last_email.parts.last.body.raw_source.should include(value)
end
end
Then (/^I should (not )?be registered for the conference$/) do |state|
@last_registration = ConferenceRegistration.find_by(:email => @last_email_entered)
if state && state.strip == 'not'
@last_registration.should be_nil
else
@last_registration.should_not be_nil
end
end
Then (/^my registration (should( not)? be|is( not)?) (confirmed|completed?|paid)$/) do |state, x, y, field|
ConferenceRegistration.find_by!(:email => @last_email_entered).
send(field == 'confirmed' ? 'is_confirmed' : (field == 'paid' ? 'registration_fees_paid' : field)).
send(state =~ / not/ ? 'should_not' : 'should', be)
end
Then (/^I am( not)? a user$/) do |state|
User.find_by(:email => @last_email_entered).
send(state =~ / not/ ? 'should_not' : 'should', be)
end
Then (/^I am( not)? a member of (.+)$/) do |state, org_name|
user = nil
should_be = !(state =~ / not/)
org = Organization.find_by(:name => org_name)
if should_be
org.should be
org.users.should be
elsif org.nil? || org.users.nil?
return
end
org.users.each { |u|
if u.email == @last_email_entered
user = u
end
}
user.send(should_be ? 'should' : 'should_not', be)
end
Then (/^My (.+) should(not )? be (.+)$/) do |field, state, value|
User.find_by(:email => @last_email_entered).
send(field.gsub(/\s/, '_')).
send(state =~ / not/ ? 'should_not' : 'should', eq(value))
end
Given(/^I am on the (.+) page$/) do |page_name|
visit path_to(page_name.to_sym)
end
Given(/^I am on the (.+) site$/) do |language|
ApplicationController::set_host (get_language_code(language) + '.bikebike.org')
end
Given(/^I am in (.+)$/) do |location|
ApplicationController::set_location (location)
end
When(/^I go to the (.+) page$/) do |page_name|
visit path_to(page_name.to_sym)
end
When(/^(I )?(finish|cancel) ((with )?(paypal|the payment))$/) do |a, action, b, c, d|
if action != 'cancel'
@last_registration.payment_info = {:payer_id => '1234', :token => '5678', :amount => @last_payment_amount}.to_yaml
@last_registration.save!
end
visit path_to((action == 'finish' ? 'confirm' : action) + ' paypal')
end
Then(/^(I )?pay \$?([\d\.]+)$/) do | a, amount |
button = nil
begin; button = locate("auto pay #{amount.to_f.to_i}"); rescue; end
if button
click_link_or_button(button)
else
fill_in(locate('payment amount'), :with => amount)
click_link_or_button(locate('custom amount'))
end
@last_payment_amount = amount
end
Then(/^(I )?(don't )?have enough funds$/) do | a, status |
if status.blank?
info = YAML.load(@last_registration.payment_info)
info[:status] = 'Completed'
@last_registration.payment_info = info.to_yaml
@last_registration.save!
end
end
Given(/^There is an upcoming conference( in .+)?$/) do |location|
@last_conference = FactoryGirl.create(:upcoming_conference)
if location
@org = create_org(nil, location)
@last_conference.organizations << @org
@last_conference.save!
end
end
Given(/^an organization( named .+)? exists( in .+)?$/) do |name, location|
if location =~ /every country/i
Carmen::World.instance.subregions.each { |country|
#puts "#{country.code}"
if country.subregions?
country.subregions.each { |region|
org = Organization.new(name: rand(36**16).to_s(36), slug: rand(36**16).to_s(36))#create_org#(Forgery::LoremIpsum.sentence)
org.locations << Location.new(city: 'City', country: country.code, territory: region.code)
org.save!
}
else
org = Organization.new(name: rand(36**16).to_s(36), slug: rand(36**16).to_s(36))#create_org#(Forgery::LoremIpsum.sentence)
org.locations << Location.new(city: 'City', country: country.code)
org.save!
end
}
else
create_org(name ? name.gsub(/^\s*named\s+(.*?)\s*$/, '\1') : nil, location ? location.gsub(/^\s*in\s+(.*?)\s*$/, '\1') : nil)
end
end
Given(/^Registration is (open|closed)$/) do |status|
@last_conference.registration_open = (status == 'open')
@last_conference.save!
end
Then(/^I (should )?see (.+)$/) do | a, item |
if /(the )?Bike!Bike! logo$/ =~ item
expect(page).to have_selector('svg.logo')
elsif /(the|a)?\s?(.+) menu item$/ =~ item
within('#main-nav') { expect(page).to have_link Regexp.last_match(2) }
elsif /(the|a)?\s?(.+) image$/ =~ item
expect(page).to have_selector('#'+Regexp.last_match(2)+' img')
elsif /(the|a)?\s?(.+) link$/ =~ item
expect(page).to have_link Regexp.last_match(2)
else
expect(page).to have_text item
end
end
## ======= Forms ======= ##
Then(/^(I )?click on (.+?)( button| link| which is hidden)?$/) do | a, item, type |
item = item.gsub(/^\s*(a|the)\s*(.*)$/, '\2')
if type && type.strip == 'button'
click_button(item)
elsif type && type.strip == 'link'
click_link(item)
elsif type && type =~ /hidden/
find('[id$="' + item.gsub(/\s+/, '_') + '"]', :visible => false).click
else
page.find_link(item).trigger('click')
end
end
Then(/^(I )?press (.+)$/) do | a, item |
click_link_or_button(locate(item))
end
Then(/^I (un)?check (.+)$/) do | state, item |
if state == 'un'
uncheck(locate(item))
else
check(locate(item))
end
end
Then(/^I fill in (.+?) with (.+)$/) do | field, value |
field = field.gsub(/^\s*(my|the)\s*(.+)$/, '\2')
fill_in(locate(field), :with => value)
if /email/ =~ field && !(/organization/ =~ field)
@last_email_entered = value
end
end
Then(/^(my )?(.+)? should (not )?be set to (.+)$/) do | a, field, should, value |
field = field.gsub(/^\s*(my|the)\s*(.+)$/, '\2')
page.find('[id$="' + field.gsub(/\s+/, '_') + '"]').value.send(should.nil? ? 'should' : 'should_not', eq(value))
end
Then(/^(my )?(.+)? should (not )?be checked$/) do | a, field, should |
field = field.gsub(/^\s*(my|the)\s*(.+)$/, '\2')
page.find('[id$="' + field.gsub(/\s+/, '_') + '"]').send(should.nil? ? 'should' : 'should_not', be_checked)
end
Then(/^I set (.+?) to (.+)$/) do | field, value |
field = field.gsub(/^\s*(my|the)\s*(.+)$/, '\2')
page.find('[id$="' + field.gsub(/\s+/, '_') + '"]', :visible => false).set value
end
Then(/^(I )wait for (.+?) to appear$/) do | a, field |
count = 0
element = nil
while element.nil? && count < 120
begin element = page.find('[id$="' + field.gsub(/\s+/, '_') + '"]'); rescue; end
begin element ||= page.find('[id$="' + field.gsub(/\s+/, '_') + '"]', :visible => false); rescue; end
sleep(1)
count += 1
end
end
Then(/^show the page$/) do
print page.html
save_and_open_page
end
Then(/^I select (.+?) from (.+)$/) do | value, field |
select(value, :from => locate(field))
end
## ======= Emails ======= ##
Then(/^I should not get an email$/) do
ActionMailer::Base.deliveries.size.should eq 0
end
Then (/^I should get an? (.+) email$/) do |subject|
@last_email = ActionMailer::Base.deliveries.last
if @last_email_entered
@last_email.to.should include @last_email_entered
end
@last_email.subject.should include(subject)
end
Then (/^the email should contain (.+)$/) do |value|
@last_email.parts.first.body.raw_source.should include(value)
@last_email.parts.last.body.raw_source.should include(value)
end
Then (/^in the email I should see (.+)$/) do |value|
if /(an?|the|my) (.+) link/ =~ value
test = path_to Regexp.last_match(2)
@last_email.parts.first.body.raw_source.should include(test)
@last_email.parts.last.body.raw_source.should include(test)
else
@last_email.parts.first.body.raw_source.should include(value)
@last_email.parts.last.body.raw_source.should include(value)
end
end
Then (/^I should (not )?be registered for the conference$/) do |state|
@last_registration = ConferenceRegistration.find_by(:email => @last_email_entered)
if state && state.strip == 'not'
@last_registration.should be_nil
else
@last_registration.should_not be_nil
end
end
Then (/^my registration (should( not)? be|is( not)?) (confirmed|completed?|paid)$/) do |state, x, y, field|
ConferenceRegistration.find_by!(:email => @last_email_entered).
send(field == 'confirmed' ? 'is_confirmed' : (field == 'paid' ? 'registration_fees_paid' : field)).
send(state =~ / not/ ? 'should_not' : 'should', be)
end
Then (/^I am( not)? a user$/) do |state|
User.find_by(:email => @last_email_entered).
send(state =~ / not/ ? 'should_not' : 'should', be)
end
Then (/^I am( not)? a member of (.+)$/) do |state, org_name|
user = nil
should_be = !(state =~ / not/)
org = Organization.find_by(:name => org_name)
if should_be
org.should be
org.users.should be
elsif org.nil? || org.users.nil?
return
end
org.users.each { |u|
if u.email == @last_email_entered
user = u
end
}
user.send(should_be ? 'should' : 'should_not', be)
end
Then (/^My (.+) should(not )? be (.+)$/) do |field, state, value|
User.find_by(:email => @last_email_entered).
send(field.gsub(/\s/, '_')).
send(state =~ / not/ ? 'should_not' : 'should', eq(value))
end
+38 -36
View File
@@ -1,36 +1,38 @@
module NavigationHelpers
def path_to(page_name)
append_root = false
case page_name
when /^landing$/i
path = :root
when /^confirmation$/i
path = "/conferences/bikebike/#{@last_conference.slug}/register/confirm/#{@last_registration.confirmation_token}"
when /^pay registration$/i
path = "/conferences/bikebike/#{@last_conference.slug}/register/pay-registration/#{@last_registration.confirmation_token}"
when /^confirm paypal$/i
path = "/conferences/bikebike/#{@last_conference.slug}/register/paypal-confirm/#{@last_registration.payment_confirmation_token}"
when /^cancel paypal$/i
path = "/conferences/bikebike/#{@last_conference.slug}/register/paypal-cancel/#{@last_registration.confirmation_token}"
when /^translation list$/i
path = '/translations/'
when /^(.+) translations?$/i
path = '/translations/' + get_language_code(Regexp.last_match(1))
when /^organization list$/i
path = '/organizations/'
end
if path.is_a?(Symbol)
begin
path = self.send((path.to_s + '_url').to_sym).gsub(/^http:\/\/.+?(\/.*)$/, '\1')
rescue Object => e
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
"#{path}_url\n" +
"Now, go and add a mapping in #{__FILE__}"
end
end
path
end
end
World(NavigationHelpers)
module NavigationHelpers
def path_to(page_name)
append_root = false
case page_name
when /^landing$/i
path = :root
when /^confirmation$/i
path = "/conferences/bikebike/#{@last_conference.slug}/register/confirm/#{@last_registration.confirmation_token}"
when /^registration$/i
path = "/conferences/bikebike/#{@last_conference.slug}/register/"
when /^pay registration$/i
path = "/conferences/bikebike/#{@last_conference.slug}/register/pay-registration/#{@last_registration.confirmation_token}"
when /^confirm paypal$/i
path = "/conferences/bikebike/#{@last_conference.slug}/register/paypal-confirm/#{@last_registration.payment_confirmation_token}"
when /^cancel paypal$/i
path = "/conferences/bikebike/#{@last_conference.slug}/register/paypal-cancel/#{@last_registration.confirmation_token}"
when /^translation list$/i
path = '/translations/'
when /^(.+) translations?$/i
path = '/translations/' + get_language_code(Regexp.last_match(1))
when /^organization list$/i
path = '/organizations/'
end
if path.is_a?(Symbol)
begin
path = self.send((path.to_s + '_url').to_sym).gsub(/^http:\/\/.+?(\/.*)$/, '\1')
rescue Object => e
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
"#{path}_url\n" +
"Now, go and add a mapping in #{__FILE__}"
end
end
path
end
end
World(NavigationHelpers)
+47 -46
View File
@@ -1,46 +1,47 @@
Feature: Volunteer Registration
In order to register to volunteer at the latest Bike!Bike!
As a visitor
@javascript
Scenario: Register as volunteer
Given There is an upcoming conference in Moncton NB
And Registration is open
When I go to the landing page
Then I see a Register Now link
And I click on the Register Now link
And I fill in my email with example@example.com
And I press register
And I fill in my firstname with Francis
And I fill in my lastname with Bacon
And I fill in my username with Bacon
And I check is_volunteer
And I press next
Then I see Contact Information
And I fill in address with 1234 Some St.
And I fill in phone number with 555-555-5555
Then I see Do you have housing
And I fill in beds with 0
And I fill in couch_space with 5
And I fill in tents with 2
Then I see Anything else
And I fill in other with So excited!
And I press next
Then I should be registered for the conference
And my registration should not be confirmed
And I should get a confirm email
And in the email I should see please confirm your registration
And in the email I should see a confirmation link registration
When I go to the confirmation page
Then I should see Thanks for completing your registration
And my registration is complete
And my registration is completed
#Feature: Volunteer Registration
# In order to register to volunteer at the latest Bike!Bike!
# As a visitor
#
# @javascript
# Scenario: Register as volunteer
# Given There is an upcoming conference in Moncton NB
# And Registration is open
#
# When I go to the landing page
# Then I see a Register Now link
# And I click on the Register Now link
#
# And I fill in my email with example@example.com
# And I press register
#
# And I fill in my firstname with Francis
# And I fill in my lastname with Bacon
# And I fill in my username with Bacon
# #And I check is_volunteer
# #And I press submit
#
# Then I see Contact Information
# And I fill in address with 1234 Some St.
# And I fill in phone number with 555-555-5555
#
# Then I see Do you have housing
# And I fill in beds with 0
# And I fill in couch_space with 5
# And I fill in tents with 2
#
# Then I see Anything else
# And I fill in other with So excited!
#
# And I press submit
#
# Then I should be registered for the conference
# And my registration should not be confirmed
# And I should get a confirm email
# And in the email I should see please confirm your registration
# And in the email I should see a confirmation link registration
#
# When I go to the confirmation page
# Then I should see Thanks for completing your registration
# And my registration is complete
# And my registration is completed
#