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 File . expand_path ( File . join ( File . dirname ( __FILE__ ) , ".." , "support" , "paths" ) )
9+
10+ module WithinHelpers
11+ def with_scope ( locator )
12+ within ( locator || 'html' ) { yield }
13+ end
14+ end
15+ World ( WithinHelpers )
16+
17+ Given /^(?:|I )am on (.+)$/ do |page_name |
18+ visit path_to ( page_name )
19+ end
20+
21+ When /^(?:|I )go to (.+)$/ do |page_name |
22+ visit path_to ( page_name )
23+ end
24+
25+ When /^(?:|I )press "([^\" ]*)"(?: within "([^\" ]*)")?$/ do |button , selector |
26+ with_scope ( selector ) do
27+ click_button ( button )
28+ end
29+ end
30+
31+ When /^(?:|I )follow "([^\" ]*)"(?: within "([^\" ]*)")?$/ do |link , selector |
32+ with_scope ( selector ) do
33+ click_link ( link )
34+ end
35+ end
36+
37+ When /^(?:|I )fill in "([^\" ]*)" with "([^\" ]*)"(?: within "([^\" ]*)")?$/ do |field , value , selector |
38+ with_scope ( selector ) do
39+ fill_in ( field , :with => value )
40+ end
41+ end
42+
43+ When /^(?:|I )fill in "([^\" ]*)" for "([^\" ]*)"(?: within "([^\" ]*)")?$/ do |value , field , selector |
44+ with_scope ( selector ) do
45+ fill_in ( field , :with => value )
46+ end
47+ end
48+
49+ # Use this to fill in an entire form with data from a table. Example:
50+ #
51+ # When I fill in the following:
52+ # | Account Number | 5002 |
53+ # | Expiry date | 2009-11-01 |
54+ # | Note | Nice guy |
55+ # | Wants Email? | |
56+ #
57+ # TODO: Add support for checkbox, select og option
58+ # based on naming conventions.
59+ #
60+ When /^(?:|I )fill in the following(?: within "([^\" ]*)"|)?:$/ do |fields , selector |
61+ with_scope ( selector ) do
62+ fields . rows_hash . each do |name , value |
63+ When %{I fill in "#{ name } " with "#{ value } "}
64+ end
65+ end
66+ end
67+
68+ When /^(?:|I )select "([^\" ]*)" from "([^\" ]*)"(?: within "([^\" ]*)")?$/ do |value , field , selector |
69+ with_scope ( selector ) do
70+ select ( value , :from => field )
71+ end
72+ end
73+
74+ When /^(?:|I )check "([^\" ]*)"(?: within "([^\" ]*)")?$/ do |field , selector |
75+ with_scope ( selector ) do
76+ check ( field )
77+ end
78+ end
79+
80+ When /^(?:|I )uncheck "([^\" ]*)"(?: within "([^\" ]*)")?$/ do |field , selector |
81+ with_scope ( selector ) do
82+ uncheck ( field )
83+ end
84+ end
85+
86+ When /^(?:|I )choose "([^\" ]*)"(?: within "([^\" ]*)")?$/ do |field , selector |
87+ with_scope ( selector ) do
88+ choose ( field )
89+ end
90+ end
91+
92+ When /^(?:|I )attach the file "([^\" ]*)" to "([^\" ]*)"(?: within "([^\" ]*)")?$/ do |path , field , selector |
93+ with_scope ( selector ) do
94+ attach_file ( field , path )
95+ end
96+ end
97+
98+ Then /^(?:|I )should see "([^\" ]*)"(?: within "([^\" ]*)")?$/ do |text , selector |
99+ with_scope ( selector ) do
100+ if defined? ( Spec ::Rails ::Matchers )
101+ page . should have_content ( text )
102+ else
103+ assert page . has_content? ( text )
104+ end
105+ end
106+ end
107+
108+ Then /^(?:|I )should see \/ ([^\/ ]*)\/ (?: within "([^\" ]*)")?$/ do |regexp , selector |
109+ regexp = Regexp . new ( regexp )
110+ with_scope ( selector ) do
111+ if defined? ( Spec ::Rails ::Matchers )
112+ page . should have_xpath ( '//*' , :text => regexp )
113+ else
114+ assert page . has_xpath? ( '//*' , :text => regexp )
115+ end
116+ end
117+ end
118+
119+ Then /^(?:|I )should not see "([^\" ]*)"(?: within "([^\" ]*)")?$/ do |text , selector |
120+ with_scope ( selector ) do
121+ if defined? ( Spec ::Rails ::Matchers )
122+ page . should_not have_content ( text )
123+ else
124+ assert_not page . has_content? ( text )
125+ end
126+ end
127+ end
128+
129+ Then /^(?:|I )should not see \/ ([^\/ ]*)\/ (?: within "([^\" ]*)")?$/ do |regexp , selector |
130+ regexp = Regexp . new ( regexp )
131+ with_scope ( selector ) do
132+ if defined? ( Spec ::Rails ::Matchers )
133+ page . should_not have_xpath ( '//*' , :text => regexp )
134+ else
135+ assert_not page . has_xpath? ( '//*' , :text => regexp )
136+ end
137+ end
138+ end
139+
140+ Then /^the "([^\" ]*)" field(?: within "([^\" ]*)")? should contain "([^\" ]*)"$/ do |field , selector , value |
141+ with_scope ( selector ) do
142+ if defined? ( Spec ::Rails ::Matchers )
143+ find_field ( field ) . value . should =~ /#{ value } /
144+ else
145+ assert_match ( /#{ value } / , field_labeled ( field ) . value )
146+ end
147+ end
148+ end
149+
150+ Then /^the "([^\" ]*)" field(?: within "([^\" ]*)")? should not contain "([^\" ]*)"$/ do |field , selector , value |
151+ with_scope ( selector ) do
152+ if defined? ( Spec ::Rails ::Matchers )
153+ find_field ( field ) . value . should_not =~ /#{ value } /
154+ else
155+ assert_no_match ( /#{ value } / , find_field ( field ) . value )
156+ end
157+ end
158+ end
159+
160+ Then /^the "([^\" ]*)" checkbox(?: within "([^\" ]*)")? should be checked$/ do |label , selector |
161+ with_scope ( selector ) do
162+ if defined? ( Spec ::Rails ::Matchers )
163+ find_field ( label ) [ 'checked' ] . should == 'checked'
164+ else
165+ assert field_labeled ( label ) [ 'checked' ] == 'checked'
166+ end
167+ end
168+ end
169+
170+ Then /^the "([^\" ]*)" checkbox(?: within "([^\" ]*)")? should not be checked$/ do |label , selector |
171+ with_scope ( selector ) do
172+ if defined? ( Spec ::Rails ::Matchers )
173+ find_field ( label ) [ 'checked' ] . should_not == 'checked'
174+ else
175+ assert field_labeled ( label ) [ 'checked' ] != 'checked'
176+ end
177+ end
178+ end
179+
180+ Then /^(?:|I )should be on (.+)$/ do |page_name |
181+ if defined? ( Spec ::Rails ::Matchers )
182+ URI . parse ( current_url ) . path . should == path_to ( page_name )
183+ else
184+ assert_equal path_to ( page_name ) , URI . parse ( current_url ) . path
185+ end
186+ end
187+
188+ Then /^show me the page$/ do
189+ save_and_open_page
190+ end
0 commit comments