kelp 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -392,3 +392,83 @@ describe Kelp::Visibility, "page_should_not_contain" do
392
392
  end
393
393
 
394
394
 
395
+ describe Kelp::Visibility, "should_see_button" do
396
+ before(:each) do
397
+ visit('/form')
398
+ end
399
+
400
+ context "passes when" do
401
+ it "an input tag with the given value exists" do
402
+ should_see_button "Save preferences"
403
+ should_see_button "Save is disabled"
404
+ end
405
+
406
+ it "a button tag with the given value exists" do
407
+ should_see_button "Submit person form"
408
+ end
409
+
410
+ it "an input tag with the given value exists within a scope" do
411
+ should_see_button "Save preferences", :within => "#preferences_form"
412
+ should_see_button "Save is disabled", :within => "#other_form"
413
+ end
414
+
415
+ it "a button tag with the given value exists within a scope" do
416
+ should_see_button "Submit person form", :within => "#person_form"
417
+ end
418
+ end
419
+
420
+ context "fails when" do
421
+ it "an input tag with the given value does not exist" do
422
+ lambda do
423
+ should_see_button "Save nonexistent"
424
+ end.should raise_error(Kelp::Unexpected)
425
+ end
426
+
427
+ it "an input tag with the given value exists, but in a different scope" do
428
+ lambda do
429
+ should_see_button "Save preferences", :within => "#person_form"
430
+ end.should raise_error(Kelp::Unexpected)
431
+ end
432
+ end
433
+
434
+ end
435
+
436
+
437
+ describe Kelp::Visibility, "should_not_see_button" do
438
+ before(:each) do
439
+ visit('/form')
440
+ end
441
+
442
+ context "passes when" do
443
+ it "an input or button tag with the given value does not exist" do
444
+ should_not_see_button "No such button"
445
+ end
446
+
447
+ it "an input tag with the given value does not exist within a scope" do
448
+ should_not_see_button "Save preferences", :within => "#person_form"
449
+ should_not_see_button "Submit person form", :within => "#preferences_form"
450
+ end
451
+ end
452
+
453
+ context "fails when" do
454
+ it "an input tag with the given value exists" do
455
+ lambda do
456
+ should_not_see_button "Save preferences"
457
+ end.should raise_error(Kelp::Unexpected)
458
+ end
459
+
460
+ it "a button tag with the given value exists" do
461
+ lambda do
462
+ should_not_see_button "Submit person form"
463
+ end.should raise_error(Kelp::Unexpected)
464
+ end
465
+
466
+ it "an input tag with the given value exists in the given scope" do
467
+ lambda do
468
+ should_not_see_button "Save preferences", :within => "#preferences_form"
469
+ end.should raise_error(Kelp::Unexpected)
470
+ end
471
+ end
472
+
473
+ end
474
+
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: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 8
10
- version: 0.1.8
9
+ - 9
10
+ version: 0.1.9
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-26 00:00:00 -06:00
18
+ date: 2011-05-06 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -170,7 +170,7 @@ files:
170
170
  - lib/kelp/xpath.rb
171
171
  - rails_generators/kelp/kelp_generator.rb
172
172
  - rails_generators/kelp/templates/capybara_steps.rb
173
- - rails_generators/kelp/templates/kelp_steps.rb
173
+ - rails_generators/kelp/templates/web_steps.rb
174
174
  - spec/attribute_spec.rb
175
175
  - spec/checkbox_spec.rb
176
176
  - spec/dropdown_spec.rb
