Created
August 20, 2012 14:59
-
-
Save superacidjax/3404971 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'uri' | |
require 'cgi' | |
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths")) | |
module WithinHelpers | |
def with_scope(locator) | |
locator ? within(locator) { yield } : yield | |
end | |
end | |
World(WithinHelpers) | |
Given /^(?:|I )am on (.+)$/ do |page_name| | |
visit path_to(page_name) | |
end | |
And /^I am on the homepage$/ do | |
visit root_path | |
end | |
When /^(?:|I )go to (.+)$/ do |page_name| | |
visit path_to(page_name) | |
end | |
When /^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/ do |button, selector| | |
with_scope(selector) do | |
click_button(button) | |
end | |
end | |
When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector| | |
with_scope(selector) do | |
click_link(link) | |
end | |
end | |
When /^(?:|I )fill in "([^"]*)" with "([^"]*)"(?: within "([^"]*)")?$/ do |field, value, selector| | |
with_scope(selector) do | |
fill_in(field, :with => value) | |
end | |
end | |
When /^(?:|I )fill in "([^"]*)" for "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector| | |
with_scope(selector) do | |
fill_in(field, :with => value) | |
end | |
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? | | | |
# | |
# | |
When /^(?:|I )fill in the following(?: within "([^"]*)")?:$/ do |selector, fields| | |
with_scope(selector) do | |
fields.rows_hash.each do |name, value| | |
When %{I fill in "#{name}" with "#{value}"} | |
end | |
end | |
end | |
When /^(?:|I )select "([^"]*)" from "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector| | |
with_scope(selector) do | |
select(value, :from => field) | |
end | |
end | |
When /^(?:|I )check "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector| | |
with_scope(selector) do | |
check(field) | |
end | |
end | |
When /^(?:|I )uncheck "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector| | |
with_scope(selector) do | |
uncheck(field) | |
end | |
end | |
When /^(?:|I )choose "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector| | |
with_scope(selector) do | |
choose(field) | |
end | |
end | |
When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"(?: within "([^"]*)")?$/ do |path, field, selector| | |
with_scope(selector) do | |
attach_file(field, path) | |
end | |
end | |
Then /^(?:|I )should see JSON:$/ do |expected_json| | |
require 'json' | |
expected = JSON.pretty_generate(JSON.parse(expected_json)) | |
actual = JSON.pretty_generate(JSON.parse(response.body)) | |
expected.should == actual | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment