kelp 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +1 -1
- data/History.md +9 -0
- data/README.md +12 -5
- data/examples/sinatra_app/views/form.erb +26 -25
- data/examples/sinatra_app/views/home.erb +1 -1
- data/features/step_definitions/app_steps.rb +3 -3
- data/kelp.gemspec +1 -1
- data/lib/kelp/field.rb +85 -5
- data/lib/kelp/helper.rb +13 -0
- data/lib/kelp/navigation.rb +60 -2
- data/lib/kelp/scoping.rb +3 -2
- data/lib/kelp/visibility.rb +66 -1
- data/lib/kelp/xpath.rb +1 -1
- data/rails_generators/kelp/kelp_generator.rb +3 -2
- data/rails_generators/kelp/templates/capybara_steps.rb +2 -118
- data/rails_generators/kelp/templates/web_steps.rb +497 -0
- data/spec/field_spec.rb +45 -6
- data/spec/navigation_spec.rb +46 -3
- data/spec/visibility_spec.rb +80 -0
- metadata +5 -5
- data/rails_generators/kelp/templates/kelp_steps.rb +0 -256
data/Gemfile.lock
CHANGED
data/History.md
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
Kelp History
|
2
2
|
============
|
3
3
|
|
4
|
+
0.1.9
|
5
|
+
-----
|
6
|
+
|
7
|
+
- Fill-in methods now accept checkbox and dropdown fields
|
8
|
+
- Generated step definitions now replace those of cucumber-rails (web_steps.rb)
|
9
|
+
- should_be_on_page and should_have_query methods added
|
10
|
+
- should_see_button and should_not_see_button visibility methods added
|
11
|
+
|
12
|
+
|
4
13
|
0.1.8
|
5
14
|
-----
|
6
15
|
|
data/README.md
CHANGED
@@ -97,13 +97,20 @@ for more information.
|
|
97
97
|
Rails generator
|
98
98
|
---------------
|
99
99
|
|
100
|
-
Kelp provides a generator for Rails 2.x projects,
|
101
|
-
|
100
|
+
Kelp provides a generator for Rails 2.x projects, which writes step definitions
|
101
|
+
to `features/step_definitions/web_steps.rb`. This file provides all of the same
|
102
|
+
step definitions normally provided by
|
103
|
+
[cucumber-rails](http://github.com/aslakhellesoy/cucumber-rails), with several
|
104
|
+
enhancements. If you have made customizations to your `web_steps.rb`, they will
|
105
|
+
be overwritten! Consider yourself warned.
|
106
|
+
|
107
|
+
To generate `web_steps.rb`, simply run:
|
102
108
|
|
103
109
|
$ script/generate kelp
|
104
110
|
|
105
|
-
|
106
|
-
|
111
|
+
*Note*: If you are upgrading from a version of Kelp prior to 0.1.9, you should
|
112
|
+
remove `kelp_steps.rb` from your `features/step_definitions` directory; these
|
113
|
+
are obsolete, and conflict with the newer step definitions in `web_steps.rb`.
|
107
114
|
|
108
115
|
A Rails 3.x generator is not currently provided. Contributions are welcome!
|
109
116
|
|
@@ -142,7 +149,7 @@ Kelp comes with a `Rakefile`, so you can run the RSpec tests and generate an
|
|
142
149
|
$ rake spec
|
143
150
|
|
144
151
|
This will write an HTML report to `coverage/index.html`. Finally, there are
|
145
|
-
some Cucumber self-tests included, mainly for testing the `
|
152
|
+
some Cucumber self-tests included, mainly for testing the `web_steps.rb`
|
146
153
|
file used by the Rails generator. Run via:
|
147
154
|
|
148
155
|
$ rake cucumber
|
@@ -33,14 +33,12 @@
|
|
33
33
|
<option value="heavy">Heavy</option>
|
34
34
|
</select>
|
35
35
|
</p>
|
36
|
-
<p>
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
</select>
|
43
|
-
</p>
|
36
|
+
<p><button value="Submit person form" /></p>
|
37
|
+
</div>
|
38
|
+
</form>
|
39
|
+
|
40
|
+
<div id="preferences_form">
|
41
|
+
<form action="/thanks" method="get">
|
44
42
|
<p>
|
45
43
|
<label for="favorite_colors">Favorite Colors</label>
|
46
44
|
<select id="favorite_colors" multiple="multiple">
|
@@ -57,23 +55,6 @@
|
|
57
55
|
<label for="like_salami">I like salami</label>
|
58
56
|
<input id="like_salami" type="checkbox" />
|
59
57
|
</p>
|
60
|
-
<p>
|
61
|
-
<label for="message">Message</label>
|
62
|
-
<input id="message" type="text" value="Your message goes here" />
|
63
|
-
</p>
|
64
|
-
<p><input type="submit" value="Submit" /></p>
|
65
|
-
</form>
|
66
|
-
</div>
|
67
|
-
|
68
|
-
<div id="other_form">
|
69
|
-
<form action="/thanks" method="get">
|
70
|
-
<p><input id="readonly" type="text" disabled="disabled" /></p>
|
71
|
-
<p><input type="submit" value="Submit" disabled="disabled" /></p>
|
72
|
-
</form>
|
73
|
-
</div>
|
74
|
-
|
75
|
-
<div id="checkbox_form">
|
76
|
-
<form action="/thanks" method="get">
|
77
58
|
<table>
|
78
59
|
<tr>
|
79
60
|
<th>Apple</th>
|
@@ -90,6 +71,26 @@
|
|
90
71
|
</td>
|
91
72
|
</tr>
|
92
73
|
</table>
|
74
|
+
<p>
|
75
|
+
<label for="message">Message</label>
|
76
|
+
<input id="message" type="text" value="Your message goes here" />
|
77
|
+
</p>
|
78
|
+
<p><input type="submit" value="Save preferences" /></p>
|
79
|
+
</form>
|
80
|
+
</div>
|
81
|
+
|
82
|
+
<div id="other_form">
|
83
|
+
<form action="/thanks" method="get">
|
84
|
+
<p>
|
85
|
+
<label for="quotes">Quotes</label>
|
86
|
+
<select id="quotes">
|
87
|
+
<option value="1">Single 'quotes'</option>
|
88
|
+
<option value="2">"Double" quotes</option>
|
89
|
+
<option value="3">'Single' and "Double" quotes</option>
|
90
|
+
</select>
|
91
|
+
</p>
|
92
|
+
<p><input id="readonly" type="text" disabled="disabled" /></p>
|
93
|
+
<p><input type="submit" value="Save is disabled" disabled="disabled" /></p>
|
93
94
|
</form>
|
94
95
|
</div>
|
95
96
|
|
@@ -4,9 +4,9 @@ require 'fileutils'
|
|
4
4
|
|
5
5
|
Given /^the latest Kelp step definitions$/ do
|
6
6
|
app_dir = File.join(root_dir, 'examples', "sinatra_app")
|
7
|
-
installed_steps = File.join(app_dir, 'features', 'step_definitions', '
|
8
|
-
latest_steps = File.join(root_dir, 'rails_generators', 'kelp', 'templates', '
|
9
|
-
# Remove the installed
|
7
|
+
installed_steps = File.join(app_dir, 'features', 'step_definitions', 'web_steps.rb')
|
8
|
+
latest_steps = File.join(root_dir, 'rails_generators', 'kelp', 'templates', 'web_steps.rb')
|
9
|
+
# Remove the installed web_steps.rb, if any, then install the latest one
|
10
10
|
FileUtils.mkdir_p(File.dirname(installed_steps))
|
11
11
|
FileUtils.rm(installed_steps) if File.exists?(installed_steps)
|
12
12
|
FileUtils.cp_r(latest_steps, installed_steps)
|
data/kelp.gemspec
CHANGED
data/lib/kelp/field.rb
CHANGED
@@ -9,27 +9,99 @@ module Kelp
|
|
9
9
|
include Scoping
|
10
10
|
include Helper
|
11
11
|
|
12
|
+
# Select a value from a dropdown or listbox, or fill in a text field,
|
13
|
+
# depending on what kind of form field is available. If `field` is a
|
14
|
+
# dropdown or listbox, select `value` from that; otherwise, assume
|
15
|
+
# `field` is a text box.
|
16
|
+
#
|
17
|
+
# @param [String] field
|
18
|
+
# Capybara locator for the field (name, id, or label text)
|
19
|
+
# @param [String] value
|
20
|
+
# Text to select from a dropdown or enter in a text box
|
21
|
+
#
|
22
|
+
# @since 0.1.9
|
23
|
+
#
|
24
|
+
def select_or_fill(field, value)
|
25
|
+
begin
|
26
|
+
select(value, :from => field)
|
27
|
+
rescue
|
28
|
+
fill_in(field, :with => value)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
# Check a checkbox, select from a dropdown or listbox, or fill in a text
|
34
|
+
# field, depending on what kind of form field is available. If value
|
35
|
+
# is `checked` or `unchecked`, assume `field` is a checkbox; otherwise,
|
36
|
+
# fall back on {#select_or_fill}.
|
37
|
+
#
|
38
|
+
# @param [String] field
|
39
|
+
# Capybara locator for the field (name, id, or label text)
|
40
|
+
# @param [String] value
|
41
|
+
# Text to select from a dropdown or enter in a text box, or
|
42
|
+
# `checked` or `unchecked` to operate on a checkbox
|
43
|
+
#
|
44
|
+
# @since 0.1.9
|
45
|
+
#
|
46
|
+
def check_or_select_or_fill(field, value)
|
47
|
+
# If value is "checked" or "unchecked", assume
|
48
|
+
# field is a checkbox
|
49
|
+
if value == "checked"
|
50
|
+
begin
|
51
|
+
check(field)
|
52
|
+
rescue
|
53
|
+
select_or_fill(field, value)
|
54
|
+
end
|
55
|
+
elsif value == "unchecked"
|
56
|
+
begin
|
57
|
+
uncheck(field)
|
58
|
+
rescue
|
59
|
+
select_or_fill(field, value)
|
60
|
+
end
|
61
|
+
else
|
62
|
+
select_or_fill(field, value)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
12
67
|
# Fill in multiple fields according to values in a `Hash`.
|
68
|
+
# Fields may be text boxes, dropdowns/listboxes, or checkboxes.
|
69
|
+
# See {#check_or_select_or_fill} for details.
|
13
70
|
#
|
14
71
|
# @example
|
15
72
|
# fill_in_fields "First name" => "Otto", "Last name" => "Scratchansniff"
|
16
73
|
# fill_in_fields "phone" => "303-224-7428", :within => "#home"
|
17
74
|
#
|
18
|
-
# @param [Hash]
|
19
|
-
# "field" => "value" for each field to fill in
|
75
|
+
# @param [Hash] field_values
|
76
|
+
# "field" => "value" for each field to fill in, select, or check/uncheck
|
20
77
|
# @param [Hash] scope
|
21
78
|
# Scoping keywords as understood by {#in_scope}
|
22
79
|
#
|
23
|
-
def fill_in_fields(
|
80
|
+
def fill_in_fields(field_values, scope={})
|
24
81
|
in_scope(scope) do
|
25
|
-
|
26
|
-
|
82
|
+
field_values.each do |field, value|
|
83
|
+
check_or_select_or_fill(field, value)
|
27
84
|
end
|
28
85
|
end
|
29
86
|
end
|
30
87
|
|
31
88
|
|
32
89
|
# Fill in a single field within the scope of a given selector.
|
90
|
+
# The field may be a text box, dropdown/listbox, or checkbox.
|
91
|
+
# See {#check_or_select_or_fill} for details.
|
92
|
+
#
|
93
|
+
# @example
|
94
|
+
# fill_in_field "Email", "otto@scratchansniff.wb"
|
95
|
+
# fill_in_field "Send me junk email", "unchecked"
|
96
|
+
#
|
97
|
+
# @param [String] field
|
98
|
+
# Capybara locator for the field (name, id, or label text)
|
99
|
+
# @param [String] value
|
100
|
+
# Text to select from a dropdown or enter in a text box, or
|
101
|
+
# `checked` or `unchecked` to operate on a checkbox
|
102
|
+
# @param [Hash] scope
|
103
|
+
# Scoping keywords as understood by {#in_scope}
|
104
|
+
#
|
33
105
|
def fill_in_field(field, value, scope={})
|
34
106
|
fields = {field => value}
|
35
107
|
fill_in_fields fields, scope
|
@@ -57,6 +129,12 @@ module Kelp
|
|
57
129
|
|
58
130
|
|
59
131
|
# Verify that the given field is empty or nil.
|
132
|
+
#
|
133
|
+
# @param [String] field
|
134
|
+
# Capybara locator for the field (name, id, or label text)
|
135
|
+
# @param [Hash] scope
|
136
|
+
# Scoping keywords as understood by {#in_scope}
|
137
|
+
#
|
60
138
|
def field_should_be_empty(field, scope={})
|
61
139
|
in_scope(scope) do
|
62
140
|
_field = nice_find_field(field)
|
@@ -73,6 +151,8 @@ module Kelp
|
|
73
151
|
# Capybara locator for the field (name, id, or label text)
|
74
152
|
# @param [String] value
|
75
153
|
# Value you expect to see in the text field
|
154
|
+
# @param [Hash] scope
|
155
|
+
# Scoping keywords as understood by {#in_scope}
|
76
156
|
#
|
77
157
|
def field_should_contain(field, value, scope={})
|
78
158
|
in_scope(scope) do
|
data/lib/kelp/helper.rb
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
module Kelp
|
2
2
|
module Helper
|
3
|
+
# Convert a Cucumber::Ast::Table or multiline string into
|
4
|
+
# a list of strings
|
5
|
+
def listify(items)
|
6
|
+
if items.class == Cucumber::Ast::Table
|
7
|
+
strings = items.raw.flatten
|
8
|
+
else
|
9
|
+
strings = items.split(/[\r\n]+/)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
|
3
14
|
# A slightly friendlier version of Capybara's `find_field`, which actually
|
4
15
|
# tells you which locator failed to match (instead of giving a useless
|
5
16
|
# Unable to find '#<XPath::Union:0xXXXXXXX>' message).
|
@@ -11,6 +22,7 @@ module Kelp
|
|
11
22
|
end
|
12
23
|
end
|
13
24
|
|
25
|
+
|
14
26
|
# Return the appropriate "ExpectationNotMetError" class for the current
|
15
27
|
# version of RSpec
|
16
28
|
def rspec_unexpected
|
@@ -20,5 +32,6 @@ module Kelp
|
|
20
32
|
Spec::Expectations::ExpectationNotMetError
|
21
33
|
end
|
22
34
|
end
|
35
|
+
|
23
36
|
end
|
24
37
|
end
|
data/lib/kelp/navigation.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'cgi'
|
1
3
|
require 'kelp/scoping'
|
2
4
|
require 'kelp/xpath'
|
3
5
|
|
4
6
|
module Kelp
|
5
7
|
# This module defines helper methods for navigating a webpage, including
|
6
|
-
# clicking links and pressing buttons
|
8
|
+
# clicking links and pressing buttons, and for verifying the current
|
9
|
+
# page's path and query parameters.
|
7
10
|
#
|
8
11
|
module Navigation
|
9
12
|
include Scoping
|
10
|
-
include
|
13
|
+
include XPaths
|
11
14
|
|
12
15
|
# Follow a link on the page.
|
13
16
|
#
|
@@ -59,5 +62,60 @@ module Kelp
|
|
59
62
|
row.click_link(link)
|
60
63
|
end
|
61
64
|
|
65
|
+
|
66
|
+
# Verify that the current page matches the path of `page_name_or_path`. The
|
67
|
+
# cucumber-generated `path_to` function will be used, if it's defined, to
|
68
|
+
# translate human-readable names into URL paths. Otherwise, assume a raw,
|
69
|
+
# absolute path string.
|
70
|
+
#
|
71
|
+
# @example
|
72
|
+
# should_be_on_page 'home page'
|
73
|
+
# should_be_on_page '/admin/login'
|
74
|
+
#
|
75
|
+
# @param [String] page_name_or_path
|
76
|
+
# Human-readable page name (mapped to a pathname by your `path_to` function),
|
77
|
+
# or an absolute path beginning with `/`.
|
78
|
+
#
|
79
|
+
# @since 0.1.9
|
80
|
+
#
|
81
|
+
def should_be_on_page(page_name_or_path)
|
82
|
+
# Use the path_to translator function if it's defined
|
83
|
+
# (normally in features/support/paths.rb)
|
84
|
+
if defined? path_to
|
85
|
+
expect_path = path_to(page_name_or_path)
|
86
|
+
# Otherwise, expect a raw path string
|
87
|
+
else
|
88
|
+
expect_path = page_name_or_path
|
89
|
+
end
|
90
|
+
actual_path = URI.parse(current_url).path
|
91
|
+
if actual_path.respond_to? :should
|
92
|
+
actual_path.should == expect_path
|
93
|
+
else
|
94
|
+
assert_equal actual_path, expect_path
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
# Verify that the current page has the given query parameters.
|
100
|
+
#
|
101
|
+
# @param [Hash] params
|
102
|
+
# Key => value parameters, as they would appear in the URL
|
103
|
+
#
|
104
|
+
# @since 0.1.9
|
105
|
+
#
|
106
|
+
def should_have_query(params)
|
107
|
+
query = URI.parse(current_url).query
|
108
|
+
actual_params = query ? CGI.parse(query) : {}
|
109
|
+
expected_params = {}
|
110
|
+
params.each_pair do |k,v|
|
111
|
+
expected_params[k] = v.split(',')
|
112
|
+
end
|
113
|
+
if actual_params.respond_to? :should
|
114
|
+
actual_params.should == expected_params
|
115
|
+
else
|
116
|
+
assert_equal expected_params, actual_params
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
62
120
|
end
|
63
121
|
end
|
data/lib/kelp/scoping.rb
CHANGED
@@ -8,7 +8,8 @@ module Kelp
|
|
8
8
|
# assumed to be a CSS selector.
|
9
9
|
def scope_within(locator)
|
10
10
|
if locator
|
11
|
-
# Use the selector_for method if it's defined
|
11
|
+
# Use the selector_for method if it's defined. This may be provided
|
12
|
+
# by features/support/selectors.rb, generated by cucumber-rails.
|
12
13
|
if defined? selector_for
|
13
14
|
within(*selector_for(locator)) { yield }
|
14
15
|
# Otherwise, remove any surrounding double-quotes
|
@@ -32,7 +33,7 @@ module Kelp
|
|
32
33
|
#
|
33
34
|
# @example
|
34
35
|
# in_scope :within => '#footer'
|
35
|
-
#
|
36
|
+
# click_link "Contact Us"
|
36
37
|
# end
|
37
38
|
#
|
38
39
|
# @param [Hash] scope
|
data/lib/kelp/visibility.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'xpath'
|
1
2
|
require 'kelp/scoping'
|
2
3
|
require 'kelp/xpath'
|
3
4
|
require 'kelp/exceptions'
|
@@ -9,7 +10,7 @@ module Kelp
|
|
9
10
|
#
|
10
11
|
module Visibility
|
11
12
|
include Scoping
|
12
|
-
include
|
13
|
+
include XPaths
|
13
14
|
|
14
15
|
# Verify the presence of content on the page. Passes when all the given items
|
15
16
|
# are found on the page, and fails if any of them are not found.
|
@@ -25,6 +26,9 @@ module Kelp
|
|
25
26
|
# @param [Hash] scope
|
26
27
|
# Scoping keywords as understood by {#in_scope}
|
27
28
|
#
|
29
|
+
# @raise [Kelp::Unexpected]
|
30
|
+
# If any of the expected text strings are not seen in the given scope
|
31
|
+
#
|
28
32
|
def should_see(texts, scope={})
|
29
33
|
texts = [texts] if (texts.class == String || texts.class == Regexp)
|
30
34
|
unexpected = []
|
@@ -52,6 +56,9 @@ module Kelp
|
|
52
56
|
# @param [Hash] scope
|
53
57
|
# Scoping keywords as understood by {#in_scope}
|
54
58
|
#
|
59
|
+
# @raise [Kelp::Unexpected]
|
60
|
+
# If any of the expected text strings are seen in the given scope
|
61
|
+
#
|
55
62
|
def should_not_see(texts, scope={})
|
56
63
|
texts = [texts] if (texts.class == String || texts.class == Regexp)
|
57
64
|
unexpected = []
|
@@ -248,6 +255,64 @@ module Kelp
|
|
248
255
|
end
|
249
256
|
end
|
250
257
|
|
258
|
+
|
259
|
+
# Verify that a button with the given text appears on the page.
|
260
|
+
# Works for `<input...>` as well as `<button...>` elements.
|
261
|
+
#
|
262
|
+
# @example
|
263
|
+
# should_see_button "Submit"
|
264
|
+
# should_see_button "Save changes", :within => "#preferences"
|
265
|
+
#
|
266
|
+
# @param [String] button_text
|
267
|
+
# Visible button text to look for
|
268
|
+
# @param [Hash] scope
|
269
|
+
# Scoping keywords as understood by {#in_scope}
|
270
|
+
#
|
271
|
+
# @raise [Kelp::Unexpected]
|
272
|
+
# If no button with the given text exists in the given scope
|
273
|
+
#
|
274
|
+
# @since 0.1.9
|
275
|
+
#
|
276
|
+
def should_see_button(button_text, scope={})
|
277
|
+
in_scope(scope) do
|
278
|
+
xpath = XPath::HTML.button(button_text)
|
279
|
+
begin
|
280
|
+
page.should have_xpath(xpath)
|
281
|
+
rescue rspec_unexpected
|
282
|
+
raise Kelp::Unexpected, "Expected to see button '#{button_text}', but button does not exist."
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
|
288
|
+
# Verify that a button with the given text does not appear on the page.
|
289
|
+
# Works for `<input...>` as well as `<button...>` elements.
|
290
|
+
#
|
291
|
+
# @example
|
292
|
+
# should_not_see_button "Delete"
|
293
|
+
# should_not_see_button "Save changes", :within => "#read_only"
|
294
|
+
#
|
295
|
+
# @param [String] button_text
|
296
|
+
# Visible button text to look for
|
297
|
+
# @param [Hash] scope
|
298
|
+
# Scoping keywords as understood by {#in_scope}
|
299
|
+
#
|
300
|
+
# @raise [Kelp::Unexpected]
|
301
|
+
# If a button with the given text does exist in the given scope
|
302
|
+
#
|
303
|
+
# @since 0.1.9
|
304
|
+
#
|
305
|
+
def should_not_see_button(button_text, scope={})
|
306
|
+
in_scope(scope) do
|
307
|
+
xpath = XPath::HTML.button(button_text)
|
308
|
+
begin
|
309
|
+
page.should have_no_xpath(xpath)
|
310
|
+
rescue rspec_unexpected
|
311
|
+
raise Kelp::Unexpected, "Did not expect to see button '#{button_text}', but button exists."
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
251
316
|
end
|
252
317
|
end
|
253
318
|
|
data/lib/kelp/xpath.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
# This generator adds
|
1
|
+
# This generator adds web_steps.rb to the step_definitions directory,
|
2
|
+
# replacing any web_steps.rb added by cucumber-rails.
|
2
3
|
|
3
4
|
generator_base = defined?(Rails) ? Rails::Generator::Base : RubiGen::Base
|
4
5
|
|
@@ -6,7 +7,7 @@ class KelpGenerator < generator_base
|
|
6
7
|
def manifest
|
7
8
|
record do |m|
|
8
9
|
m.directory 'features/step_definitions'
|
9
|
-
m.file '
|
10
|
+
m.file 'web_steps.rb', 'features/step_definitions/web_steps.rb'
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
@@ -1,7 +1,6 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
require
|
4
|
-
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
|
2
|
+
# May not be needed?
|
3
|
+
#require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
|
5
4
|
#require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "selectors"))
|
6
5
|
|
7
6
|
# Single-line step scoper
|
@@ -14,119 +13,4 @@ When /^(.*) within ([^:]+):$/ do |step, parent, table_or_string|
|
|
14
13
|
scope_within(parent) { When "#{step}:", table_or_string }
|
15
14
|
end
|
16
15
|
|
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 "([^"]*)"$/ do |button|
|
26
|
-
click_button button
|
27
|
-
end
|
28
|
-
|
29
|
-
When /^(?:|I )follow "([^"]*)"$/ do |link|
|
30
|
-
click_link link
|
31
|
-
end
|
32
|
-
|
33
|
-
When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
|
34
|
-
fill_in field, :with => value
|
35
|
-
end
|
36
|
-
|
37
|
-
When /^(?:|I )fill in "([^"]*)" for "([^"]*)"$/ do |value, field|
|
38
|
-
fill_in field, :with => value
|
39
|
-
end
|
40
|
-
|
41
|
-
# Use this to fill in an entire form with data from a table. Example:
|
42
|
-
#
|
43
|
-
# When I fill in the following:
|
44
|
-
# | Account Number | 5002 |
|
45
|
-
# | Expiry date | 2009-11-01 |
|
46
|
-
# | Note | Nice guy |
|
47
|
-
# | Wants Email? | |
|
48
|
-
#
|
49
|
-
# TODO: Add support for checkbox, select og option
|
50
|
-
# based on naming conventions.
|
51
|
-
#
|
52
|
-
When /^(?:|I )fill in the following:$/ do |fields|
|
53
|
-
fill_in_fields fields.rows_hash
|
54
|
-
end
|
55
|
-
|
56
|
-
When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field|
|
57
|
-
select value, :from => field
|
58
|
-
end
|
59
|
-
|
60
|
-
When /^(?:|I )check "([^"]*)"$/ do |field|
|
61
|
-
check field
|
62
|
-
end
|
63
|
-
|
64
|
-
When /^(?:|I )uncheck "([^"]*)"$/ do |field|
|
65
|
-
uncheck field
|
66
|
-
end
|
67
|
-
|
68
|
-
When /^(?:|I )choose "([^"]*)"$/ do |field|
|
69
|
-
choose field
|
70
|
-
end
|
71
|
-
|
72
|
-
When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
|
73
|
-
attach_file field, File.expand_path(path)
|
74
|
-
end
|
75
16
|
|
76
|
-
Then /^(?:|I )should see "([^"]*)"$/ do |text|
|
77
|
-
should_see text
|
78
|
-
end
|
79
|
-
|
80
|
-
Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
|
81
|
-
should_see Regexp.new(regexp)
|
82
|
-
end
|
83
|
-
|
84
|
-
Then /^(?:|I )should not see "([^"]*)"$/ do |text|
|
85
|
-
should_not_see text
|
86
|
-
end
|
87
|
-
|
88
|
-
Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
|
89
|
-
should_not_see Regexp.new(regexp)
|
90
|
-
end
|
91
|
-
|
92
|
-
Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
|
93
|
-
field_should_contain field, value, :within => parent
|
94
|
-
end
|
95
|
-
|
96
|
-
Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value|
|
97
|
-
field_should_not_contain field, value, :within => parent
|
98
|
-
end
|
99
|
-
|
100
|
-
Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent|
|
101
|
-
checkbox_should_be_checked label, :within => parent
|
102
|
-
end
|
103
|
-
|
104
|
-
Then /^the "([^"]*)" checkbox(?: within (.*))? should not be checked$/ do |label, parent|
|
105
|
-
checkbox_should_not_be_checked label, :within => parent
|
106
|
-
end
|
107
|
-
|
108
|
-
Then /^(?:|I )should be on (.+)$/ do |page_name|
|
109
|
-
current_path = URI.parse(current_url).path
|
110
|
-
if current_path.respond_to? :should
|
111
|
-
current_path.should == path_to(page_name)
|
112
|
-
else
|
113
|
-
assert_equal path_to(page_name), current_path
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
|
118
|
-
query = URI.parse(current_url).query
|
119
|
-
actual_params = query ? CGI.parse(query) : {}
|
120
|
-
expected_params = {}
|
121
|
-
expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
|
122
|
-
|
123
|
-
if actual_params.respond_to? :should
|
124
|
-
actual_params.should == expected_params
|
125
|
-
else
|
126
|
-
assert_equal expected_params, actual_params
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
Then /^show me the page$/ do
|
131
|
-
save_and_open_page
|
132
|
-
end
|