capybara 2.18.0 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +26 -1
  3. data/README.md +12 -12
  4. data/lib/capybara.rb +13 -25
  5. data/lib/capybara/config.rb +11 -57
  6. data/lib/capybara/cucumber.rb +2 -3
  7. data/lib/capybara/driver/base.rb +5 -16
  8. data/lib/capybara/driver/node.rb +5 -4
  9. data/lib/capybara/dsl.rb +1 -0
  10. data/lib/capybara/helpers.rb +16 -28
  11. data/lib/capybara/minitest.rb +139 -138
  12. data/lib/capybara/minitest/spec.rb +15 -14
  13. data/lib/capybara/node/actions.rb +59 -81
  14. data/lib/capybara/node/base.rb +11 -18
  15. data/lib/capybara/node/document.rb +2 -2
  16. data/lib/capybara/node/document_matchers.rb +8 -8
  17. data/lib/capybara/node/element.rb +30 -40
  18. data/lib/capybara/node/finders.rb +62 -70
  19. data/lib/capybara/node/matchers.rb +48 -71
  20. data/lib/capybara/node/simple.rb +11 -17
  21. data/lib/capybara/queries/ancestor_query.rb +4 -6
  22. data/lib/capybara/queries/base_query.rb +18 -17
  23. data/lib/capybara/queries/current_path_query.rb +8 -24
  24. data/lib/capybara/queries/match_query.rb +3 -7
  25. data/lib/capybara/queries/selector_query.rb +92 -95
  26. data/lib/capybara/queries/sibling_query.rb +4 -4
  27. data/lib/capybara/queries/text_query.rb +37 -34
  28. data/lib/capybara/queries/title_query.rb +8 -11
  29. data/lib/capybara/rack_test/browser.rb +15 -18
  30. data/lib/capybara/rack_test/css_handlers.rb +6 -4
  31. data/lib/capybara/rack_test/driver.rb +6 -10
  32. data/lib/capybara/rack_test/form.rb +50 -40
  33. data/lib/capybara/rack_test/node.rb +70 -56
  34. data/lib/capybara/rails.rb +2 -6
  35. data/lib/capybara/result.rb +22 -22
  36. data/lib/capybara/rspec.rb +5 -10
  37. data/lib/capybara/rspec/compound.rb +5 -10
  38. data/lib/capybara/rspec/features.rb +17 -48
  39. data/lib/capybara/rspec/matcher_proxies.rb +31 -15
  40. data/lib/capybara/rspec/matchers.rb +70 -60
  41. data/lib/capybara/selector.rb +129 -117
  42. data/lib/capybara/selector/css.rb +6 -11
  43. data/lib/capybara/selector/filter.rb +1 -17
  44. data/lib/capybara/selector/filter_set.rb +17 -14
  45. data/lib/capybara/selector/filters/base.rb +7 -6
  46. data/lib/capybara/selector/filters/expression_filter.rb +6 -23
  47. data/lib/capybara/selector/filters/node_filter.rb +2 -12
  48. data/lib/capybara/selector/selector.rb +27 -33
  49. data/lib/capybara/selenium/driver.rb +113 -127
  50. data/lib/capybara/selenium/node.rb +148 -113
  51. data/lib/capybara/server.rb +3 -2
  52. data/lib/capybara/session.rb +137 -223
  53. data/lib/capybara/session/config.rb +47 -67
  54. data/lib/capybara/session/matchers.rb +8 -7
  55. data/lib/capybara/spec/public/test.js +26 -4
  56. data/lib/capybara/spec/session/accept_alert_spec.rb +1 -0
  57. data/lib/capybara/spec/session/accept_confirm_spec.rb +3 -2
  58. data/lib/capybara/spec/session/accept_prompt_spec.rb +1 -0
  59. data/lib/capybara/spec/session/all_spec.rb +31 -18
  60. data/lib/capybara/spec/session/ancestor_spec.rb +2 -4
  61. data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +6 -5
  62. data/lib/capybara/spec/session/assert_current_path.rb +12 -11
  63. data/lib/capybara/spec/session/assert_selector.rb +1 -0
  64. data/lib/capybara/spec/session/assert_text.rb +18 -17
  65. data/lib/capybara/spec/session/assert_title.rb +1 -0
  66. data/lib/capybara/spec/session/attach_file_spec.rb +14 -13
  67. data/lib/capybara/spec/session/body_spec.rb +1 -0
  68. data/lib/capybara/spec/session/check_spec.rb +7 -6
  69. data/lib/capybara/spec/session/choose_spec.rb +5 -4
  70. data/lib/capybara/spec/session/click_button_spec.rb +20 -28
  71. data/lib/capybara/spec/session/click_link_or_button_spec.rb +8 -7
  72. data/lib/capybara/spec/session/click_link_spec.rb +8 -7
  73. data/lib/capybara/spec/session/current_scope_spec.rb +4 -3
  74. data/lib/capybara/spec/session/current_url_spec.rb +7 -6
  75. data/lib/capybara/spec/session/dismiss_confirm_spec.rb +1 -1
  76. data/lib/capybara/spec/session/dismiss_prompt_spec.rb +1 -0
  77. data/lib/capybara/spec/session/element/assert_match_selector.rb +1 -1
  78. data/lib/capybara/spec/session/element/match_xpath_spec.rb +1 -1
  79. data/lib/capybara/spec/session/element/matches_selector_spec.rb +5 -5
  80. data/lib/capybara/spec/session/evaluate_async_script_spec.rb +3 -2
  81. data/lib/capybara/spec/session/evaluate_script_spec.rb +4 -3
  82. data/lib/capybara/spec/session/execute_script_spec.rb +4 -3
  83. data/lib/capybara/spec/session/fill_in_spec.rb +6 -5
  84. data/lib/capybara/spec/session/find_button_spec.rb +4 -3
  85. data/lib/capybara/spec/session/find_by_id_spec.rb +2 -1
  86. data/lib/capybara/spec/session/find_field_spec.rb +8 -14
  87. data/lib/capybara/spec/session/find_link_spec.rb +6 -5
  88. data/lib/capybara/spec/session/find_spec.rb +37 -31
  89. data/lib/capybara/spec/session/first_spec.rb +60 -33
  90. data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +2 -1
  91. data/lib/capybara/spec/session/frame/within_frame_spec.rb +9 -16
  92. data/lib/capybara/spec/session/go_back_spec.rb +1 -0
  93. data/lib/capybara/spec/session/go_forward_spec.rb +1 -0
  94. data/lib/capybara/spec/session/has_all_selectors_spec.rb +15 -15
  95. data/lib/capybara/spec/session/has_button_spec.rb +2 -1
  96. data/lib/capybara/spec/session/has_css_spec.rb +3 -2
  97. data/lib/capybara/spec/session/has_current_path_spec.rb +12 -28
  98. data/lib/capybara/spec/session/has_field_spec.rb +4 -3
  99. data/lib/capybara/spec/session/has_link_spec.rb +1 -0
  100. data/lib/capybara/spec/session/has_none_selectors_spec.rb +17 -17
  101. data/lib/capybara/spec/session/has_select_spec.rb +30 -29
  102. data/lib/capybara/spec/session/has_selector_spec.rb +5 -4
  103. data/lib/capybara/spec/session/has_table_spec.rb +2 -1
  104. data/lib/capybara/spec/session/has_text_spec.rb +6 -5
  105. data/lib/capybara/spec/session/has_title_spec.rb +1 -0
  106. data/lib/capybara/spec/session/has_xpath_spec.rb +1 -0
  107. data/lib/capybara/spec/session/headers.rb +2 -1
  108. data/lib/capybara/spec/session/html_spec.rb +1 -0
  109. data/lib/capybara/spec/session/node_spec.rb +91 -56
  110. data/lib/capybara/spec/session/node_wrapper_spec.rb +36 -0
  111. data/lib/capybara/spec/session/refresh_spec.rb +4 -2
  112. data/lib/capybara/spec/session/reset_session_spec.rb +1 -0
  113. data/lib/capybara/spec/session/response_code.rb +1 -0
  114. data/lib/capybara/spec/session/save_and_open_page_spec.rb +1 -0
  115. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +6 -11
  116. data/lib/capybara/spec/session/save_page_spec.rb +1 -17
  117. data/lib/capybara/spec/session/save_screenshot_spec.rb +1 -1
  118. data/lib/capybara/spec/session/select_spec.rb +20 -20
  119. data/lib/capybara/spec/session/selectors_spec.rb +2 -2
  120. data/lib/capybara/spec/session/sibling_spec.rb +1 -1
  121. data/lib/capybara/spec/session/text_spec.rb +1 -0
  122. data/lib/capybara/spec/session/title_spec.rb +1 -1
  123. data/lib/capybara/spec/session/uncheck_spec.rb +4 -3
  124. data/lib/capybara/spec/session/unselect_spec.rb +6 -5
  125. data/lib/capybara/spec/session/visit_spec.rb +9 -3
  126. data/lib/capybara/spec/session/window/become_closed_spec.rb +2 -1
  127. data/lib/capybara/spec/session/window/current_window_spec.rb +1 -0
  128. data/lib/capybara/spec/session/window/open_new_window_spec.rb +1 -0
  129. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +2 -1
  130. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +2 -1
  131. data/lib/capybara/spec/session/window/window_spec.rb +12 -12
  132. data/lib/capybara/spec/session/window/windows_spec.rb +2 -3
  133. data/lib/capybara/spec/session/window/within_window_spec.rb +13 -68
  134. data/lib/capybara/spec/session/within_spec.rb +1 -0
  135. data/lib/capybara/spec/spec_helper.rb +26 -18
  136. data/lib/capybara/spec/test_app.rb +8 -9
  137. data/lib/capybara/spec/views/form.erb +1 -0
  138. data/lib/capybara/spec/views/with_html.erb +3 -1
  139. data/lib/capybara/spec/views/within_frames.erb +4 -1
  140. data/lib/capybara/version.rb +2 -1
  141. data/lib/capybara/window.rb +6 -10
  142. data/spec/basic_node_spec.rb +1 -0
  143. data/spec/capybara_spec.rb +9 -32
  144. data/spec/dsl_spec.rb +5 -13
  145. data/spec/filter_set_spec.rb +5 -4
  146. data/spec/fixtures/selenium_driver_rspec_failure.rb +2 -1
  147. data/spec/fixtures/selenium_driver_rspec_success.rb +3 -2
  148. data/spec/minitest_spec.rb +4 -3
  149. data/spec/minitest_spec_spec.rb +3 -2
  150. data/spec/per_session_config_spec.rb +9 -8
  151. data/spec/rack_test_spec.rb +21 -20
  152. data/spec/result_spec.rb +17 -16
  153. data/spec/rspec/features_spec.rb +17 -14
  154. data/spec/rspec/scenarios_spec.rb +5 -7
  155. data/spec/rspec/shared_spec_matchers.rb +96 -99
  156. data/spec/rspec/views_spec.rb +2 -1
  157. data/spec/rspec_matchers_spec.rb +19 -2
  158. data/spec/rspec_spec.rb +11 -15
  159. data/spec/selector_spec.rb +5 -6
  160. data/spec/selenium_spec_chrome.rb +7 -4
  161. data/spec/selenium_spec_marionette.rb +26 -12
  162. data/spec/server_spec.rb +33 -33
  163. data/spec/session_spec.rb +2 -1
  164. data/spec/shared_selenium_session.rb +27 -21
  165. data/spec/spec_helper.rb +2 -5
  166. metadata +66 -87
  167. data/lib/capybara/query.rb +0 -7
  168. data/spec/selenium_spec_firefox.rb +0 -68
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#find' do
3
4
  before do
