kelp 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/History.md +7 -0
- data/README.md +4 -3
- data/examples/sinatra_app/features/visibility.feature +9 -0
- data/examples/sinatra_app/features/visibility_fail.feature +27 -0
- data/examples/sinatra_app/views/form.erb +6 -6
- data/features/kelp_step_definitions.feature +20 -5
- data/features/step_definitions/app_steps.rb +5 -2
- data/kelp.gemspec +1 -1
- data/lib/kelp/dropdown.rb +7 -3
- data/lib/kelp/exceptions.rb +5 -0
- data/lib/kelp/visibility.rb +21 -2
- data/spec/dropdown_spec.rb +3 -3
- data/spec/visibility_spec.rb +13 -13
- metadata +6 -4
data/Gemfile.lock
CHANGED
data/History.md
CHANGED
data/README.md
CHANGED
@@ -147,15 +147,16 @@ file used by the Rails generator. Run via:
|
|
147
147
|
|
148
148
|
$ rake cucumber
|
149
149
|
|
150
|
-
This self-test
|
151
|
-
`examples/sinatra_app/features`,
|
150
|
+
This self-test includes high-level scenarios that exercise more detailed
|
151
|
+
scenarios in `examples/sinatra_app/features`, ensuring that the generated step
|
152
|
+
definitions perform as expected.
|
152
153
|
|
153
154
|
|
154
155
|
Future plans
|
155
156
|
------------
|
156
157
|
|
157
158
|
* Generator for Rails 3
|
158
|
-
* Support
|
159
|
+
* Support Webrat
|
159
160
|
|
160
161
|
|
161
162
|
Copyright
|
@@ -5,9 +5,18 @@ Feature: Visibility
|
|
5
5
|
|
6
6
|
Scenario: Should or shouldn't see
|
7
7
|
Then I should see the following:
|
8
|
+
| Homepage |
|
8
9
|
| Hello world |
|
9
10
|
| Goodbye world |
|
10
11
|
|
12
|
+
And I should see the following:
|
13
|
+
"""
|
14
|
+
First
|
15
|
+
Second
|
16
|
+
Third
|
17
|
+
About Us
|
18
|
+
"""
|
19
|
+
|
11
20
|
And I should not see the following:
|
12
21
|
| Goodbye cruel world |
|
13
22
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Feature: Visibility failures
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given I visit "/home"
|
5
|
+
|
6
|
+
Scenario: Should see - failure
|
7
|
+
Then I should see the following:
|
8
|
+
"""
|
9
|
+
First
|
10
|
+
Missing
|
11
|
+
Second
|
12
|
+
Uh-oh
|
13
|
+
Third
|
14
|
+
Not there
|
15
|
+
"""
|
16
|
+
|
17
|
+
Scenario: Should not see - failure
|
18
|
+
Then I should not see the following:
|
19
|
+
"""
|
20
|
+
First
|
21
|
+
Missing
|
22
|
+
Second
|
23
|
+
Uh-oh
|
24
|
+
Third
|
25
|
+
Not there
|
26
|
+
"""
|
27
|
+
|
@@ -20,17 +20,17 @@
|
|
20
20
|
<p>
|
21
21
|
<label for="height">Height</label>
|
22
22
|
<select id="height">
|
23
|
-
<option value="
|
24
|
-
<option value="
|
25
|
-
<option value="
|
23
|
+
<option value="short">Short</option>
|
24
|
+
<option value="average" selected="selected">Average</option>
|
25
|
+
<option value="tall" >Tall</option>
|
26
26
|
</select>
|
27
27
|
</p>
|
28
28
|
<p>
|
29
29
|
<label for="weight">Weight</label>
|
30
30
|
<select id="weight">
|
31
|
-
<option value="
|
32
|
-
<option value="
|
33
|
-
<option value="
|
31
|
+
<option value="light">Light</option>
|
32
|
+
<option value="medium">Medium</option>
|
33
|
+
<option value="heavy">Heavy</option>
|
34
34
|
</select>
|
35
35
|
</p>
|
36
36
|
<p>
|
@@ -8,7 +8,7 @@ Feature: Kelp Step Definitions
|
|
8
8
|
|
9
9
|
Scenario: Checkbox test
|
10
10
|
When I run cucumber on "checkbox.feature"
|
11
|
-
Then the results should
|
11
|
+
Then the results should include:
|
12
12
|
"""
|
13
13
|
2 scenarios (2 passed)
|
14
14
|
6 steps (6 passed)
|
@@ -16,7 +16,7 @@ Feature: Kelp Step Definitions
|
|
16
16
|
|
17
17
|
Scenario: Dropdown test
|
18
18
|
When I run cucumber on "dropdown.feature"
|
19
|
-
Then the results should
|
19
|
+
Then the results should include:
|
20
20
|
"""
|
21
21
|
3 scenarios (3 passed)
|
22
22
|
11 steps (11 passed)
|
@@ -24,7 +24,7 @@ Feature: Kelp Step Definitions
|
|
24
24
|
|
25
25
|
Scenario: Field test
|
26
26
|
When I run cucumber on "field.feature"
|
27
|
-
Then the results should
|
27
|
+
Then the results should include:
|
28
28
|
"""
|
29
29
|
2 scenarios (2 passed)
|
30
30
|
7 steps (7 passed)
|
@@ -32,9 +32,24 @@ Feature: Kelp Step Definitions
|
|
32
32
|
|
33
33
|
Scenario: Visibility test
|
34
34
|
When I run cucumber on "visibility.feature"
|
35
|
-
Then the results should
|
35
|
+
Then the results should include:
|
36
36
|
"""
|
37
37
|
3 scenarios (3 passed)
|
38
|
-
|
38
|
+
12 steps (12 passed)
|
39
|
+
"""
|
40
|
+
|
41
|
+
@focus
|
42
|
+
Scenario: Visibility failure test
|
43
|
+
When I run cucumber on "visibility_fail.feature"
|
44
|
+
Then the results should include:
|
45
|
+
"""
|
46
|
+
Expected to see: ["First", "Missing", "Second", "Uh-oh", "Third", "Not there"]
|
47
|
+
Did not see: ["Missing", "Uh-oh", "Not there"] (Kelp::Unexpected)
|
39
48
|
"""
|
49
|
+
And the results should include:
|
50
|
+
"""
|
51
|
+
Expected not to see: ["First", "Missing", "Second", "Uh-oh", "Third", "Not there"]
|
52
|
+
Did see: ["First", "Second", "Third"] (Kelp::Unexpected)
|
53
|
+
"""
|
54
|
+
|
40
55
|
|
@@ -24,8 +24,11 @@ When /^I run cucumber on "(.+)"$/ do |feature|
|
|
24
24
|
end
|
25
25
|
|
26
26
|
|
27
|
-
Then /^the results should
|
28
|
-
|
27
|
+
Then /^the results should include:$/ do |expected_results|
|
28
|
+
# Remove leading whitespace before comparison
|
29
|
+
got = @output.gsub(/^\s*/, '')
|
30
|
+
want = expected_results.gsub(/^\s*/, '')
|
31
|
+
if !got.include?(want)
|
29
32
|
got = @output.collect {|line| " #{line}"}.join
|
30
33
|
want = expected_results.collect {|line| " #{line}"}.join
|
31
34
|
raise("Expected:\n#{want}\nGot:\n#{got}")
|
data/kelp.gemspec
CHANGED
data/lib/kelp/dropdown.rb
CHANGED
@@ -28,10 +28,14 @@ module Kelp
|
|
28
28
|
# See if there's a 'selected' option
|
29
29
|
begin
|
30
30
|
selected = field.find(:xpath, ".//option[@selected='selected']")
|
31
|
-
# If not, find the option matching the
|
31
|
+
# If not, find the option matching the field's 'value' attribute
|
32
32
|
rescue Capybara::ElementNotFound
|
33
|
-
|
34
|
-
|
33
|
+
# FIXME: Find a way to support multiple-selection dropdowns
|
34
|
+
if field.value.class == Array
|
35
|
+
raise Exception, "Multiple-selection dropdowns are not supported"
|
36
|
+
end
|
37
|
+
field_value = xpath_sanitize(field.value)
|
38
|
+
selected = field.find(:xpath, ".//option[@value=#{field_value}]")
|
35
39
|
end
|
36
40
|
selected.text.should =~ /#{value}/
|
37
41
|
end
|
data/lib/kelp/visibility.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'kelp/scoping'
|
2
2
|
require 'kelp/xpath'
|
3
|
+
require 'kelp/exceptions'
|
3
4
|
|
4
5
|
module Kelp
|
5
6
|
# This module defines methods for verifying the visibility (or invisibility)
|
@@ -25,11 +26,20 @@ module Kelp
|
|
25
26
|
#
|
26
27
|
def should_see(texts, scope={})
|
27
28
|
texts = [texts] if (texts.class == String || texts.class == Regexp)
|
29
|
+
unexpected = []
|
28
30
|
in_scope(scope) do
|
29
31
|
texts.each do |text|
|
30
|
-
|
32
|
+
begin
|
33
|
+
page_should_contain text
|
34
|
+
rescue RSpec::Expectations::ExpectationNotMetError
|
35
|
+
unexpected << text
|
36
|
+
end
|
31
37
|
end
|
32
38
|
end
|
39
|
+
if !unexpected.empty?
|
40
|
+
raise Kelp::Unexpected,
|
41
|
+
"Expected to see: #{texts.inspect}\nDid not see: #{unexpected.inspect}"
|
42
|
+
end
|
33
43
|
end
|
34
44
|
|
35
45
|
|
@@ -43,11 +53,20 @@ module Kelp
|
|
43
53
|
#
|
44
54
|
def should_not_see(texts, scope={})
|
45
55
|
texts = [texts] if (texts.class == String || texts.class == Regexp)
|
56
|
+
unexpected = []
|
46
57
|
in_scope(scope) do
|
47
58
|
texts.each do |text|
|
48
|
-
|
59
|
+
begin
|
60
|
+
page_should_not_contain text
|
61
|
+
rescue RSpec::Expectations::ExpectationNotMetError
|
62
|
+
unexpected << text
|
63
|
+
end
|
49
64
|
end
|
50
65
|
end
|
66
|
+
if !unexpected.empty?
|
67
|
+
raise Kelp::Unexpected,
|
68
|
+
"Expected not to see: #{texts.inspect}\nDid see: #{unexpected.inspect}"
|
69
|
+
end
|
51
70
|
end
|
52
71
|
|
53
72
|
|
data/spec/dropdown_spec.rb
CHANGED
@@ -144,16 +144,16 @@ describe Kelp::Dropdown, "dropdown_value_should_equal" do
|
|
144
144
|
|
145
145
|
context "passes when" do
|
146
146
|
it "the option with the 'selected' attribute has the given value" do
|
147
|
-
dropdown_value_should_equal "Height", "
|
147
|
+
dropdown_value_should_equal "Height", "average"
|
148
148
|
end
|
149
149
|
|
150
150
|
it "the first option selected by default has the given value" do
|
151
|
-
dropdown_value_should_equal "Weight", "
|
151
|
+
dropdown_value_should_equal "Weight", "light"
|
152
152
|
end
|
153
153
|
|
154
154
|
it "the programmatically chosen option has the given value" do
|
155
155
|
select "Tall", :from => "Height"
|
156
|
-
dropdown_value_should_equal "Height", "
|
156
|
+
dropdown_value_should_equal "Height", "tall"
|
157
157
|
end
|
158
158
|
end
|
159
159
|
|
data/spec/visibility_spec.rb
CHANGED
@@ -50,7 +50,7 @@ describe Kelp::Visibility, "should_see" do
|
|
50
50
|
it "does not exist" do
|
51
51
|
lambda do
|
52
52
|
should_see "Goodbye cruel world"
|
53
|
-
end.should raise_error(
|
53
|
+
end.should raise_error(Kelp::Unexpected)
|
54
54
|
end
|
55
55
|
|
56
56
|
it "any of several do not exist" do
|
@@ -60,19 +60,19 @@ describe Kelp::Visibility, "should_see" do
|
|
60
60
|
"Goodbye world",
|
61
61
|
"Hello, nurse!"
|
62
62
|
]
|
63
|
-
end.should raise_error(
|
63
|
+
end.should raise_error(Kelp::Unexpected)
|
64
64
|
end
|
65
65
|
|
66
66
|
it "is not within a given CSS scope" do
|
67
67
|
lambda do
|
68
68
|
should_see "Goodbye world", :within => "#greeting"
|
69
|
-
end.should raise_error(
|
69
|
+
end.should raise_error(Kelp::Unexpected)
|
70
70
|
end
|
71
71
|
|
72
72
|
it "is not within a given XPath scope" do
|
73
73
|
lambda do
|
74
74
|
should_see "Goodbye world", :within => "//div[@id='greeting']"
|
75
|
-
end.should raise_error(
|
75
|
+
end.should raise_error(Kelp::Unexpected)
|
76
76
|
end
|
77
77
|
|
78
78
|
it "is given a nonexistent XPath scope" do
|
@@ -86,13 +86,13 @@ describe Kelp::Visibility, "should_see" do
|
|
86
86
|
it "does not match" do
|
87
87
|
lambda do
|
88
88
|
should_see /(Yo|Wazzup) world/
|
89
|
-
end.should raise_error(
|
89
|
+
end.should raise_error(Kelp::Unexpected)
|
90
90
|
end
|
91
91
|
|
92
92
|
it "matches but is not within the scope" do
|
93
93
|
lambda do
|
94
94
|
should_see /Goodbye world/, :within => "#greeting"
|
95
|
-
end.should raise_error(
|
95
|
+
end.should raise_error(Kelp::Unexpected)
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
@@ -151,7 +151,7 @@ describe Kelp::Visibility, "should_not_see" do
|
|
151
151
|
it "exists" do
|
152
152
|
lambda do
|
153
153
|
should_not_see "Hello world"
|
154
|
-
end.should raise_error(
|
154
|
+
end.should raise_error(Kelp::Unexpected)
|
155
155
|
end
|
156
156
|
|
157
157
|
it "any of several exist" do
|
@@ -161,19 +161,19 @@ describe Kelp::Visibility, "should_not_see" do
|
|
161
161
|
"Goodbye cruel world",
|
162
162
|
"Goodbye world"
|
163
163
|
]
|
164
|
-
end.should raise_error(
|
164
|
+
end.should raise_error(Kelp::Unexpected)
|
165
165
|
end
|
166
166
|
|
167
167
|
it "exists within the given CSS scope" do
|
168
168
|
lambda do
|
169
169
|
should_not_see "Hello world", :within => "#greeting"
|
170
|
-
end.should raise_error(
|
170
|
+
end.should raise_error(Kelp::Unexpected)
|
171
171
|
end
|
172
172
|
|
173
173
|
it "exists within the given XPath scope" do
|
174
174
|
lambda do
|
175
175
|
should_not_see "Hello world", :within => "//div[@id='greeting']"
|
176
|
-
end.should raise_error(
|
176
|
+
end.should raise_error(Kelp::Unexpected)
|
177
177
|
end
|
178
178
|
end
|
179
179
|
|
@@ -181,7 +181,7 @@ describe Kelp::Visibility, "should_not_see" do
|
|
181
181
|
it "matches" do
|
182
182
|
lambda do
|
183
183
|
should_not_see /(Hello|Goodbye) world/
|
184
|
-
end.should raise_error(
|
184
|
+
end.should raise_error(Kelp::Unexpected)
|
185
185
|
end
|
186
186
|
|
187
187
|
it "any of several regexps match" do
|
@@ -191,13 +191,13 @@ describe Kelp::Visibility, "should_not_see" do
|
|
191
191
|
/(Ciao|Later) world/,
|
192
192
|
/(Hello|Goodbye) world/
|
193
193
|
]
|
194
|
-
end.should raise_error(
|
194
|
+
end.should raise_error(Kelp::Unexpected)
|
195
195
|
end
|
196
196
|
|
197
197
|
it "matches within the scope" do
|
198
198
|
lambda do
|
199
199
|
should_not_see /(Hello|Goodbye) world/, :within => "#greeting"
|
200
|
-
end.should raise_error(
|
200
|
+
end.should raise_error(Kelp::Unexpected)
|
201
201
|
end
|
202
202
|
end
|
203
203
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kelp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 7
|
10
|
+
version: 0.1.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Eric Pierce
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-04-
|
18
|
+
date: 2011-04-25 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -144,6 +144,7 @@ files:
|
|
144
144
|
- examples/sinatra_app/features/field.feature
|
145
145
|
- examples/sinatra_app/features/support/env.rb
|
146
146
|
- examples/sinatra_app/features/visibility.feature
|
147
|
+
- examples/sinatra_app/features/visibility_fail.feature
|
147
148
|
- examples/sinatra_app/features/web_steps.rb
|
148
149
|
- examples/sinatra_app/views/about.erb
|
149
150
|
- examples/sinatra_app/views/edit1.erb
|
@@ -160,6 +161,7 @@ files:
|
|
160
161
|
- lib/kelp/attribute.rb
|
161
162
|
- lib/kelp/checkbox.rb
|
162
163
|
- lib/kelp/dropdown.rb
|
164
|
+
- lib/kelp/exceptions.rb
|
163
165
|
- lib/kelp/field.rb
|
164
166
|
- lib/kelp/helper.rb
|
165
167
|
- lib/kelp/navigation.rb
|