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.
1+ # TL;DR: YOU SHOULD DELETE THIS FILE
2+ #
3+ # This file was generated by Cucumber-Rails and is only here to get you a head start
4+ # These step definitions are thin wrappers around the Capybara/Webrat API that lets you
5+ # visit pages, interact with widgets and make assertions about page content.
6+ #
7+ # If you use these step definitions as basis for your features you will quickly end up
8+ # with features that are:
9+ #
10+ # * Hard to maintain
11+ # * Verbose to read
12+ #
13+ # A much better approach is to write your own higher level step definitions, following
14+ # the advice in the following blog posts:
15+ #
16+ # * http://benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories.html
17+ # * http://dannorth.net/2011/01/31/whose-domain-is-it-anyway/
18+ # * http://elabs.se/blog/15-you-re-cuking-it-wrong
19+ #
620
721
822require 'uri'
923require 'cgi'
1024require File . expand_path ( File . join ( File . dirname ( __FILE__ ) , ".." , "support" , "paths" ) )
25+ require File . expand_path ( File . join ( File . dirname ( __FILE__ ) , ".." , "support" , "selectors" ) )
1126
1227module WithinHelpers
1328 def with_scope ( locator )
14- locator ? within ( locator ) { yield } : yield
29+ locator ? within ( * selector_for ( locator ) ) { yield } : yield
1530 end
1631end
1732World ( WithinHelpers )
1833
34+ # Single-line step scoper
35+ When /^(.*) within (.*[^:])$/ do |step , parent |
36+ with_scope ( parent ) { When step }
37+ end
38+
39+ # Multi-line step scoper
40+ When /^(.*) within (.*[^:]):$/ do |step , parent , table_or_string |
41+ with_scope ( parent ) { When "#{ step } :" , table_or_string }
42+ end
43+
1944Given /^(?:|I )am on (.+)$/ do |page_name |
2045 visit path_to ( page_name )
2146end
@@ -24,28 +49,20 @@ def with_scope(locator)
2449 visit path_to ( page_name )
2550end
2651
27- When /^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/ do |button , selector |
28- with_scope ( selector ) do
29- click_button ( button )
30- end
52+ When /^(?:|I )press "([^"]*)"$/ do |button |
53+ click_button ( button )
3154end
3255
33- When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link , selector |
34- with_scope ( selector ) do
35- click_link ( link )
36- end
56+ When /^(?:|I )follow "([^"]*)"$/ do |link |
57+ click_link ( link )
3758end
3859
39- When /^(?:|I )fill in "([^"]*)" with "([^"]*)"(?: within "([^"]*)")?$/ do |field , value , selector |
40- with_scope ( selector ) do
41- fill_in ( field , :with => value )
42- end
60+ When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field , value |
61+ fill_in ( field , :with => value )
4362end
4463
45- When /^(?:|I )fill in "([^"]*)" for "([^"]*)"(?: within "([^"]*)")?$/ do |value , field , selector |
46- with_scope ( selector ) do
47- fill_in ( field , :with => value )
48- end
64+ When /^(?:|I )fill in "([^"]*)" for "([^"]*)"$/ do |value , field |
65+ fill_in ( field , :with => value )
4966end
5067
5168# Use this to fill in an entire form with data from a table. Example:
@@ -59,95 +76,70 @@ def with_scope(locator)
5976# TODO: Add support for checkbox, select og option
6077# based on naming conventions.
6178#
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 )
79+ When /^(?:|I )fill in the following:$/ do |fields |
80+ fields . rows_hash . each do |name , value |
81+ When %{I fill in "#{ name } " with "#{ value } "}
7382 end
7483end
7584
76- When /^(?:|I )check "([^"]*)"(?: within "([^"]*)")?$/ do |field , selector |
77- with_scope ( selector ) do
78- check ( field )
79- end
85+ When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value , field |
86+ select ( value , :from => field )
8087end
8188
82- When /^(?:|I )uncheck "([^"]*)"(?: within "([^"]*)")?$/ do |field , selector |
83- with_scope ( selector ) do
84- uncheck ( field )
85- end
89+ When /^(?:|I )check "([^"]*)"$/ do |field |
90+ check ( field )
8691end
8792
88- When /^(?:|I )choose "([^"]*)"(?: within "([^"]*)")?$/ do |field , selector |
89- with_scope ( selector ) do
90- choose ( field )
91- end
93+ When /^(?:|I )uncheck "([^"]*)"$/ do |field |
94+ uncheck ( field )
9295end
9396
94- When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"(?: within "([^"]*)")?$/ do |path , field , selector |
95- with_scope ( selector ) do
96- attach_file ( field , path )
97- end
97+ When /^(?:|I )choose "([^"]*)"$/ do |field |
98+ choose ( field )
9899end
99100
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
101+ When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path , field |
102+ attach_file ( field , File . expand_path ( path ) )
105103end
106104
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
105+ Then /^(?:|I )should see "([^"]*)"$/ do |text |
106+ if page . respond_to? :should
107+ page . should have_content ( text )
108+ else
109+ assert page . has_content? ( text )
114110 end
115111end
116112
117- Then /^(?:|I )should see \/ ([^\/ ]*)\/ (?: within "([^"]*)")? $/ do |regexp , selector |
113+ Then /^(?:|I )should see \/ ([^\/ ]*)\/ $/ do |regexp |
118114 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
115+
116+ if page . respond_to? :should
117+ page . should have_xpath ( '//*' , :text => regexp )
118+ else
119+ assert page . has_xpath? ( '//*' , :text => regexp )
125120 end
126121end
127122
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
123+ Then /^(?:|I )should not see "([^"]*)"$/ do |text |
124+ if page . respond_to? :should
125+ page . should have_no_content ( text )
126+ else
127+ assert page . has_no_content? ( text )
135128 end
136129end
137130
138- Then /^(?:|I )should not see \/ ([^\/ ]*)\/ (?: within "([^"]*)")? $/ do |regexp , selector |
131+ Then /^(?:|I )should not see \/ ([^\/ ]*)\/ $/ do |regexp |
139132 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
133+
134+ if page . respond_to? :should
135+ page . should have_no_xpath ( '//*' , :text => regexp )
136+ else
137+ assert page . has_no_xpath? ( '//*' , :text => regexp )
146138 end
147139end
148140
149- Then /^the "([^"]*)" field(?: within "([^"]*)" )? should contain "([^"]*)"$/ do |field , selector , value |
150- with_scope ( selector ) do
141+ Then /^the "([^"]*)" field(?: within (.*) )? should contain "([^"]*)"$/ do |field , parent , value |
142+ with_scope ( parent ) do
151143 field = find_field ( field )
152144 field_value = ( field . tag_name == 'textarea' ) ? field . text : field . value
153145 if field_value . respond_to? :should
@@ -158,8 +150,8 @@ def with_scope(locator)
158150 end
159151end
160152
161- Then /^the "([^"]*)" field(?: within "([^"]*)" )? should not contain "([^"]*)"$/ do |field , selector , value |
162- with_scope ( selector ) do
153+ Then /^the "([^"]*)" field(?: within (.*) )? should not contain "([^"]*)"$/ do |field , parent , value |
154+ with_scope ( parent ) do
163155 field = find_field ( field )
164156 field_value = ( field . tag_name == 'textarea' ) ? field . text : field . value
165157 if field_value . respond_to? :should_not
@@ -170,8 +162,8 @@ def with_scope(locator)
170162 end
171163end
172164
173- Then /^the "([^"]*)" checkbox(?: within "([^"]*)" )? should be checked$/ do |label , selector |
174- with_scope ( selector ) do
165+ Then /^the "([^"]*)" checkbox(?: within (.*) )? should be checked$/ do |label , parent |
166+ with_scope ( parent ) do
175167 field_checked = find_field ( label ) [ 'checked' ]
176168 if field_checked . respond_to? :should
177169 field_checked . should be_true
@@ -181,8 +173,8 @@ def with_scope(locator)
181173 end
182174end
183175
184- Then /^the "([^"]*)" checkbox(?: within "([^"]*)" )? should not be checked$/ do |label , selector |
185- with_scope ( selector ) do
176+ Then /^the "([^"]*)" checkbox(?: within (.*) )? should not be checked$/ do |label , parent |
177+ with_scope ( parent ) do
186178 field_checked = find_field ( label ) [ 'checked' ]
187179 if field_checked . respond_to? :should
188180 field_checked . should be_false
0 commit comments