4
5
  @session.visit('/with_html')
@@ -85,6 +86,11 @@ Capybara::SpecHelper.spec '#find' do
85
86
  it "should support pseudo selectors" do
86
87
  expect(@session.find(:css, 'input:disabled').value).to eq('This is disabled')
87
88
  end
89
+
90
+ it "should support escaping characters" do
91
+ expect(@session.find(:css, '#\31 escape\.me').text).to eq('needs escaping')
92
+ expect(@session.find(:css, '.\32 escape').text).to eq('needs escaping')
93
+ end
88
94
  end
89
95
 
90
96
  context "with xpath selectors" do
@@ -179,17 +185,17 @@ Capybara::SpecHelper.spec '#find' do
179
185
 
180
186
  it "should allow use of filters from custom filter set" do
181
187
  expect(@session.find(:id, 'test_field', filter_set: :value, with: 'monkey').value).to eq('monkey')
182
- expect{ @session.find(:id, 'test_field', filter_set: :value, with: 'not_monkey') }.to raise_error(Capybara::ElementNotFound)
188
+ expect { @session.find(:id, 'test_field', filter_set: :value, with: 'not_monkey') }.to raise_error(Capybara::ElementNotFound)
183
189
  end
184
190
 
185
191
  it "should allow use of filter set from a different selector" do
