Commit fcd07561f1fd41020a56fdc45cda14fd96329d45
1 parent
b38611ef
Exists in
master
and in
29 other branches
Adding capybara steps
Showing
1 changed file
with
219 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,219 @@ |
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 )press "([^"]*)"(?: within "([^"]*)")?$/ do |button, selector| | |
28 | + with_scope(selector) do | |
29 | + click_button(button) | |
30 | + end | |
31 | +end | |
32 | + | |
33 | +When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector| | |
34 | + with_scope(selector) do | |
35 | + click_link(link) | |
36 | + end | |
37 | +end | |
38 | + | |
39 | +When /^(?:|I )fill in "([^"]*)" with "([^"]*)"(?: within "([^"]*)")?$/ do |field, value, selector| | |
40 | + with_scope(selector) do | |
41 | + fill_in(field, :with => value) | |
42 | + end | |
43 | +end | |
44 | + | |
45 | +When /^(?:|I )fill in "([^"]*)" for "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector| | |
46 | + with_scope(selector) do | |
47 | + fill_in(field, :with => value) | |
48 | + end | |
49 | +end | |
50 | + | |
51 | +# Use this to fill in an entire form with data from a table. Example: | |
52 | +# | |
53 | +# When I fill in the following: | |
54 | +# | Account Number | 5002 | | |
55 | +# | Expiry date | 2009-11-01 | | |
56 | +# | Note | Nice guy | | |
57 | +# | Wants Email? | | | |
58 | +# | |
59 | +# TODO: Add support for checkbox, select og option | |
60 | +# based on naming conventions. | |
61 | +# | |
62 | +When /^(?:|I )fill in the following(?: within "([^"]*)")?:$/ do |selector, fields| | |
63 | + with_scope(selector) do | |
64 | + fields.rows_hash.each do |name, value| | |
65 | + When %{I fill in "#{name}" with "#{value}"} | |
66 | + end | |
67 | + end | |
68 | +end | |
69 | + | |
70 | +When /^(?:|I )select "([^"]*)" from "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector| | |
71 | + with_scope(selector) do | |
72 | + select(value, :from => field) | |
73 | + end | |
74 | +end | |
75 | + | |
76 | +When /^(?:|I )check "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector| | |
77 | + with_scope(selector) do | |
78 | + check(field) | |
79 | + end | |
80 | +end | |
81 | + | |
82 | +When /^(?:|I )uncheck "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector| | |
83 | + with_scope(selector) do | |
84 | + uncheck(field) | |
85 | + end | |
86 | +end | |
87 | + | |
88 | +When /^(?:|I )choose "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector| | |
89 | + with_scope(selector) do | |
90 | + choose(field) | |
91 | + end | |
92 | +end | |
93 | + | |
94 | +When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"(?: within "([^"]*)")?$/ do |path, field, selector| | |
95 | + with_scope(selector) do | |
96 | + attach_file(field, path) | |
97 | + end | |
98 | +end | |
99 | + | |
100 | +Then /^(?:|I )should see JSON:$/ do |expected_json| | |
101 | + require 'json' | |
102 | + expected = JSON.pretty_generate(JSON.parse(expected_json)) | |
103 | + actual = JSON.pretty_generate(JSON.parse(response.body)) | |
104 | + expected.should == actual | |
105 | +end | |
106 | + | |
107 | +Then /^(?:|I )should see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector| | |
108 | + with_scope(selector) do | |
109 | + if page.respond_to? :should | |
110 | + page.should have_content(text) | |
111 | + else | |
112 | + assert page.has_content?(text) | |
113 | + end | |
114 | + end | |
115 | +end | |
116 | + | |
117 | +Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector| | |
118 | + regexp = Regexp.new(regexp) | |
119 | + with_scope(selector) do | |
120 | + if page.respond_to? :should | |
121 | + page.should have_xpath('//*', :text => regexp) | |
122 | + else | |
123 | + assert page.has_xpath?('//*', :text => regexp) | |
124 | + end | |
125 | + end | |
126 | +end | |
127 | + | |
128 | +Then /^(?:|I )should not see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector| | |
129 | + with_scope(selector) do | |
130 | + if page.respond_to? :should | |
131 | + page.should have_no_content(text) | |
132 | + else | |
133 | + assert page.has_no_content?(text) | |
134 | + end | |
135 | + end | |
136 | +end | |
137 | + | |
138 | +Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector| | |
139 | + regexp = Regexp.new(regexp) | |
140 | + with_scope(selector) do | |
141 | + if page.respond_to? :should | |
142 | + page.should have_no_xpath('//*', :text => regexp) | |
143 | + else | |
144 | + assert page.has_no_xpath?('//*', :text => regexp) | |
145 | + end | |
146 | + end | |
147 | +end | |
148 | + | |
149 | +Then /^the "([^"]*)" field(?: within "([^"]*)")? should contain "([^"]*)"$/ do |field, selector, value| | |
150 | + with_scope(selector) do | |
151 | + field = find_field(field) | |
152 | + field_value = (field.tag_name == 'textarea') ? field.text : field.value | |
153 | + if field_value.respond_to? :should | |
154 | + field_value.should =~ /#{value}/ | |
155 | + else | |
156 | + assert_match(/#{value}/, field_value) | |
157 | + end | |
158 | + end | |
159 | +end | |
160 | + | |
161 | +Then /^the "([^"]*)" field(?: within "([^"]*)")? should not contain "([^"]*)"$/ do |field, selector, value| | |
162 | + with_scope(selector) do | |
163 | + field = find_field(field) | |
164 | + field_value = (field.tag_name == 'textarea') ? field.text : field.value | |
165 | + if field_value.respond_to? :should_not | |
166 | + field_value.should_not =~ /#{value}/ | |
167 | + else | |
168 | + assert_no_match(/#{value}/, field_value) | |
169 | + end | |
170 | + end | |
171 | +end | |
172 | + | |
173 | +Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should be checked$/ do |label, selector| | |
174 | + with_scope(selector) do | |
175 | + field_checked = find_field(label)['checked'] | |
176 | + if field_checked.respond_to? :should | |
177 | + field_checked.should be_true | |
178 | + else | |
179 | + assert field_checked | |
180 | + end | |
181 | + end | |
182 | +end | |
183 | + | |
184 | +Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should not be checked$/ do |label, selector| | |
185 | + with_scope(selector) do | |
186 | + field_checked = find_field(label)['checked'] | |
187 | + if field_checked.respond_to? :should | |
188 | + field_checked.should be_false | |
189 | + else | |
190 | + assert !field_checked | |
191 | + end | |
192 | + end | |
193 | +end | |
194 | + | |
195 | +Then /^(?:|I )should be on (.+)$/ do |page_name| | |
196 | + current_path = URI.parse(current_url).path | |
197 | + if current_path.respond_to? :should | |
198 | + current_path.should == path_to(page_name) | |
199 | + else | |
200 | + assert_equal path_to(page_name), current_path | |
201 | + end | |
202 | +end | |
203 | + | |
204 | +Then /^(?:|I )should have the following query string:$/ do |expected_pairs| | |
205 | + query = URI.parse(current_url).query | |
206 | + actual_params = query ? CGI.parse(query) : {} | |
207 | + expected_params = {} | |
208 | + expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')} | |
209 | + | |
210 | + if actual_params.respond_to? :should | |
211 | + actual_params.should == expected_params | |
212 | + else | |
213 | + assert_equal expected_params, actual_params | |
214 | + end | |
215 | +end | |
216 | + | |
217 | +Then /^show me the page$/ do | |
218 | + save_and_open_page | |
219 | +end | ... | ... |