@@ -1,256 +0,0 @@
1
- # kelp_steps.rb
2
- #
3
- # This file defines some generic step definitions that utilize the helper
4
- # methods provided by Kelp. It is auto-generated by running:
5
- #
6
- # script/generate kelp
7
- #
8
- # from a Rails application. It's probably a good idea to avoid editing this
9
- # file, since it may be overwritten by an upgraded kelp gem later. If you
10
- # find an issues with these step definitions and think they can be improved,
11
- # please create an issue on Github:
12
- #
13
- # http://github.com/wapcaplet/kelp/issues
14
- #
15
-
16
- require 'kelp'
17
- World(Kelp::Attribute)
18
- World(Kelp::Checkbox)
19
- World(Kelp::Dropdown)
20
- World(Kelp::Field)
21
- World(Kelp::Navigation)
22
- World(Kelp::Scoping)
23
- World(Kelp::Visibility)
24
-
25
- module KelpStepHelper
26
- # Convert a Cucumber::Ast::Table or multiline string into
27
- # a list of strings
28
- def listify(items)
29
- if items.class == Cucumber::Ast::Table
30
- strings = items.raw.flatten
31
- else
32
- strings = items.split(/[\r\n]+/)
33
- end
34
- end
35
- end
36
- World(KelpStepHelper)
37
-
38
- SHOULD_OR_NOT = /(should|should not)/
39
- WITHIN = /(?: within "([^\"]+)")?/
40
- ELEMENT = /(?:field|checkbox|dropdown|button)/
41
- STR = /([^\"]+)/
42
-
43
- # Verify the presence or absence of multiple text strings in the page,
44
- # or within a given context.
45
- #
46
- # With `should see`, fails if any of the strings are missing.
47
- # With `should not see`, fails if any of the strings are present.
48
- #
49
- # `items` may be a Cucumber table, or a multi-line string. Examples:
50
- #
51
- # Then I should see the following:
52
- # | Apple crumble |
53
- # | Banana cream pie |
54
- # | Cherry tart |
55
- #
56
- # Then I should see the following:
57
- # """
58
- # Bacon & Eggs
59
- # Biscuits & Gravy
60
- # Hash Browns
61
- # """
62
- #
63
- Then /^I #{SHOULD_OR_NOT} see the following#{WITHIN}:$/ do |expect, selector, items|
64
- strings = listify(items)
65
- if expect == 'should'
66
- should_see strings, :within => selector
67
- else
68
- should_not_see strings, :within => selector
69
- end
70
- end
71
-
72
-
73
- # Verify that one or more table rows containing the correct values exist (or do
74
- # not exist). Rows do not need to match exactly, and fields do not need to be
75
- # in the same order.
76
- #
77
- # Examples:
78
- #
79
- # Then I should see table rows containing:
80
- # | Eric | Edit |
81
- # | John | Edit |
82
- # And I should not see a table row containing:
83
- # | Eric | Delete |
84
- #
85
- Then /^I #{SHOULD_OR_NOT} see (?:a table row|table rows)#{WITHIN} containing:$/ do |expect, selector, rows|
86
- rows.raw.each do |fields|
87
- if expect == 'should'
88
- should_see_in_same_row(fields, :within => selector)
89
- else
90
- should_not_see_in_same_row(fields, :within => selector)
91
- end
92
- end
93
- end
94
-
95
-
96
- # Verify that a dropdown has a given value selected. This verifies the visible
97
- # value shown to the user, rather than the value attribute of the selected
98
- # option element.
99
- #
100
- # Examples:
101
- #
102
- # Then the "Height" dropdown should equal "Average"
103
- #
104
- Then /^the "#{STR}" dropdown#{WITHIN} should equal "#{STR}"$/ do |dropdown, selector, value|
105
- dropdown_should_equal(dropdown, value, :within => selector)
106
- end
107
-
108
-
109
- # Verify that a dropdown includes or doesn't include the given value.
110
- #
111
- # Examples:
112
- #
113
- # Then the "Height" dropdown should include "Tall"
114
- #
115
- Then /^the "#{STR}" dropdown#{WITHIN} #{SHOULD_OR_NOT} include "#{STR}"$/ do |dropdown, selector, expect, value|
116
- if expect == 'should'
117
- dropdown_should_include(dropdown, value, :within => selector)
118
- else
119
- dropdown_should_not_include(dropdown, value, :within => selector)
120
- end
121
- end
122
-
123
-
124
- # Verify that a dropdown includes or doesn't include all values in the given
125
- # table or multiline string.
126
- #
127
- # Examples:
128
- #
129
- # Then the "Height" dropdown should include:
130
- # | Short |
131
- # | Average |
132
- # | Tall |
133
- #
134
- # Then the "Favorite Colors" dropdown should include:
135
- # """
136
- # Red
137
- # Green
138
- # Blue
139
- # """
140
- #
141
- Then /^the "#{STR}" dropdown#{WITHIN} #{SHOULD_OR_NOT} include:$/ do |dropdown, selector, expect, values|
142
- listify(values).each do |value|
143
- if expect == 'should'
144
- dropdown_should_include(dropdown, value, :within => selector)
145
- else
146
- dropdown_should_not_include(dropdown, value, :within => selector)
147
- end
148
- end
149
- end
150
-
151
-
152
- # Verify that a given field is empty or nil.
153
- #
154
- # Examples:
155
- #
156
- # Then the "First name" field should be empty
157
- #
158
- Then /^the "#{STR}" field#{WITHIN} should be empty$/ do |field, selector|
159
- field_should_be_empty(field, :within => selector)
160
- end
161
-
162
-
163
- # Verify multiple fields in a form, optionally restricted to a given selector.
164
- # Fields may be text inputs or dropdowns.
165
- #
166
- # Examples:
167
- #
168
- # Then the fields should contain:
169
- # | First name | Eric |
170
- # | Last name | Pierce |
171
- #
172
- Then /^the fields#{WITHIN} should contain:$/ do |selector, fields|
173
- fields_should_contain_within(selector, fields.rows_hash)
174
- end
175
-
176
-
177
- # Verify that expected text exists or does not exist in the same row as
178
- # some text. This can be used to ensure the presence or absence of "Edit"
179
- # or "Delete" links, or specific data associated with a row in a table.
180
- #
181
- # Examples:
182
- #
183
- # Then I should see "Edit" next to "John"
184
- # And I should not see "Delete" next to "John"
185
- #
186
- Then /^I #{SHOULD_OR_NOT} see "#{STR}" next to "#{STR}"#{WITHIN}$/ do |expect, text, next_to, selector|
187
- if expect == 'should'
188
- should_see_in_same_row([text, next_to], :within => selector)
189
- else
190
- should_not_see_in_same_row([text, next_to], :within => selector)
191
- end
192
- end
193
-
194
-
195
- # Verify that several expected text strings exist or do not exist in the same
196
- # row as some text. Prevents multiple "should see X next to Y" calls. Similar
197
- # to "should see a row containing", but targeted toward a specific row.
198
- #
199
- # Examples:
200
- #
201
- # Then I should see the following next to "Terry":
202
- # | Copy |
203
- # | Edit |
204
- # | Delete |
205
- #
206
- # Then I should see the following next to "John":
207
- # """
208
- # Copy
209
- # Edit
210
- # Delete
211
- # """
212
- #
213
- Then /^I #{SHOULD_OR_NOT} see the following next to "#{STR}"#{WITHIN}:$/ do |expect, next_to, selector, items|
214
- listify(items).each do |text|
215
- if expect == 'should'
216
- should_see_in_same_row([text, next_to], :within => selector)
217
- else
218
- should_not_see_in_same_row([text, next_to], :within => selector)
219
- end
220
- end
221
- end
222
-
223
-
224
- # Click a link in a table row that contains the given text.
225
- # This can be used to click the "Edit" link for a specific record.
226
- #
227
- # Examples:
228
- #
229
- # When I follow "Edit" next to "John"
230
- #
231
- When /^I follow "#{STR}" next to "#{STR}"$/ do |link, next_to|
232
- click_link_in_row(link, next_to)
233
- end
234
-
235
-
236
- # Verify that a checkbox in a certain table row is checked or unchecked.
237
- # "should not be checked" and "should be unchecked" are equivalent, and
238
- # "should be checked" and "should not be unchecked" are equivalent.
239
- #
240
- # Examples:
241
- #
242
- # Then the "Like" checkbox next to "Apple" should be checked
243
- # And the "Like" checkbox next to "Banana" should be unchecked
244
- #
245
- Then /^the "#{STR}" checkbox next to "#{STR}"#{WITHIN} #{SHOULD_OR_NOT} be (checked|unchecked)$/ do |checkbox, next_to, selector, expect, state|
246
-
247
- within(:xpath, xpath_row_containing(next_to)) do
248
- if (expect == 'should' && state == 'checked') || (expect == 'should not' && state == 'unchecked')
249
- checkbox_should_be_checked(checkbox, :within => selector)
250
- else
251
- checkbox_should_not_be_checked(checkbox, :within => selector)
252
- end
253
- end
254
- end
255
-
256
-