186
192
  expect(@session.find(:id, 'test_field', filter_set: :field, with: 'monkey').value).to eq('monkey')
187
- expect{ @session.find(:id, 'test_field', filter_set: :field, with: 'not_monkey') }.to raise_error(Capybara::ElementNotFound)
193
+ expect { @session.find(:id, 'test_field', filter_set: :field, with: 'not_monkey') }.to raise_error(Capybara::ElementNotFound)
188
194
  end
189
195
 
190
196
  it "should allow importing of filter set into selector" do
191
197
  expect(@session.find(:id_with_field_filters, 'test_field', with: 'monkey').value).to eq('monkey')
192
- expect{ @session.find(:id_with_field_filters, 'test_field', with: 'not_monkey') }.to raise_error(Capybara::ElementNotFound)
198
+ expect { @session.find(:id_with_field_filters, 'test_field', with: 'not_monkey') }.to raise_error(Capybara::ElementNotFound)
193
199
  end
194
200
  end
195
201
 
@@ -217,15 +223,15 @@ Capybara::SpecHelper.spec '#find' do
217
223
 
218
224
  context "with :exact option" do
219
225
  it "matches exactly when true" do
220
- expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], exact: true).value).to eq("monkey")
226
+ expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], exact: true).value).to eq("monkey")
221
227
  expect do
