2011-06-29 01:05:07 +00:00
|
|
|
# TL;DR: YOU SHOULD DELETE THIS FILE
|
2010-04-12 23:33:25 +00:00
|
|
|
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
|
2010-07-23 20:09:54 +00:00
|
|
|
# It is recommended to regenerate this file in the future when you upgrade to a
|
|
|
|
# newer version of cucumber-rails. Consider adding your own code to a new file
|
2010-04-12 23:33:25 +00:00
|
|
|
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
|
|
|
|
# files.
|
|
|
|
|
|
|
|
require 'uri'
|
2010-05-09 12:44:53 +00:00
|
|
|
require 'cgi'
|
2010-04-12 23:33:25 +00:00
|
|
|
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
|
2011-06-29 01:05:07 +00:00
|
|
|
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "selectors"))
|
2010-04-12 23:33:25 +00:00
|
|
|
|
|
|
|
module WithinHelpers
|
|
|
|
def with_scope(locator)
|
2011-06-29 01:05:07 +00:00
|
|
|
locator ? within(*selector_for(locator)) { yield } : yield
|
2010-04-12 23:33:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
World(WithinHelpers)
|
|
|
|
|
2011-06-29 01:05:07 +00:00
|
|
|
# Single-line step scoper
|
|
|
|
When /^(.*) within (.*[^:])$/ do |step, parent|
|
2011-11-27 08:29:09 +00:00
|
|
|
with_scope(parent) { step step }
|
2011-06-29 01:05:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Multi-line step scoper
|
|
|
|
When /^(.*) within (.*[^:]):$/ do |step, parent, table_or_string|
|
2011-11-27 08:29:09 +00:00
|
|
|
with_scope(parent) { step "#{step}:", table_or_string }
|
2011-06-29 01:05:07 +00:00
|
|
|
end
|
|
|
|
|
2010-04-12 23:33:25 +00:00
|
|
|
Given /^(?:|I )am on (.+)$/ do |page_name|
|
|
|
|
visit path_to(page_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
When /^(?:|I )go to (.+)$/ do |page_name|
|
|
|
|
visit path_to(page_name)
|
|
|
|
end
|
|
|
|
|
2011-06-29 01:05:07 +00:00
|
|
|
When /^(?:|I )press "([^"]*)"$/ do |button|
|
|
|
|
click_button(button)
|
2010-04-12 23:33:25 +00:00
|
|
|
end
|
|
|
|
|
2011-06-29 01:05:07 +00:00
|
|
|
When /^(?:|I )follow "([^"]*)"$/ do |link|
|
|
|
|
click_link(link)
|
2010-04-12 23:33:25 +00:00
|
|
|
end
|
|
|
|
|
2011-06-29 01:05:07 +00:00
|
|
|
When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
|
|
|
|
fill_in(field, :with => value)
|
2010-04-12 23:33:25 +00:00
|
|
|
end
|
|
|
|
|
2011-06-29 01:05:07 +00:00
|
|
|
When /^(?:|I )fill in "([^"]*)" for "([^"]*)"$/ do |value, field|
|
|
|
|
fill_in(field, :with => value)
|
2010-04-12 23:33:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Use this to fill in an entire form with data from a table. Example:
|
|
|
|
#
|
|
|
|
# When I fill in the following:
|
|
|
|
# | Account Number | 5002 |
|
|
|
|
# | Expiry date | 2009-11-01 |
|
|
|
|
# | Note | Nice guy |
|
|
|
|
# | Wants Email? | |
|
|
|
|
#
|
|
|
|
# TODO: Add support for checkbox, select og option
|
|
|
|
# based on naming conventions.
|
|
|
|
#
|
2011-06-29 01:05:07 +00:00
|
|
|
When /^(?:|I )fill in the following:$/ do |fields|
|
|
|
|
fields.rows_hash.each do |name, value|
|
2011-11-27 08:29:09 +00:00
|
|
|
step %{I fill in "#{name}" with "#{value}"}
|
2010-04-12 23:33:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-29 01:05:07 +00:00
|
|
|
When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field|
|
|
|
|
select(value, :from => field)
|
2010-04-12 23:33:25 +00:00
|
|
|
end
|
|
|
|
|
2011-06-29 01:05:07 +00:00
|
|
|
When /^(?:|I )check "([^"]*)"$/ do |field|
|
|
|
|
check(field)
|
2010-04-12 23:33:25 +00:00
|
|
|
end
|
|
|
|
|
2011-06-29 01:05:07 +00:00
|
|
|
When /^(?:|I )uncheck "([^"]*)"$/ do |field|
|
|
|
|
uncheck(field)
|
2010-04-12 23:33:25 +00:00
|
|
|
end
|
|
|
|
|
2011-06-29 01:05:07 +00:00
|
|
|
When /^(?:|I )choose "([^"]*)"$/ do |field|
|
|
|
|
choose(field)
|
2010-04-12 23:33:25 +00:00
|
|
|
end
|
|
|
|
|
2011-06-29 01:05:07 +00:00
|
|
|
When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
|
|
|
|
attach_file(field, File.expand_path(path))
|
2010-04-12 23:33:25 +00:00
|
|
|
end
|
|
|
|
|
2011-06-29 01:05:07 +00:00
|
|
|
Then /^(?:|I )should see "([^"]*)"$/ do |text|
|
|
|
|
if page.respond_to? :should
|
|
|
|
page.should have_content(text)
|
|
|
|
else
|
|
|
|
assert page.has_content?(text)
|
2010-04-12 23:33:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-29 01:05:07 +00:00
|
|
|
Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
|
2010-04-12 23:33:25 +00:00
|
|
|
regexp = Regexp.new(regexp)
|
2011-06-29 01:05:07 +00:00
|
|
|
|
|
|
|
if page.respond_to? :should
|
|
|
|
page.should have_xpath('//*', :text => regexp)
|
|
|
|
else
|
|
|
|
assert page.has_xpath?('//*', :text => regexp)
|
2010-04-12 23:33:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-29 01:05:07 +00:00
|
|
|
Then /^(?:|I )should not see "([^"]*)"$/ do |text|
|
|
|
|
if page.respond_to? :should
|
|
|
|
page.should have_no_content(text)
|
|
|
|
else
|
|
|
|
assert page.has_no_content?(text)
|
2010-04-12 23:33:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-29 01:05:07 +00:00
|
|
|
Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
|
2010-04-12 23:33:25 +00:00
|
|
|
regexp = Regexp.new(regexp)
|
2011-06-29 01:05:07 +00:00
|
|
|
|
|
|
|
if page.respond_to? :should
|
|
|
|
page.should have_no_xpath('//*', :text => regexp)
|
|
|
|
else
|
|
|
|
assert page.has_no_xpath?('//*', :text => regexp)
|
2010-04-12 23:33:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-29 01:05:07 +00:00
|
|
|
Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
|
|
|
|
with_scope(parent) do
|
2010-05-09 12:44:53 +00:00
|
|
|
field = find_field(field)
|
|
|
|
field_value = (field.tag_name == 'textarea') ? field.text : field.value
|
2010-04-12 23:33:25 +00:00
|
|
|
if field_value.respond_to? :should
|
|
|
|
field_value.should =~ /#{value}/
|
|
|
|
else
|
|
|
|
assert_match(/#{value}/, field_value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-29 01:05:07 +00:00
|
|
|
Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value|
|
|
|
|
with_scope(parent) do
|
2010-05-09 12:44:53 +00:00
|
|
|
field = find_field(field)
|
|
|
|
field_value = (field.tag_name == 'textarea') ? field.text : field.value
|
2010-04-12 23:33:25 +00:00
|
|
|
if field_value.respond_to? :should_not
|
|
|
|
field_value.should_not =~ /#{value}/
|
|
|
|
else
|
2010-05-09 12:44:53 +00:00
|
|
|
assert_no_match(/#{value}/, field_value)
|
2010-04-12 23:33:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-29 01:05:07 +00:00
|
|
|
Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent|
|
|
|
|
with_scope(parent) do
|
2010-04-12 23:33:25 +00:00
|
|
|
field_checked = find_field(label)['checked']
|
|
|
|
if field_checked.respond_to? :should
|
2011-06-29 01:05:07 +00:00
|
|
|
field_checked.should be_true
|
2010-04-12 23:33:25 +00:00
|
|
|
else
|
2011-06-29 01:05:07 +00:00
|
|
|
assert field_checked
|
2010-04-12 23:33:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-29 01:05:07 +00:00
|
|
|
Then /^the "([^"]*)" checkbox(?: within (.*))? should not be checked$/ do |label, parent|
|
|
|
|
with_scope(parent) do
|
2010-04-12 23:33:25 +00:00
|
|
|
field_checked = find_field(label)['checked']
|
2011-06-29 01:05:07 +00:00
|
|
|
if field_checked.respond_to? :should
|
|
|
|
field_checked.should be_false
|
2010-04-12 23:33:25 +00:00
|
|
|
else
|
2011-06-29 01:05:07 +00:00
|
|
|
assert !field_checked
|
2010-04-12 23:33:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-04-12 23:33:25 +00:00
|
|
|
Then /^(?:|I )should be on (.+)$/ do |page_name|
|
|
|
|
current_path = URI.parse(current_url).path
|
|
|
|
if current_path.respond_to? :should
|
|
|
|
current_path.should == path_to(page_name)
|
|
|
|
else
|
|
|
|
assert_equal path_to(page_name), current_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
|
2010-05-09 12:44:53 +00:00
|
|
|
query = URI.parse(current_url).query
|
|
|
|
actual_params = query ? CGI.parse(query) : {}
|
|
|
|
expected_params = {}
|
2010-07-23 20:09:54 +00:00
|
|
|
expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
|
|
|
|
|
2010-04-12 23:33:25 +00:00
|
|
|
if actual_params.respond_to? :should
|
|
|
|
actual_params.should == expected_params
|
|
|
|
else
|
|
|
|
assert_equal expected_params, actual_params
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Then /^show me the page$/ do
|
|
|
|
save_and_open_page
|
2011-11-27 08:29:09 +00:00
|
|
|
end
|