mechanical-cuke 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.textile +21 -27
- data/VERSION +1 -1
- data/features/web_steps.feature +13 -0
- data/lib/mechanical-cuke.rb +36 -8
- data/lib/mechanical-cuke/web_steps.rb +47 -0
- data/test/fixtures/server/views/form.erb +11 -1
- data/test/fixtures/server/views/form_output.erb +9 -0
- metadata +2 -2
data/.gitignore
CHANGED
data/README.textile
CHANGED
@@ -1,16 +1,10 @@
|
|
1
|
-
h1.
|
1
|
+
h1. Mechanical Cuke
|
2
2
|
|
3
|
-
mechanical-cuke re-implements the Cucumber step definitions provided
|
4
|
-
by cucumber-rails in web_steps.rb in Mechanize. This allows Cucumber
|
5
|
-
features to be written for any site by running the tests over HTTP.
|
3
|
+
mechanical-cuke re-implements the Cucumber step definitions provided by cucumber-rails' web_steps.rb in Mechanize. This allows Cucumber features to be written for any site by running the tests over HTTP.
|
6
4
|
|
7
5
|
h2. Rational
|
8
6
|
|
9
|
-
Webrat and Capybara both can drive tests over HTML. However, Webrat's
|
10
|
-
Mechanize support is limited (doesn't work with multipart forms, can't
|
11
|
-
submit empty form fields, no support for basis auth). Capybara drives
|
12
|
-
tests over HTTP using browsers, excellent for testing Javascript, but
|
13
|
-
slow for test that only involve HTML.
|
7
|
+
Webrat and Capybara both can drive tests over HTML. However, Webrat's Mechanize support is limited (doesn't work with multipart forms, can't submit empty form fields, no support for basic auth). Capybara drives tests over HTTP using browsers, excellent for testing Javascript, but slow for test that only involve HTML.
|
14
8
|
|
15
9
|
h2. Usage
|
16
10
|
|
@@ -20,9 +14,7 @@ Add:
|
|
20
14
|
|
21
15
|
to features/support/env.rb
|
22
16
|
|
23
|
-
In features/support/paths.rb you will need to make sure you are
|
24
|
-
returning the full URL. The simplest way to do this is to add 'URL' +
|
25
|
-
before the case statement in the path_to function e.g.:
|
17
|
+
In features/support/paths.rb you will need to make sure you are returning the full URL. The simplest way to do this is to add 'URL' + before the case statement in the path_to function e.g.:
|
26
18
|
|
27
19
|
bc. def path_to(page_name)
|
28
20
|
case page_name
|
@@ -42,7 +34,7 @@ GET the page at _path_ and sets it to the current page for follow steps.
|
|
42
34
|
|
43
35
|
bc. When I press "button"
|
44
36
|
|
45
|
-
Press button with label "_button_". If the button is in a form
|
37
|
+
Press button with label "_button_". If the button is in a form the form is submitted.
|
46
38
|
|
47
39
|
bc. When I follow "link"
|
48
40
|
|
@@ -51,9 +43,7 @@ Click the link with text "_link_".
|
|
51
43
|
bc. When I fill in "field" with "value"
|
52
44
|
When I fill in "value" for "field"
|
53
45
|
|
54
|
-
Fill in the text field, password field, or text area _field_ with
|
55
|
-
_value_. _field_ can be the id or name of the field, or the text
|
56
|
-
within the label for the field.
|
46
|
+
Fill in the text field, password field, or text area _field_ with _value_. _field_ can be the id or name of the field, or the text within the label for the field.
|
57
47
|
|
58
48
|
bc. When I fill in the following:
|
59
49
|
|
@@ -67,23 +57,20 @@ bc. When I fill in the following:
|
|
67
57
|
|
68
58
|
bc. When I select "value" from "field"
|
69
59
|
|
70
|
-
Selects the option with _value_ from select list _field_. _field_ can
|
71
|
-
be the id or name of the field, or the text within the label for the
|
72
|
-
field.
|
60
|
+
Selects the option with _value_ from select list _field_. _field_ can be the id or name of the field, or the text within the label for the field.
|
73
61
|
|
74
62
|
bc. When I check "field"
|
75
63
|
When I uncheck "field"
|
76
64
|
|
77
|
-
Check or uncheck "_field_".
|
65
|
+
Check or uncheck the checkbox "_field_".
|
78
66
|
|
79
67
|
bc. When I choose "field"
|
80
68
|
|
81
|
-
Checks radio button _field_. _field_ can be the id or the text within
|
82
|
-
the label for the field; the field name would be ambiguous.
|
69
|
+
Checks radio button _field_. _field_ can be the id or the text within the label for the field; the field name would be ambiguous.
|
83
70
|
|
84
71
|
When I attach the file "path" to "field"
|
85
72
|
|
86
|
-
Attach the file in _path_ to the file field _field_.
|
73
|
+
Attach the file in _path_ to the file field _field_.
|
87
74
|
|
88
75
|
bc. Then I should see "text"
|
89
76
|
Then I should see /regexp/
|
@@ -98,12 +85,12 @@ The body of the page should *not* contain _text_ or _regexp_.
|
|
98
85
|
bc. Then the "field" field should contain "value"
|
99
86
|
Then the "field" field should not contain "value"
|
100
87
|
|
101
|
-
The value _field_ should be (or not be) _value_.
|
88
|
+
The value _field_ should be (or not be) _value_.
|
102
89
|
|
103
90
|
bc. Then the "_field_" checkbox should be checked
|
104
91
|
Then the "_field_" checkbox not should be checked
|
105
92
|
|
106
|
-
The checkbox _field_ should be (or not be) checked.
|
93
|
+
The checkbox _field_ should be (or not be) checked.
|
107
94
|
|
108
95
|
bc. Then I should be on _path_
|
109
96
|
|
@@ -113,7 +100,14 @@ bc. Then show me the page
|
|
113
100
|
|
114
101
|
Save the current page and open in the default browser.
|
115
102
|
|
116
|
-
h2.
|
103
|
+
h2. Todo
|
117
104
|
|
118
|
-
|
105
|
+
Add scopes to allow steps to function within an element e.g:
|
106
|
+
|
107
|
+
bc. When I press "Submit" within "#login_form"
|
108
|
+
|
109
|
+
Make Rspec support actually work.
|
119
110
|
|
111
|
+
h2. Author
|
112
|
+
|
113
|
+
Spike Ilacqua
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/features/web_steps.feature
CHANGED
@@ -26,6 +26,8 @@ Feature: Using Mechanize
|
|
26
26
|
And I fill in "Password by Label" with "Password Text"
|
27
27
|
And I select "Option Two" from "Select by Name"
|
28
28
|
And I choose "Radio Button One"
|
29
|
+
And I check "Unchecked Box"
|
30
|
+
And I uncheck "Checked Box"
|
29
31
|
And I press "Submit"
|
30
32
|
Then I should see "Label Field"
|
31
33
|
And I should see "Name Field"
|
@@ -35,6 +37,16 @@ Feature: Using Mechanize
|
|
35
37
|
And I should see "Radio Button One Chosen"
|
36
38
|
But I should not see "Option One"
|
37
39
|
And I should not see "Radio Button Two Chosen"
|
40
|
+
And I should see "Unchecked Box Checked"
|
41
|
+
But I should not see "Checked Box Checked"
|
42
|
+
|
43
|
+
Scenario: Form Value Steps
|
44
|
+
Given I am on the form page
|
45
|
+
Then the "Checked Box" checkbox should be checked
|
46
|
+
And the "Unchecked Box" checkbox should not be checked
|
47
|
+
When I fill in "Field by Label" with "Label Field"
|
48
|
+
Then the "Field by Label" field should contain "Label Field"
|
49
|
+
And the "Field by Label" field should not contain "Oogy Boogy"
|
38
50
|
|
39
51
|
Scenario: Form Table Steps
|
40
52
|
Given I am on the form page
|
@@ -47,6 +59,7 @@ Feature: Using Mechanize
|
|
47
59
|
And I should see "Named"
|
48
60
|
And I should see "ID-ed"
|
49
61
|
|
62
|
+
|
50
63
|
@mock_launchy
|
51
64
|
Scenario: Save and Open Step
|
52
65
|
Given I am on the index page
|
data/lib/mechanical-cuke.rb
CHANGED
@@ -8,19 +8,28 @@ module MechanicalCuke
|
|
8
8
|
def configure
|
9
9
|
yield self
|
10
10
|
end
|
11
|
-
# TODO: try def get blah blah
|
12
11
|
end
|
13
|
-
end
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
end
|
13
|
+
def mechanize
|
14
|
+
@mechanize ||= Mechanize.new
|
15
|
+
end
|
18
16
|
|
19
|
-
|
17
|
+
def get(url)
|
18
|
+
mechanize.get(url)
|
19
|
+
end
|
20
|
+
|
21
|
+
def current_page
|
22
|
+
mechanize.current_page
|
23
|
+
end
|
20
24
|
|
21
|
-
def response_body
|
22
|
-
|
25
|
+
def response_body
|
26
|
+
current_page.body
|
27
|
+
end
|
23
28
|
end
|
29
|
+
|
30
|
+
World(MechanicalCuke)
|
31
|
+
|
32
|
+
private
|
24
33
|
|
25
34
|
def form
|
26
35
|
current_page.forms.first
|
@@ -68,3 +77,22 @@ def find_radiobutton(field)
|
|
68
77
|
|
69
78
|
return nil
|
70
79
|
end
|
80
|
+
|
81
|
+
def find_checkbox(field)
|
82
|
+
# Search by id
|
83
|
+
if (node = find_by_id(field))
|
84
|
+
return form.checkbox_with(:node => node.first)
|
85
|
+
end
|
86
|
+
|
87
|
+
# Then by name
|
88
|
+
if (f = form.checkbox_with(:name => field))
|
89
|
+
return f
|
90
|
+
end
|
91
|
+
|
92
|
+
# And finally by label
|
93
|
+
if (node = find_by_label(field))
|
94
|
+
return form.checkbox_with(:node => node)
|
95
|
+
end
|
96
|
+
|
97
|
+
return nil
|
98
|
+
end
|
@@ -39,6 +39,17 @@ When /^(?:|I )select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
|
|
39
39
|
f.option_with(:value => value).select
|
40
40
|
end
|
41
41
|
|
42
|
+
|
43
|
+
When /^(?:|I )check "([^\"]*)"$/ do |field|
|
44
|
+
cb = find_checkbox(field)
|
45
|
+
cb.checked = true
|
46
|
+
end
|
47
|
+
|
48
|
+
When /^(?:|I )uncheck "([^\"]*)"$/ do |field|
|
49
|
+
cb = find_checkbox(field)
|
50
|
+
cb.checked = false
|
51
|
+
end
|
52
|
+
|
42
53
|
When /^(?:|I )choose "([^\"]*)"$/ do |field|
|
43
54
|
r = find_radiobutton(field)
|
44
55
|
raise "Can't find radio button \"#{field}\"" if r.nil?
|
@@ -84,6 +95,42 @@ But /^(?:|I )should not see "([^\"]*)"$/ do |text|
|
|
84
95
|
end
|
85
96
|
end
|
86
97
|
|
98
|
+
Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
|
99
|
+
f = find_field(field)
|
100
|
+
if defined?(Spec::Rails::Matchers)
|
101
|
+
f.should == field
|
102
|
+
else
|
103
|
+
assert_equal value, f.value
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value|
|
108
|
+
f = find_field(field)
|
109
|
+
if defined?(Spec::Rails::Matchers)
|
110
|
+
f.should_not == value
|
111
|
+
else
|
112
|
+
assert_not_equal value, f.value
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
|
117
|
+
cb = find_checkbox(label)
|
118
|
+
if defined?(Spec::Rails::Matchers)
|
119
|
+
cb.checked.should be true
|
120
|
+
else
|
121
|
+
assert cb.checked
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
Then /^the "([^\"]*)" checkbox should not be checked$/ do |label|
|
126
|
+
cb = find_checkbox(label)
|
127
|
+
if defined?(Spec::Rails::Matchers)
|
128
|
+
cb.checked.should be true
|
129
|
+
else
|
130
|
+
assert !cb.checked
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
87
134
|
Then /^(?:|I )should be on (.+)$/ do |page_name|
|
88
135
|
current_path = current_page.uri.to_s
|
89
136
|
if defined?(Spec::Rails::Matchers)
|
@@ -42,7 +42,17 @@
|
|
42
42
|
<label for="radio_button_two_id">Radio Button Two</label>
|
43
43
|
<input type="radio" id="radio_button_two_id" name="radio_button" value="Radio Button Two Chosen" checked>
|
44
44
|
</p>
|
45
|
-
|
45
|
+
<p>
|
46
|
+
<label for="unchecked_checkbox_id">Unchecked Box</label>
|
47
|
+
<input type="checkbox" id="unchecked_checkbox_id"
|
48
|
+
name="unchecked_checkbox" value="Unchecked Box Checked">
|
49
|
+
</p>
|
50
|
+
<p>
|
51
|
+
<label for="checked_checkbox_id">Checked Box</label>
|
52
|
+
<input type="checkbox" id="checked_checkbox_id"
|
53
|
+
name="checked_checkbox"
|
54
|
+
value="Checked Box Checked" checked="yes">
|
55
|
+
</p>
|
46
56
|
<p>
|
47
57
|
<input type="submit" value="Submit">
|
48
58
|
</p>
|
@@ -32,5 +32,14 @@
|
|
32
32
|
<label>Radio Button by Name</label>
|
33
33
|
<%= params[:radio_button] %>
|
34
34
|
</p>
|
35
|
+
<p>
|
36
|
+
<label>Unchecked Checkbox</label>
|
37
|
+
<%= params[:unchecked_checkbox] %>
|
38
|
+
</p>
|
39
|
+
<p>
|
40
|
+
<label>Checked Checkbox</label>
|
41
|
+
<%= params[:checked_checkbox] %>
|
42
|
+
</p>
|
43
|
+
|
35
44
|
</body>
|
36
45
|
</html>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mechanical-cuke
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Spike Ilacqua
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-08-
|
12
|
+
date: 2010-08-19 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|