222
- @session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], exact: true)
228
+ @session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], exact: true)
223
229
  end.to raise_error(Capybara::ElementNotFound)
224
230
  end
225
231
 
226
232
  it "matches loosely when false" do
227
- expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], exact: false).value).to eq("monkey")
228
- expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], exact: false).value).to eq("monkey")
233
+ expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], exact: false).value).to eq("monkey")
234
+ expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], exact: false).value).to eq("monkey")
229
235
  end
230
236
 
231
237
  it "defaults to `Capybara.exact`" do
@@ -238,8 +244,8 @@ Capybara::SpecHelper.spec '#find' do
238
244
  end
239
245
 
240
246
  it "warns when the option has no effect" do
241
- expect_any_instance_of(Kernel).to receive(:warn).
242
- with('The :exact option only has an effect on queries using the XPath#is method. Using it with the query "#test_field" has no effect.')
247
+ expect_any_instance_of(Kernel).to receive(:warn)
248
+ .with('The :exact option only has an effect on queries using the XPath#is method. Using it with the query "#test_field" has no effect.')
243
249
  @session.find(:css, '#test_field', exact: true)
244
250
  end
245
251
  end
@@ -253,7 +259,7 @@ Capybara::SpecHelper.spec '#find' do
253
259
  end
254
260
  it "raises an error even if there the match is exact and the others are inexact" do
255
261
  expect do
256
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], exact: false, match: :one)
262
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], exact: false, match: :one)
257
263
  end.to raise_error(Capybara::Ambiguous)
258
264
  end
259
265
  it "returns the element if there is only one" do
@@ -281,25 +287,25 @@ Capybara::SpecHelper.spec '#find' do
281
287
  context "and `exact` set to `false`" do
282
288
  it "raises an error when there are multiple exact matches" do
283
289
  expect do
284
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :smart, exact: false)
290
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :smart, exact: false)
285
291
  end.to raise_error(Capybara::Ambiguous)
286
292
  end
287
293
  it "finds a single exact match when there also are inexact matches" do
288
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :smart, exact: false)
294
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :smart, exact: false)
289
295
  expect(result.text).to eq("almost singular")
290
296
  end
291
297
  it "raises an error when there are multiple inexact matches" do
292
298
  expect do
293
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :smart, exact: false)
299
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :smart, exact: false)
294
300
  end.to raise_error(Capybara::Ambiguous)
295
301
  end
296
302
  it "finds a single inexact match" do
297
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :smart, exact: false)
303
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :smart, exact: false)
298
304
  expect(result.text).to eq("almost singular but not quite")
299
305
  end
300
306
  it "raises an error if there is no match" do
301
307
  expect do
302
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :smart, exact: false)
308
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :smart, exact: false)
303
309
  end.to raise_error(Capybara::ElementNotFound)
304
310
  end
305
311
  end
@@ -307,26 +313,26 @@ Capybara::SpecHelper.spec '#find' do
307
313
  context "with `exact` set to `true`" do
308
314
  it "raises an error when there are multiple exact matches" do
309
315
  expect do
310
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :smart, exact: true)
316
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :smart, exact: true)
311
317
  end.to raise_error(Capybara::Ambiguous)
312
318
  end
313
319
  it "finds a single exact match when there also are inexact matches" do
314
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :smart, exact: true)
320
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :smart, exact: true)
315
321
  expect(result.text).to eq("almost singular")
316
322
  end
317
323
  it "raises an error when there are multiple inexact matches" do
318
324
  expect do
319
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :smart, exact: true)
325
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :smart, exact: true)
320
326
  end.to raise_error(Capybara::ElementNotFound)
321
327
  end
322
328
  it "raises an error when there is a single inexact matches" do
323
329
  expect do
324
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :smart, exact: true)
330
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :smart, exact: true)
325
331
  end.to raise_error(Capybara::ElementNotFound)
326
332
  end
