|
| 1 | +# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. |
| 2 | +# It is recommended to regenerate this file in the future when you upgrade to a |
| 3 | +# newer version of cucumber-rails. Consider adding your own code to a new file |
| 4 | +# instead of editing this one. Cucumber will automatically load all features/**/*.rb |
| 5 | +# files. |
| 6 | + |
| 7 | + |
| 8 | +require 'uri' |
| 9 | +require 'cgi' |
| 10 | +require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths")) |
| 11 | + |
| 12 | +module WithinHelpers |
| 13 | + def with_scope(locator) |
| 14 | + locator ? within(locator) { yield } : yield |
| 15 | + end |
| 16 | +end |
| 17 | +World(WithinHelpers) |
| 18 | + |
| 19 | +Given /^(?:|I )am on (.+)$/ do |page_name| |
| 20 | + visit path_to(page_name) |
| 21 | +end |
| 22 | + |
| 23 | +When /^(?:|I )go to (.+)$/ do |page_name| |
| 24 | + visit path_to(page_name) |
| 25 | +end |
| 26 | + |
| 27 | +When /^(?:|I )visit (\/.+)$/ do |page_path| |
| 28 | + visit page_path |
| 29 | +end |
| 30 | + |
| 31 | +When /^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/ do |button, selector| |
| 32 | + with_scope(selector) do |
| 33 | + click_button(button) |
| 34 | + end |
| 35 | +end |
| 36 | + |
| 37 | +When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector| |
| 38 | + with_scope(selector) do |
| 39 | + click_link(link) |
| 40 | + end |
| 41 | +end |
| 42 | + |
| 43 | +When /^(?:|I )fill in "([^"]*)" with "([^"]*)"(?: within "([^"]*)")?$/ do |field, value, selector| |
| 44 | + with_scope(selector) do |
| 45 | + fill_in(field, :with => value) |
| 46 | + end |
| 47 | +end |
| 48 | + |
| 49 | +When /^(?:|I )fill in "([^"]*)" for "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector| |
| 50 | + with_scope(selector) do |
| 51 | + fill_in(field, :with => value) |
| 52 | + end |
| 53 | +end |
| 54 | + |
| 55 | +# Use this to fill in an entire form with data from a table. Example: |
| 56 | +# |
| 57 | +# When I fill in the following: |
| 58 | +# | Account Number | 5002 | |
| 59 | +# | Expiry date | 2009-11-01 | |
| 60 | +# | Note | Nice guy | |
| 61 | +# | Wants Email? | | |
| 62 | +# |
| 63 | +# TODO: Add support for checkbox, select og option |
| 64 | +# based on naming conventions. |
| 65 | +# |
| 66 | +When /^(?:|I )fill in the following(?: within "([^"]*)")?:$/ do |selector, fields| |
| 67 | + with_scope(selector) do |
| 68 | + fields.rows_hash.each do |name, value| |
| 69 | + When %{I fill in "#{name}" with "#{value}"} |
| 70 | + end |
| 71 | + end |
| 72 | +end |
| 73 | + |
| 74 | +When /^(?:|I )select "([^"]*)" from "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector| |
| 75 | + with_scope(selector) do |
| 76 | + select(value, :from => field) |
| 77 | + end |
| 78 | +end |
| 79 | + |
| 80 | +When /^(?:|I )check "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector| |
| 81 | + with_scope(selector) do |
| 82 | + check(field) |
| 83 | + end |
| 84 | +end |
| 85 | + |
| 86 | +When /^(?:|I )uncheck "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector| |
| 87 | + with_scope(selector) do |
| 88 | + uncheck(field) |
| 89 | + end |
| 90 | +end |
| 91 | + |
| 92 | +When /^(?:|I )choose "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector| |
| 93 | + with_scope(selector) do |
| 94 | + choose(field) |
| 95 | + end |
| 96 | +end |
| 97 | + |
| 98 | +When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"(?: within "([^"]*)")?$/ do |path, field, selector| |
| 99 | + with_scope(selector) do |
| 100 | + attach_file(field, path) |
| 101 | + end |
| 102 | +end |
| 103 | + |
| 104 | +Then /^(?:|I )should see JSON:$/ do |expected_json| |
| 105 | + require 'json' |
| 106 | + expected = JSON.pretty_generate(JSON.parse(expected_json)) |
| 107 | + actual = JSON.pretty_generate(JSON.parse(response.body)) |
| 108 | + expected.should == actual |
| 109 | +end |
| 110 | + |
| 111 | +Then /^(?:|I )should see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector| |
| 112 | + with_scope(selector) do |
| 113 | + if page.respond_to? :should |
| 114 | + page.should have_content(text) |
| 115 | + else |
| 116 | + assert page.has_content?(text) |
| 117 | + end |
| 118 | + end |
| 119 | +end |
| 120 | + |
| 121 | +Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector| |
| 122 | + regexp = Regexp.new(regexp) |
| 123 | + with_scope(selector) do |
| 124 | + if page.respond_to? :should |
| 125 | + page.should have_xpath('//*', :text => regexp) |
| 126 | + else |
| 127 | + assert page.has_xpath?('//*', :text => regexp) |
| 128 | + end |
| 129 | + end |
| 130 | +end |
| 131 | + |
| 132 | +Then /^(?:|I )should not see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector| |
| 133 | + with_scope(selector) do |
| 134 | + if page.respond_to? :should |
| 135 | + page.should have_no_content(text) |
| 136 | + else |
| 137 | + assert page.has_no_content?(text) |
| 138 | + end |
| 139 | + end |
| 140 | +end |
| 141 | + |
| 142 | +Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector| |
| 143 | + regexp = Regexp.new(regexp) |
| 144 | + with_scope(selector) do |
| 145 | + if page.respond_to? :should |
| 146 | + page.should have_no_xpath('//*', :text => regexp) |
| 147 | + else |
| 148 | + assert page.has_no_xpath?('//*', :text => regexp) |
| 149 | + end |
| 150 | + end |
| 151 | +end |
| 152 | + |
| 153 | +Then /^the "([^"]*)" field(?: within "([^"]*)")? should contain "([^"]*)"$/ do |field, selector, value| |
| 154 | + with_scope(selector) do |
| 155 | + field = find_field(field) |
| 156 | + field_value = (field.tag_name == 'textarea') ? field.text : field.value |
| 157 | + if field_value.respond_to? :should |
| 158 | + field_value.should =~ /#{value}/ |
| 159 | + else |
| 160 | + assert_match(/#{value}/, field_value) |
| 161 | + end |
| 162 | + end |
| 163 | +end |
| 164 | + |
| 165 | +Then /^the "([^"]*)" field(?: within "([^"]*)")? should not contain "([^"]*)"$/ do |field, selector, value| |
| 166 | + with_scope(selector) do |
| 167 | + field = find_field(field) |
| 168 | + field_value = (field.tag_name == 'textarea') ? field.text : field.value |
| 169 | + if field_value.respond_to? :should_not |
| 170 | + field_value.should_not =~ /#{value}/ |
| 171 | + else |
| 172 | + assert_no_match(/#{value}/, field_value) |
| 173 | + end |
| 174 | + end |
| 175 | +end |
| 176 | + |
| 177 | +Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should be checked$/ do |label, selector| |
| 178 | + with_scope(selector) do |
| 179 | + field_checked = find_field(label)['checked'] |
| 180 | + if field_checked.respond_to? :should |
| 181 | + field_checked.should be_true |
| 182 | + else |
| 183 | + assert field_checked |
| 184 | + end |
| 185 | + end |
| 186 | +end |
| 187 | + |
| 188 | +Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should not be checked$/ do |label, selector| |
| 189 | + with_scope(selector) do |
| 190 | + field_checked = find_field(label)['checked'] |
| 191 | + if field_checked.respond_to? :should |
| 192 | + field_checked.should be_false |
| 193 | + else |
| 194 | + assert !field_checked |
| 195 | + end |
| 196 | + end |
| 197 | +end |
| 198 | + |
| 199 | +Then /^(?:|I )should be on (.+)$/ do |page_name| |
| 200 | + current_path = URI.parse(current_url).path |
| 201 | + if current_path.respond_to? :should |
| 202 | + current_path.should == path_to(page_name) |
| 203 | + else |
| 204 | + assert_equal path_to(page_name), current_path |
| 205 | + end |
| 206 | +end |
| 207 | + |
| 208 | +Then /^(?:|I )should have the following query string:$/ do |expected_pairs| |
| 209 | + query = URI.parse(current_url).query |
| 210 | + actual_params = query ? CGI.parse(query) : {} |
| 211 | + expected_params = {} |
| 212 | + expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')} |
| 213 | + |
| 214 | + if actual_params.respond_to? :should |
| 215 | + actual_params.should == expected_params |
| 216 | + else |
| 217 | + assert_equal expected_params, actual_params |
| 218 | + end |
| 219 | +end |
| 220 | + |
| 221 | +Then /^I save and open the page$/ do |
| 222 | + save_and_open_page |
| 223 | +end |
| 224 | + |
| 225 | +Then /^show me the page$/ do |
| 226 | + save_and_open_page |
| 227 | +end |
0 commit comments