bbc-capybara 1.1.2

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.
Files changed (107) hide show
  1. data/History.txt +325 -0
  2. data/License.txt +22 -0
  3. data/README.md +815 -0
  4. data/lib/capybara.rb +368 -0
  5. data/lib/capybara/cucumber.rb +25 -0
  6. data/lib/capybara/driver/base.rb +64 -0
  7. data/lib/capybara/driver/node.rb +74 -0
  8. data/lib/capybara/dsl.rb +50 -0
  9. data/lib/capybara/node/actions.rb +146 -0
  10. data/lib/capybara/node/base.rb +63 -0
  11. data/lib/capybara/node/document.rb +25 -0
  12. data/lib/capybara/node/element.rb +201 -0
  13. data/lib/capybara/node/finders.rb +154 -0
  14. data/lib/capybara/node/matchers.rb +442 -0
  15. data/lib/capybara/node/simple.rb +132 -0
  16. data/lib/capybara/query.rb +63 -0
  17. data/lib/capybara/rack_test/browser.rb +126 -0
  18. data/lib/capybara/rack_test/driver.rb +80 -0
  19. data/lib/capybara/rack_test/form.rb +80 -0
  20. data/lib/capybara/rack_test/node.rb +121 -0
  21. data/lib/capybara/rails.rb +17 -0
  22. data/lib/capybara/rspec.rb +26 -0
  23. data/lib/capybara/rspec/features.rb +22 -0
  24. data/lib/capybara/rspec/matchers.rb +152 -0
  25. data/lib/capybara/selector.rb +156 -0
  26. data/lib/capybara/selenium/driver.rb +169 -0
  27. data/lib/capybara/selenium/node.rb +91 -0
  28. data/lib/capybara/server.rb +87 -0
  29. data/lib/capybara/session.rb +322 -0
  30. data/lib/capybara/spec/driver.rb +329 -0
  31. data/lib/capybara/spec/fixtures/capybara.jpg +3 -0
  32. data/lib/capybara/spec/fixtures/test_file.txt +1 -0
  33. data/lib/capybara/spec/public/jquery-ui.js +791 -0
  34. data/lib/capybara/spec/public/jquery.js +9046 -0
  35. data/lib/capybara/spec/public/test.js +43 -0
  36. data/lib/capybara/spec/session.rb +148 -0
  37. data/lib/capybara/spec/session/all_spec.rb +78 -0
  38. data/lib/capybara/spec/session/attach_file_spec.rb +76 -0
  39. data/lib/capybara/spec/session/check_spec.rb +68 -0
  40. data/lib/capybara/spec/session/choose_spec.rb +29 -0
  41. data/lib/capybara/spec/session/click_button_spec.rb +305 -0
  42. data/lib/capybara/spec/session/click_link_or_button_spec.rb +37 -0
  43. data/lib/capybara/spec/session/click_link_spec.rb +120 -0
  44. data/lib/capybara/spec/session/current_url_spec.rb +83 -0
  45. data/lib/capybara/spec/session/fill_in_spec.rb +127 -0
  46. data/lib/capybara/spec/session/find_button_spec.rb +18 -0
  47. data/lib/capybara/spec/session/find_by_id_spec.rb +18 -0
  48. data/lib/capybara/spec/session/find_field_spec.rb +26 -0
  49. data/lib/capybara/spec/session/find_link_spec.rb +19 -0
  50. data/lib/capybara/spec/session/find_spec.rb +168 -0
  51. data/lib/capybara/spec/session/first_spec.rb +105 -0
  52. data/lib/capybara/spec/session/has_button_spec.rb +32 -0
  53. data/lib/capybara/spec/session/has_css_spec.rb +243 -0
  54. data/lib/capybara/spec/session/has_field_spec.rb +192 -0
  55. data/lib/capybara/spec/session/has_link_spec.rb +37 -0
  56. data/lib/capybara/spec/session/has_select_spec.rb +129 -0
  57. data/lib/capybara/spec/session/has_selector_spec.rb +129 -0
  58. data/lib/capybara/spec/session/has_table_spec.rb +34 -0
  59. data/lib/capybara/spec/session/has_text_spec.rb +138 -0
  60. data/lib/capybara/spec/session/has_xpath_spec.rb +123 -0
  61. data/lib/capybara/spec/session/headers.rb +19 -0
  62. data/lib/capybara/spec/session/javascript.rb +312 -0
  63. data/lib/capybara/spec/session/response_code.rb +19 -0
  64. data/lib/capybara/spec/session/select_spec.rb +119 -0
  65. data/lib/capybara/spec/session/text_spec.rb +24 -0
  66. data/lib/capybara/spec/session/uncheck_spec.rb +21 -0
  67. data/lib/capybara/spec/session/unselect_spec.rb +67 -0
  68. data/lib/capybara/spec/session/within_spec.rb +178 -0
  69. data/lib/capybara/spec/test_app.rb +156 -0
  70. data/lib/capybara/spec/views/buttons.erb +4 -0
  71. data/lib/capybara/spec/views/fieldsets.erb +29 -0
  72. data/lib/capybara/spec/views/form.erb +366 -0
  73. data/lib/capybara/spec/views/frame_one.erb +8 -0
  74. data/lib/capybara/spec/views/frame_two.erb +8 -0
  75. data/lib/capybara/spec/views/header_links.erb +7 -0
  76. data/lib/capybara/spec/views/host_links.erb +12 -0
  77. data/lib/capybara/spec/views/popup_one.erb +8 -0
  78. data/lib/capybara/spec/views/popup_two.erb +8 -0
  79. data/lib/capybara/spec/views/postback.erb +13 -0
  80. data/lib/capybara/spec/views/tables.erb +62 -0
  81. data/lib/capybara/spec/views/with_html.erb +75 -0
  82. data/lib/capybara/spec/views/with_html_entities.erb +1 -0
  83. data/lib/capybara/spec/views/with_js.erb +53 -0
  84. data/lib/capybara/spec/views/with_scope.erb +36 -0
  85. data/lib/capybara/spec/views/with_simple_html.erb +1 -0
  86. data/lib/capybara/spec/views/within_frames.erb +10 -0
  87. data/lib/capybara/spec/views/within_popups.erb +25 -0
  88. data/lib/capybara/util/save_and_open_page.rb +45 -0
  89. data/lib/capybara/util/timeout.rb +27 -0
  90. data/lib/capybara/version.rb +3 -0
  91. data/spec/basic_node_spec.rb +89 -0
  92. data/spec/capybara_spec.rb +46 -0
  93. data/spec/driver/rack_test_driver_spec.rb +90 -0
  94. data/spec/driver/selenium_driver_spec.rb +55 -0
  95. data/spec/dsl_spec.rb +255 -0
  96. data/spec/fixtures/selenium_driver_rspec_failure.rb +8 -0
  97. data/spec/fixtures/selenium_driver_rspec_success.rb +8 -0
  98. data/spec/rspec/features_spec.rb +43 -0
  99. data/spec/rspec/matchers_spec.rb +564 -0
  100. data/spec/rspec_spec.rb +51 -0
  101. data/spec/save_and_open_page_spec.rb +155 -0
  102. data/spec/server_spec.rb +74 -0
  103. data/spec/session/rack_test_session_spec.rb +61 -0
  104. data/spec/session/selenium_session_spec.rb +26 -0
  105. data/spec/spec_helper.rb +31 -0
  106. data/spec/timeout_spec.rb +28 -0
  107. metadata +297 -0
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capybara::Selenium::Driver do
4
+ it "should exit with a zero exit status" do
5
+ browser = Capybara::Selenium::Driver.new(TestApp).browser
6
+ true.should == true
7
+ end
8
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+ require 'capybara/rspec'
3
+
4
+ RSpec.configuration.before(:each, :example_group => {:file_path => __FILE__}) do
5
+ @in_filtered_hook = true
6
+ end
7
+
8
+ feature "Capybara's feature DSL" do
9
+ background do
10
+ @in_background = true
11
+ end
12
+
13
+ scenario "includes Capybara" do
14
+ visit('/')
15
+ page.should have_content('Hello world!')
16
+ end
17
+
18
+ scenario "preserves description" do
19
+ example.metadata[:full_description].should == "Capybara's feature DSL preserves description"
20
+ end
21
+
22
+ scenario "allows driver switching", :driver => :selenium do
23
+ Capybara.current_driver.should == :selenium
24
+ end
25
+
26
+ scenario "runs background" do
27
+ @in_background.should be_true
28
+ end
29
+
30
+ scenario "runs hooks filtered by file path" do
31
+ @in_filtered_hook.should be_true
32
+ end
33
+
34
+ scenario "doesn't pollute the Object namespace" do
35
+ Object.new.respond_to?(:feature, true).should be_false
36
+ end
37
+ end
38
+
39
+ feature "Capybara's feature DSL with driver", :driver => :culerity do
40
+ scenario "switches driver" do
41
+ Capybara.current_driver.should == :culerity
42
+ end
43
+ end
@@ -0,0 +1,564 @@
1
+ require 'spec_helper'
2
+ require 'capybara/dsl'
3
+ require 'capybara/rspec/matchers'
4
+
5
+ describe Capybara::RSpecMatchers do
6
+ include Capybara::DSL
7
+ include Capybara::RSpecMatchers
8
+
9
+ describe "have_css matcher" do
10
+ it "gives proper description" do
11
+ have_css('h1').description.should == "has css \"h1\""
12
+ end
13
+
14
+ context "on a string" do
15
+ context "with should" do
16
+ it "passes if has_css? returns true" do
17
+ "<h1>Text</h1>".should have_css('h1')
18
+ end
19
+
20
+ it "fails if has_css? returns false" do
21
+ expect do
22
+ "<h1>Text</h1>".should have_css('h2')
23
+ end.to raise_error(/expected css "h2" to return something/)
24
+ end
25
+
26
+ it "passes if matched node count equals expected count" do
27
+ "<h1>Text</h1>".should have_css('h1', :count => 1)
28
+ end
29
+
30
+ it "fails if matched node count does not equal expected count" do
31
+ expect do
32
+ "<h1>Text</h1>".should have_css('h1', :count => 2)
33
+ end.to raise_error(/expected css "h1" to be returned 2 times/)
34
+ end
35
+ end
36
+
37
+ context "with should_not" do
38
+ it "passes if has_no_css? returns true" do
39
+ "<h1>Text</h1>".should_not have_css('h2')
40
+ end
41
+
42
+ it "fails if has_no_css? returns false" do
43
+ expect do
44
+ "<h1>Text</h1>".should_not have_css('h1')
45
+ end.to raise_error(/expected css "h1" not to return anything/)
46
+ end
47
+
48
+ it "passes if matched node count does not equal expected count" do
49
+ "<h1>Text</h1>".should_not have_css('h1', :count => 2)
50
+ end
51
+
52
+ it "fails if matched node count equals expected count" do
53
+ expect do
54
+ "<h1>Text</h1>".should_not have_css('h1', :count => 1)
55
+ end.to raise_error(/expected css "h1" not to return anything/)
56
+ end
57
+ end
58
+ end
59
+
60
+ context "on a page or node" do
61
+ before do
62
+ visit('/with_html')
63
+ end
64
+
65
+ context "with should" do
66
+ it "passes if has_css? returns true" do
67
+ page.should have_css('h1')
68
+ end
69
+
70
+ it "fails if has_css? returns false" do
71
+ expect do
72
+ page.should have_css('h1#doesnotexist')
73
+ end.to raise_error(/expected css "h1#doesnotexist" to return something/)
74
+ end
75
+ end
76
+
77
+ context "with should_not" do
78
+ it "passes if has_no_css? returns true" do
79
+ page.should_not have_css('h1#doesnotexist')
80
+ end
81
+
82
+ it "fails if has_no_css? returns false" do
83
+ expect do
84
+ page.should_not have_css('h1')
85
+ end.to raise_error(/expected css "h1" not to return anything/)
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ describe "have_xpath matcher" do
92
+ it "gives proper description" do
93
+ have_xpath('//h1').description.should == "has xpath \"\/\/h1\""
94
+ end
95
+
96
+ context "on a string" do
97
+ context "with should" do
98
+ it "passes if has_css? returns true" do
99
+ "<h1>Text</h1>".should have_xpath('//h1')
100
+ end
101
+
102
+ it "fails if has_css? returns false" do
103
+ expect do
104
+ "<h1>Text</h1>".should have_xpath('//h2')
105
+ end.to raise_error(%r(expected xpath "//h2" to return something))
106
+ end
107
+ end
108
+
109
+ context "with should_not" do
110
+ it "passes if has_no_css? returns true" do
111
+ "<h1>Text</h1>".should_not have_xpath('//h2')
112
+ end
113
+
114
+ it "fails if has_no_css? returns false" do
115
+ expect do
116
+ "<h1>Text</h1>".should_not have_xpath('//h1')
117
+ end.to raise_error(%r(expected xpath "//h1" not to return anything))
118
+ end
119
+ end
120
+ end
121
+
122
+ context "on a page or node" do
123
+ before do
124
+ visit('/with_html')
125
+ end
126
+
127
+ context "with should" do
128
+ it "passes if has_css? returns true" do
129
+ page.should have_xpath('//h1')
130
+ end
131
+
132
+ it "fails if has_css? returns false" do
133
+ expect do
134
+ page.should have_xpath("//h1[@id='doesnotexist']")
135
+ end.to raise_error(%r(expected xpath "//h1\[@id='doesnotexist'\]" to return something))
136
+ end
137
+ end
138
+
139
+ context "with should_not" do
140
+ it "passes if has_no_css? returns true" do
141
+ page.should_not have_xpath('//h1[@id="doesnotexist"]')
142
+ end
143
+
144
+ it "fails if has_no_css? returns false" do
145
+ expect do
146
+ page.should_not have_xpath('//h1')
147
+ end.to raise_error(%r(expected xpath "//h1" not to return anything))
148
+ end
149
+ end
150
+ end
151
+ end
152
+
153
+ describe "have_selector matcher" do
154
+ it "gives proper description" do
155
+ have_selector('//h1').description.should == "has xpath \"//h1\""
156
+ end
157
+
158
+ context "on a string" do
159
+ context "with should" do
160
+ it "passes if has_css? returns true" do
161
+ "<h1>Text</h1>".should have_selector('//h1')
162
+ end
163
+
164
+ it "fails if has_css? returns false" do
165
+ expect do
166
+ "<h1>Text</h1>".should have_selector('//h2')
167
+ end.to raise_error(%r(expected xpath "//h2" to return something))
168
+ end
169
+
170
+ it "fails with the selector's failure_message if set" do
171
+ Capybara.add_selector(:monkey) do
172
+ xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
173
+ failure_message { |node, selector| node.all(".//*[contains(@id, 'monkey')]").map { |node| node.text }.sort.join(', ') }
174
+ end
175
+ expect do
176
+ '<h1 id="monkey_paul">Monkey John</h1>'.should have_selector(:monkey, 14)
177
+ end.to raise_error("Monkey John")
178
+ end
179
+ end
180
+
181
+ context "with should_not" do
182
+ it "passes if has_no_css? returns true" do
183
+ "<h1>Text</h1>".should_not have_selector(:css, 'h2')
184
+ end
185
+
186
+ it "fails if has_no_css? returns false" do
187
+ expect do
188
+ "<h1>Text</h1>".should_not have_selector(:css, 'h1')
189
+ end.to raise_error(%r(expected css "h1" not to return anything))
190
+ end
191
+ end
192
+ end
193
+
194
+ context "on a page or node" do
195
+ before do
196
+ visit('/with_html')
197
+ end
198
+
199
+ context "with should" do
200
+ it "passes if has_css? returns true" do
201
+ page.should have_selector('//h1', :text => 'test')
202
+ end
203
+
204
+ it "fails if has_css? returns false" do
205
+ expect do
206
+ page.should have_selector("//h1[@id='doesnotexist']")
207
+ end.to raise_error(%r(expected xpath "//h1\[@id='doesnotexist'\]" to return something))
208
+ end
209
+
210
+ it "includes text in error message" do
211
+ expect do
212
+ page.should have_selector("//h1", :text => 'wrong text')
213
+ end.to raise_error(%r(expected xpath "//h1" with text "wrong text" to return something))
214
+ end
215
+
216
+ it "fails with the selector's failure_message if set" do
217
+ Capybara.add_selector(:monkey) do
218
+ xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
219
+ failure_message { |node, selector| node.all(".//*[contains(@id, 'monkey')]").map { |node| node.text }.sort.join(', ') }
220
+ end
221
+ expect do
222
+ page.should have_selector(:monkey, 14)
223
+ end.to raise_error("Monkey John, Monkey Paul")
224
+ end
225
+ end
226
+
227
+ context "with should_not" do
228
+ it "passes if has_no_css? returns true" do
229
+ page.should_not have_selector(:css, 'h1#doesnotexist')
230
+ end
231
+
232
+ it "fails if has_no_css? returns false" do
233
+ expect do
234
+ page.should_not have_selector(:css, 'h1', :text => 'test')
235
+ end.to raise_error(%r(expected css "h1" with text "test" not to return anything))
236
+ end
237
+ end
238
+ end
239
+ end
240
+
241
+ describe "have_content matcher" do
242
+ it "gives proper description" do
243
+ have_content('Text').description.should == "has content \"Text\""
244
+ end
245
+
246
+ context "on a string" do
247
+ context "with should" do
248
+ it "passes if has_css? returns true" do
249
+ "<h1>Text</h1>".should have_content('Text')
250
+ end
251
+
252
+ it "fails if has_css? returns false" do
253
+ expect do
254
+ "<h1>Text</h1>".should have_content('No such Text')
255
+ end.to raise_error(/expected there to be content "No such Text" in "Text"/)
256
+ end
257
+ end
258
+
259
+ context "with should_not" do
260
+ it "passes if has_no_css? returns true" do
261
+ "<h1>Text</h1>".should_not have_content('No such Text')
262
+ end
263
+
264
+ it "fails if has_no_css? returns false" do
265
+ expect do
266
+ "<h1>Text</h1>".should_not have_content('Text')
267
+ end.to raise_error(/expected content "Text" not to return anything/)
268
+ end
269
+ end
270
+ end
271
+
272
+ context "on a page or node" do
273
+ before do
274
+ visit('/with_html')
275
+ end
276
+
277
+ context "with should" do
278
+ it "passes if has_css? returns true" do
279
+ page.should have_content('This is a test')
280
+ end
281
+
282
+ it "fails if has_css? returns false" do
283
+ expect do
284
+ page.should have_content('No such Text')
285
+ end.to raise_error(/expected there to be content "No such Text" in "(.*)This is a test(.*)"/)
286
+ end
287
+
288
+ context "with default selector CSS" do
289
+ before { Capybara.default_selector = :css }
290
+ it "fails if has_css? returns false" do
291
+ expect do
292
+ page.should have_content('No such Text')
293
+ end.to raise_error(/expected there to be content "No such Text" in "(.*)This is a test(.*)"/)
294
+ end
295
+ after { Capybara.default_selector = :xpath }
296
+ end
297
+ end
298
+
299
+ context "with should_not" do
300
+ it "passes if has_no_css? returns true" do
301
+ page.should_not have_content('No such Text')
302
+ end
303
+
304
+ it "fails if has_no_css? returns false" do
305
+ expect do
306
+ page.should_not have_content('This is a test')
307
+ end.to raise_error(/expected content "This is a test" not to return anything/)
308
+ end
309
+ end
310
+ end
311
+ end
312
+
313
+ describe "have_text matcher" do
314
+ it "gives proper description" do
315
+ have_text('Text').description.should == "has text \"Text\""
316
+ end
317
+
318
+ context "on a string" do
319
+ context "with should" do
320
+ it "passes if has_text? returns true" do
321
+ "<h1>Text</h1>".should have_text('Text')
322
+ end
323
+
324
+ it "fails if has_text? returns false" do
325
+ expect do
326
+ "<h1>Text</h1>".should have_text('No such Text')
327
+ end.to raise_error(/expected there to be text "No such Text" in "Text"/)
328
+ end
329
+ end
330
+
331
+ context "with should_not" do
332
+ it "passes if has_no_text? returns true" do
333
+ "<h1>Text</h1>".should_not have_text('No such Text')
334
+ end
335
+
336
+ it "fails if has_no_text? returns false" do
337
+ expect do
338
+ "<h1>Text</h1>".should_not have_text('Text')
339
+ end.to raise_error(/expected text "Text" not to return anything/)
340
+ end
341
+ end
342
+ end
343
+
344
+ context "on a page or node" do
345
+ before do
346
+ visit('/with_html')
347
+ end
348
+
349
+ context "with should" do
350
+ it "passes if has_text? returns true" do
351
+ page.should have_text('This is a test')
352
+ end
353
+
354
+ it "fails if has_text? returns false" do
355
+ expect do
356
+ page.should have_text('No such Text')
357
+ end.to raise_error(/expected there to be text "No such Text" in "(.*)This is a test(.*)"/)
358
+ end
359
+
360
+ context "with default selector CSS" do
361
+ before { Capybara.default_selector = :css }
362
+ it "fails if has_text? returns false" do
363
+ expect do
364
+ page.should have_text('No such Text')
365
+ end.to raise_error(/expected there to be text "No such Text" in "(.*)This is a test(.*)"/)
366
+ end
367
+ after { Capybara.default_selector = :xpath }
368
+ end
369
+ end
370
+
371
+ context "with should_not" do
372
+ it "passes if has_no_text? returns true" do
373
+ page.should_not have_text('No such Text')
374
+ end
375
+
376
+ it "fails if has_no_text? returns false" do
377
+ expect do
378
+ page.should_not have_text('This is a test')
379
+ end.to raise_error(/expected text "This is a test" not to return anything/)
380
+ end
381
+ end
382
+ end
383
+ end
384
+
385
+ describe "have_link matcher" do
386
+ let(:html) { '<a href="#">Just a link</a>' }
387
+
388
+ it "gives proper description" do
389
+ have_link('Just a link').description.should == "has link \"Just a link\""
390
+ end
391
+
392
+ it "passes if there is such a button" do
393
+ html.should have_link('Just a link')
394
+ end
395
+
396
+ it "fails if there is no such button" do
397
+ expect do
398
+ html.should have_link('No such Link')
399
+ end.to raise_error(/expected link "No such Link"/)
400
+ end
401
+ end
402
+
403
+ describe "have_button matcher" do
404
+ let(:html) { '<button>A button</button><input type="submit" value="Another button"/>' }
405
+
406
+ it "gives proper description" do
407
+ have_button('A button').description.should == "has button \"A button\""
408
+ end
409
+
410
+ it "passes if there is such a button" do
411
+ html.should have_button('A button')
412
+ end
413
+
414
+ it "fails if there is no such button" do
415
+ expect do
416
+ html.should have_button('No such Button')
417
+ end.to raise_error(/expected button "No such Button"/)
418
+ end
419
+ end
420
+
421
+ describe "have_field matcher" do
422
+ let(:html) { '<p><label>Text field<input type="text"/></label></p>' }
423
+
424
+ it "gives proper description" do
425
+ have_field('Text field').description.should == "has field \"Text field\""
426
+ end
427
+
428
+ it "passes if there is such a field" do
429
+ html.should have_field('Text field')
430
+ end
431
+
432
+ it "fails if there is no such field" do
433
+ expect do
434
+ html.should have_field('No such Field')
435
+ end.to raise_error(/expected field "No such Field"/)
436
+ end
437
+ end
438
+
439
+ describe "have_checked_field matcher" do
440
+ let(:html) do
441
+ '<label>it is checked<input type="checkbox" checked="checked"/></label>
442
+ <label>unchecked field<input type="checkbox"/></label>'
443
+ end
444
+
445
+ it "gives proper description" do
446
+ have_checked_field('it is checked').description.should == "has checked_field \"it is checked\""
447
+ end
448
+
449
+ context "with should" do
450
+ it "passes if there is such a field and it is checked" do
451
+ html.should have_checked_field('it is checked')
452
+ end
453
+
454
+ it "fails if there is such a field but it is not checked" do
455
+ expect do
456
+ html.should have_checked_field('unchecked field')
457
+ end.to raise_error(/expected checked_field "unchecked field"/)
458
+ end
459
+
460
+ it "fails if there is no such field" do
461
+ expect do
462
+ html.should have_checked_field('no such field')
463
+ end.to raise_error(/expected checked_field "no such field"/)
464
+ end
465
+ end
466
+
467
+ context "with should not" do
468
+ it "fails if there is such a field and it is checked" do
469
+ expect do
470
+ html.should_not have_checked_field('it is checked')
471
+ end.to raise_error(/expected checked_field "it is checked" not to return anything/)
472
+ end
473
+
474
+ it "passes if there is such a field but it is not checked" do
475
+ html.should_not have_checked_field('unchecked field')
476
+ end
477
+
478
+ it "passes if there is no such field" do
479
+ html.should_not have_checked_field('no such field')
480
+ end
481
+ end
482
+ end
483
+
484
+ describe "have_unchecked_field matcher" do
485
+ let(:html) do
486
+ '<label>it is checked<input type="checkbox" checked="checked"/></label>
487
+ <label>unchecked field<input type="checkbox"/></label>'
488
+ end
489
+
490
+ it "gives proper description" do
491
+ have_unchecked_field('unchecked field').description.should == "has unchecked_field \"unchecked field\""
492
+ end
493
+
494
+ context "with should" do
495
+ it "passes if there is such a field and it is not checked" do
496
+ html.should have_unchecked_field('unchecked field')
497
+ end
498
+
499
+ it "fails if there is such a field but it is checked" do
500
+ expect do
501
+ html.should have_unchecked_field('it is checked')
502
+ end.to raise_error(/expected unchecked_field "it is checked"/)
503
+ end
504
+
505
+ it "fails if there is no such field" do
506
+ expect do
507
+ html.should have_unchecked_field('no such field')
508
+ end.to raise_error(/expected unchecked_field "no such field"/)
509
+ end
510
+ end
511
+
512
+ context "with should not" do
513
+ it "fails if there is such a field and it is not checked" do
514
+ expect do
515
+ html.should_not have_unchecked_field('unchecked field')
516
+ end.to raise_error(/expected unchecked_field "unchecked field" not to return anything/)
517
+ end
518
+
519
+ it "passes if there is such a field but it is checked" do
520
+ html.should_not have_unchecked_field('it is checked')
521
+ end
522
+
523
+ it "passes if there is no such field" do
524
+ html.should_not have_unchecked_field('no such field')
525
+ end
526
+ end
527
+ end
528
+
529
+ describe "have_select matcher" do
530
+ let(:html) { '<label>Select Box<select></select></label>' }
531
+
532
+ it "gives proper description" do
533
+ have_select('Select Box').description.should == "has select \"Select Box\""
534
+ end
535
+
536
+ it "passes if there is such a select" do
537
+ html.should have_select('Select Box')
538
+ end
539
+
540
+ it "fails if there is no such select" do
541
+ expect do
542
+ html.should have_select('No such Select box')
543
+ end.to raise_error(/expected select "No such Select box"/)
544
+ end
545
+ end
546
+
547
+ describe "have_table matcher" do
548
+ let(:html) { '<table><caption>Lovely table</caption></table>' }
549
+
550
+ it "gives proper description" do
551
+ have_table('Lovely table').description.should == "has table \"Lovely table\""
552
+ end
553
+
554
+ it "passes if there is such a select" do
555
+ html.should have_table('Lovely table')
556
+ end
557
+
558
+ it "fails if there is no such select" do
559
+ expect do
560
+ html.should have_table('No such Table')
561
+ end.to raise_error(/expected table "No such Table"/)
562
+ end
563
+ end
564
+ end