327
333
  it "raises an error if there is no match" do
328
334
  expect do
329
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :smart, exact: true)
335
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :smart, exact: true)
330
336
  end.to raise_error(Capybara::ElementNotFound)
331
337
  end
332
338
  end
@@ -335,50 +341,50 @@ Capybara::SpecHelper.spec '#find' do
335
341
  context "when set to `prefer_exact`" do
336
342
  context "and `exact` set to `false`" do
337
343
  it "picks the first one when there are multiple exact matches" do
338
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :prefer_exact, exact: false)
344
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :prefer_exact, exact: false)
339
345
  expect(result.text).to eq("multiple one")
340
346
  end
341
347
  it "finds a single exact match when there also are inexact matches" do
342
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :prefer_exact, exact: false)
348
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :prefer_exact, exact: false)
343
349
  expect(result.text).to eq("almost singular")
344
350
  end
345
351
  it "picks the first one when there are multiple inexact matches" do
346
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :prefer_exact, exact: false)
352
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :prefer_exact, exact: false)
347
353
  expect(result.text).to eq("almost singular but not quite")
348
354
  end
349
355
  it "finds a single inexact match" do
350
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :prefer_exact, exact: false)
356
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :prefer_exact, exact: false)
351
357
  expect(result.text).to eq("almost singular but not quite")
352
358
  end
353
359
  it "raises an error if there is no match" do
354
360
  expect do
355
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :prefer_exact, exact: false)
361
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :prefer_exact, exact: false)
356
362
  end.to raise_error(Capybara::ElementNotFound)
357
363
  end
358
364
  end
359
365
 
360
366
  context "with `exact` set to `true`" do
361
367
  it "picks the first one when there are multiple exact matches" do
362
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :prefer_exact, exact: true)
368
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :prefer_exact, exact: true)
363
369
  expect(result.text).to eq("multiple one")
364
370
  end
365
371
  it "finds a single exact match when there also are inexact matches" do
366
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :prefer_exact, exact: true)
372
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :prefer_exact, exact: true)
367
373
  expect(result.text).to eq("almost singular")
368
374
  end
369
375
  it "raises an error if there are multiple inexact matches" do
370
376
  expect do
371
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :prefer_exact, exact: true)
377
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :prefer_exact, exact: true)
372
378
  end.to raise_error(Capybara::ElementNotFound)
373
379
  end
374
380
  it "raises an error if there is a single inexact match" do
375
381
  expect do
376
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :prefer_exact, exact: true)
382
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :prefer_exact, exact: true)
377
383
  end.to raise_error(Capybara::ElementNotFound)
378
384
  end
379
385
  it "raises an error if there is no match" do
380
386
  expect do
381
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :prefer_exact, exact: true)
387
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :prefer_exact, exact: true)
382
388
  end.to raise_error(Capybara::ElementNotFound)
383
389
  end
384
390
  end
@@ -401,7 +407,7 @@ Capybara::SpecHelper.spec '#find' do
401
407
  end
402
408
 
403
409
  it "supports a custom filter block" do
404
- expect(@session.find(:css, 'input'){|node| node.disabled? }[:name]).to eq('disabled_text')
410
+ expect(@session.find(:css, 'input', &:disabled?)[:name]).to eq('disabled_text')
405
411
  end
406
412
 
407
413
  context "within a scope" do
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#first' do
3
4
  before do
4
5
  @session.visit('/with_html')
@@ -9,8 +10,16 @@ Capybara::SpecHelper.spec '#first' do
9
10
  expect(@session.first("//input[@id='test_field']").value).to eq('monkey')
10
11
  end
11
12
 
12
- it "should return nil when nothing was found" do
13
- expect(@session.first('//div[@id="nosuchthing"]')).to be_nil
13
+ it "should raise ElementNotFound when nothing was found" do
14
+ expect do
15
+ @session.first('//div[@id="nosuchthing"]')
16
+ end.to raise_error Capybara::ElementNotFound
17
+ end
18
+
19
+ it "should return nil when nothing was found if count options allow no results" do
20
+ expect(@session.first('//div[@id="nosuchthing"]', minimum: 0)).to be_nil
21
+ expect(@session.first('//div[@id="nosuchthing"]', count: 0)).to be_nil
22
+ expect(@session.first('//div[@id="nosuchthing"]', between: (0..3))).to be_nil
14
23
  end
15
24
 
16
25
  it "should accept an XPath instance" do
@@ -20,9 +29,10 @@ Capybara::SpecHelper.spec '#first' do
20
29
  expect(@session.first(@xpath).value).to eq('John')
21
30
  end
22
31
 
23
- it "should warn when unused parameters are passed" do
24
- expect_any_instance_of(Kernel).to receive(:warn).with(/Unused parameters passed.*unused text/)
25
- @session.first(:css, '.header h2', 'unused text')
32
+ it "should raise when unused parameters are passed" do
33
+ expect do
34
+ @session.first(:css, 'h1', 'unused text')
35
+ end.to raise_error ArgumentError, /Unused parameters passed.*unused text/
26
36
  end
27
37
 
28
38
  context "with css selectors" do
@@ -49,40 +59,52 @@ Capybara::SpecHelper.spec '#first' do
49
59
 
50
60
  context "with visible filter" do
51
61
  it "should only find visible nodes when true" do
52
- expect(@session.first(:css, "a#invisible", visible: true)).to be_nil
62
+ expect do
63
+ @session.first(:css, "a#invisible", visible: true)
64
+ end.to raise_error Capybara::ElementNotFound
53
65
  end
54
66
 
55
67
  it "should find nodes regardless of whether they are invisible when false" do
56
- expect(@session.first(:css, "a#invisible", visible: false)).not_to be_nil
57
- expect(@session.first(:css, "a#invisible", visible: false, text: 'hidden link')).not_to be_nil
58
- expect(@session.first(:css, "a#visible", visible: false)).not_to be_nil
68
+ expect(@session.first(:css, "a#invisible", visible: false)).to be
69
+ expect(@session.first(:css, "a#invisible", visible: false, text: 'hidden link')).to be
70
+ expect(@session.first(:css, "a#visible", visible: false)).to be
59
71
  end
60
72
 
61
73
  it "should find nodes regardless of whether they are invisible when :all" do
62
- expect(@session.first(:css, "a#invisible", visible: :all)).not_to be_nil
63
- expect(@session.first(:css, "a#invisible", visible: :all, text: 'hidden link')).not_to be_nil
64
- expect(@session.first(:css, "a#visible", visible: :all)).not_to be_nil
74
+ expect(@session.first(:css, "a#invisible", visible: :all)).to be
75
+ expect(@session.first(:css, "a#invisible", visible: :all, text: 'hidden link')).to be
76
+ expect(@session.first(:css, "a#visible", visible: :all)).to be
65
77
  end
66
78
 
67
79
  it "should find only hidden nodes when :hidden" do
68
- expect(@session.first(:css, "a#invisible", visible: :hidden)).not_to be_nil
69
- expect(@session.first(:css, "a#invisible", visible: :hidden, text: 'hidden link')).not_to be_nil
70
- expect(@session.first(:css, "a#invisible", visible: :hidden, text: 'not hidden link')).to be_nil
71
- expect(@session.first(:css, "a#visible", visible: :hidden)).to be_nil
80
+ expect(@session.first(:css, "a#invisible", visible: :hidden)).to be
81
+ expect(@session.first(:css, "a#invisible", visible: :hidden, text: 'hidden link')).to be
82
+ expect do
83
+ @session.first(:css, "a#invisible", visible: :hidden, text: 'not hidden link')
84
+ end.to raise_error Capybara::ElementNotFound
85
+ expect do
86
+ @session.first(:css, "a#visible", visible: :hidden)
87
+ end.to raise_error Capybara::ElementNotFound
72
88
  end
73
89
 
74
90
  it "should find only visible nodes when :visible" do
75
- expect(@session.first(:css, "a#invisible", visible: :visible)).to be_nil
76
- expect(@session.first(:css, "a#invisible", visible: :visible, text: 'hidden link')).to be_nil
77
- expect(@session.first(:css, "a#visible", visible: :visible)).not_to be_nil
91
+ expect do
92
+ @session.first(:css, "a#invisible", visible: :visible)
93
+ end.to raise_error Capybara::ElementNotFound
94
+ expect do
95
+ @session.first(:css, "a#invisible", visible: :visible, text: 'hidden link')
96
+ end.to raise_error Capybara::ElementNotFound
97
+ expect(@session.first(:css, "a#visible", visible: :visible)).to be
78
98
  end
79
99
 
80
100
  it "should default to Capybara.ignore_hidden_elements" do
81
101
  Capybara.ignore_hidden_elements = true
82
- expect(@session.first(:css, "a#invisible")).to be_nil
102
+ expect do
103
+ @session.first(:css, "a#invisible")
104
+ end.to raise_error Capybara::ElementNotFound
83
105
  Capybara.ignore_hidden_elements = false
84
- expect(@session.first(:css, "a#invisible")).not_to be_nil
85
- expect(@session.first(:css, "a")).not_to be_nil
106
+ expect(@session.first(:css, "a#invisible")).to be
107
+ expect(@session.first(:css, "a")).to be
86
108
  end
87
109
  end
88
110
 
@@ -93,35 +115,40 @@ Capybara::SpecHelper.spec '#first' do
93
115
 
94
116
  it "should find the first element using the given locator" do
95
117
  @session.within(:xpath, "//div[@id='for_bar']") do
96
- expect(@session.first('.//form')).not_to be_nil
118
+ expect(@session.first('.//form')).to be
97
119
  end
98
120
  end
99
121
  end
100
122
 
101
- context "with Capybara.wait_on_first_by_default", requires: [:js] do
123
+ context "waiting behavior", requires: [:js] do
102
124
  before do
103
125
  @session.visit('/with_js')
104
126
  end
105
127
 
106
- it "should not wait if false" do
107
- Capybara.wait_on_first_by_default = false
128
+ it "should not wait if minimum: 0" do
108
129
  @session.click_link('clickable')
109
- expect(@session.first(:css, 'a#has-been-clicked')).to be_nil
130
+ Capybara.using_wait_time(3) do
131
+ start_time = Time.now
132
+ expect(@session.first(:css, 'a#has-been-clicked', minimum: 0)).to be_nil
133
+ expect(Time.now - start_time).to be < 3
134
+ end
110
135
  end
111
136
 
112
- it "should wait for at least one match if true" do
113
- Capybara.wait_on_first_by_default = true
137
+ it "should wait for at least one match by default" do
114
138
  Capybara.using_wait_time(3) do
115
139
  @session.click_link('clickable')
116
140
  expect(@session.first(:css, 'a#has-been-clicked')).not_to be_nil
117
141
  end
118
142
  end
119
143
 
120
- it "should return nil after waiting if no match" do
121
- Capybara.wait_on_first_by_default = true
144
+ it "should raise an error after waiting if no match" do
145
+ @session.click_link('clickable')
122
146
  Capybara.using_wait_time(3) do
123
- @session.click_link('clickable')
124
- expect(@session.first(:css, 'a#not-a-real-link')).to be_nil
147
+ start_time = Time.now
148
+ expect do
149
+ @session.first(:css, 'a#not-a-real-link')
150
+ end.to raise_error Capybara::ElementNotFound
151
+ expect(Time.now - start_time).to be > 3
125
152
  end
126
153
  end
127
154
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#switch_to_frame', requires: [:frames] do
3
4
  before(:each) do
4
5
  @session.visit('/within_frames')
@@ -47,7 +48,7 @@ Capybara::SpecHelper.spec '#switch_to_frame', requires: [:frames] do
47
48
  end
48
49
  end
49
50
 
50
- it "works if the frame is closed", requires: [:frames, :js] do
51
+ it "works if the frame is closed", requires: %i[frames js] do
51
52
  frame = @session.find(:frame, 'parentFrame')
52
53
  @session.switch_to_frame frame
53
54
  frame = @session.find(:frame, 'childFrame')
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#within_frame', requires: [:frames] do
3
4
  before(:each) do
4
5
  @session.visit('/within_frames')
@@ -56,21 +57,25 @@ Capybara::SpecHelper.spec '#within_frame', requires: [:frames] do
56
57
  it "should find multiple nested frames" do
57
58
  @session.within_frame 'parentFrame' do
58
59
  @session.within_frame 'childFrame' do
59
- @session.within_frame 'grandchildFrame1' do end
60
- @session.within_frame 'grandchildFrame2' do end
60
+ @session.within_frame 'grandchildFrame1' do
61
+ # dummy
62
+ end
63
+ @session.within_frame 'grandchildFrame2' do
64
+ # dummy
65
+ end
61
66
  end
62
67
  end
63
68
  end
64
69
 
65
70
  it "should reset scope when changing frames" do
66
71
  @session.within(:css, '#divInMainWindow') do
67
- @session.within_frame 'parentFrame' do
72
+ @session.within_frame 'innerParentFrame' do
68
73
  expect(@session.has_selector?(:css, "iframe#childFrame")).to be true
69
74
  end
70
75
  end
71
76
  end
72
77
 
73
- it "works if the frame is closed", requires: [:frames, :js] do
78
+ it "works if the frame is closed", requires: %i[frames js] do
74
79
  @session.within_frame 'parentFrame' do
75
80
  @session.within_frame 'childFrame' do
76
81
  @session.click_link 'Close Window'
@@ -79,16 +84,4 @@ Capybara::SpecHelper.spec '#within_frame', requires: [:frames] do
79
84
  expect(@session).not_to have_selector(:css, '#childFrame')
80
85
  end
81
86
  end
82
-
83
- it "should support the driver #switch_to_frame api" do
84
- # This test is purely to notify driver authors to update their API.
85
- # The #switch_to_frame API will be required in the next version (> 2.8) of Capybara for frames support.
86
- # It should not be used as an example of code for users.
87
- frame = @session.find(:frame, "frameOne")
88
- expect {
89
- @session.driver.switch_to_frame(frame)
90
- sleep 0.5
91
- @session.driver.switch_to_frame(:parent)
92
- }.not_to raise_error
93
- end
94
87
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#go_back', requires: [:js] do
3
4
  it "should fetch a response from the driver from the previous page" do
4
5
  @session.visit('/')
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#go_forward', requires: [:js] do
3
4
  it "should fetch a response from the driver from the previous page" do
4
5
  @session.visit('/')
@@ -1,52 +1,53 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#have_all_selectors' do
3
4
  before do
4
5
  @session.visit('/with_html')
5
6
  end
6
7
 
7
8
  it "should be true if the given selectors are on the page" do
8
- expect(@session).to have_all_of_selectors(:css, "p a#foo", "h2#h2one", "h2#h2two" )
9
+ expect(@session).to have_all_of_selectors(:css, "p a#foo", "h2#h2one", "h2#h2two")
9
10
  end
10
11
 
11
12
  it "should be false if any of the given selectors are not on the page" do
12
- expect {
13
+ expect do
13
14
  expect(@session).to have_all_of_selectors(:css, "p a#foo", "h2#h2three", "h2#h2one")
14
- }.to raise_error ::RSpec::Expectations::ExpectationNotMetError
15
+ end.to raise_error ::RSpec::Expectations::ExpectationNotMetError
15
16
  end
16
17
 
17
18
  it "should use default selector" do
18
19
  Capybara.default_selector = :css
19
- expect(@session).to have_all_of_selectors("p a#foo", "h2#h2two", "h2#h2one" )
20
- expect {
20
+ expect(@session).to have_all_of_selectors("p a#foo", "h2#h2two", "h2#h2one")
21
+ expect do
21
22
  expect(@session).to have_all_of_selectors("p a#foo", "h2#h2three", "h2#h2one")
22
- }.to raise_error ::RSpec::Expectations::ExpectationNotMetError
23
+ end.to raise_error ::RSpec::Expectations::ExpectationNotMetError
23
24
  end
24
25
 
25
26
  context "should respect scopes" do
26
27
  it "when used with `within`" do
27
28
  @session.within "//p[@id='first']" do
28
29
  expect(@session).to have_all_of_selectors(".//a[@id='foo']")
29
- expect {
30
+ expect do
30
31
  expect(@session).to have_all_of_selectors(".//a[@id='red']")
31
- }.to raise_error ::RSpec::Expectations::ExpectationNotMetError
32
+ end.to raise_error ::RSpec::Expectations::ExpectationNotMetError
32
33
  end
33
34
  end
34
35
 
35
36
  it "when called on elements" do
36
37
  el = @session.find "//p[@id='first']"
37
38
  expect(el).to have_all_of_selectors(".//a[@id='foo']")
38
- expect {
39
+ expect do
39
40
  expect(el).to have_all_of_selectors(".//a[@id='red']")
40
- }.to raise_error ::RSpec::Expectations::ExpectationNotMetError
41
+ end.to raise_error ::RSpec::Expectations::ExpectationNotMetError
41
42
  end
42
43
  end
43
44
 
44
45
  context "with options" do
45
46
  it "should apply options to all locators" do
46
47
  expect(@session).to have_all_of_selectors(:field, 'normal', 'additional_newline', type: :textarea)
47
- expect {
48
+ expect do
48
49
  expect(@session).to have_all_of_selectors(:field, 'normal', 'test_field', 'additional_newline', type: :textarea)
49
- }.to raise_error ::RSpec::Expectations::ExpectationNotMetError
50
+ end.to raise_error ::RSpec::Expectations::ExpectationNotMetError
50
51
  end
51
52
  end
52
53
 
@@ -61,9 +62,8 @@ Capybara::SpecHelper.spec '#have_all_selectors' do
61
62
  end
62
63
 
63
64
  it "cannot be negated" do
64
- expect {
65
+ expect do
65
66
  expect(@session).not_to have_all_of_selectors(:css, "p a#foo", "h2#h2one", "h2#h2two")
66
- }.to raise_error ArgumentError
67
+ end.to raise_error ArgumentError
67
68
  end
68
69
  end
69
-