capybara 2.18.0 → 3.0.0

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 (172) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +55 -1
  3. data/README.md +18 -17
  4. data/lib/capybara/config.rb +11 -58
  5. data/lib/capybara/cucumber.rb +2 -3
  6. data/lib/capybara/driver/base.rb +15 -16
  7. data/lib/capybara/driver/node.rb +5 -4
  8. data/lib/capybara/dsl.rb +1 -0
  9. data/lib/capybara/helpers.rb +19 -29
  10. data/lib/capybara/minitest/spec.rb +15 -14
  11. data/lib/capybara/minitest.rb +139 -138
  12. data/lib/capybara/node/actions.rb +60 -81
  13. data/lib/capybara/node/base.rb +11 -18
  14. data/lib/capybara/node/document.rb +2 -2
  15. data/lib/capybara/node/document_matchers.rb +8 -8
  16. data/lib/capybara/node/element.rb +30 -40
  17. data/lib/capybara/node/finders.rb +62 -70
  18. data/lib/capybara/node/matchers.rb +50 -71
  19. data/lib/capybara/node/simple.rb +11 -17
  20. data/lib/capybara/queries/ancestor_query.rb +11 -7
  21. data/lib/capybara/queries/base_query.rb +22 -18
  22. data/lib/capybara/queries/current_path_query.rb +8 -24
  23. data/lib/capybara/queries/match_query.rb +3 -7
  24. data/lib/capybara/queries/selector_query.rb +92 -95
  25. data/lib/capybara/queries/sibling_query.rb +4 -4
  26. data/lib/capybara/queries/text_query.rb +35 -35
  27. data/lib/capybara/queries/title_query.rb +8 -11
  28. data/lib/capybara/rack_test/browser.rb +15 -18
  29. data/lib/capybara/rack_test/css_handlers.rb +6 -4
  30. data/lib/capybara/rack_test/driver.rb +6 -10
  31. data/lib/capybara/rack_test/form.rb +50 -40
  32. data/lib/capybara/rack_test/node.rb +93 -63
  33. data/lib/capybara/rails.rb +2 -6
  34. data/lib/capybara/result.rb +22 -22
  35. data/lib/capybara/rspec/compound.rb +5 -10
  36. data/lib/capybara/rspec/features.rb +17 -48
  37. data/lib/capybara/rspec/matcher_proxies.rb +31 -15
  38. data/lib/capybara/rspec/matchers.rb +70 -61
  39. data/lib/capybara/rspec.rb +5 -10
  40. data/lib/capybara/selector/css.rb +6 -11
  41. data/lib/capybara/selector/filter.rb +1 -17
  42. data/lib/capybara/selector/filter_set.rb +18 -15
  43. data/lib/capybara/selector/filters/base.rb +7 -6
  44. data/lib/capybara/selector/filters/expression_filter.rb +6 -23
  45. data/lib/capybara/selector/filters/node_filter.rb +2 -12
  46. data/lib/capybara/selector/selector.rb +28 -34
  47. data/lib/capybara/selector.rb +129 -117
  48. data/lib/capybara/selenium/driver.rb +131 -125
  49. data/lib/capybara/selenium/node.rb +197 -115
  50. data/lib/capybara/server.rb +3 -2
  51. data/lib/capybara/session/config.rb +47 -67
  52. data/lib/capybara/session/matchers.rb +8 -7
  53. data/lib/capybara/session.rb +138 -224
  54. data/lib/capybara/spec/public/test.js +25 -4
  55. data/lib/capybara/spec/session/accept_alert_spec.rb +1 -0
  56. data/lib/capybara/spec/session/accept_confirm_spec.rb +3 -2
  57. data/lib/capybara/spec/session/accept_prompt_spec.rb +1 -0
  58. data/lib/capybara/spec/session/all_spec.rb +31 -18
  59. data/lib/capybara/spec/session/ancestor_spec.rb +6 -8
  60. data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +6 -5
  61. data/lib/capybara/spec/session/assert_current_path.rb +12 -11
  62. data/lib/capybara/spec/session/assert_selector.rb +1 -0
  63. data/lib/capybara/spec/session/assert_text.rb +23 -23
  64. data/lib/capybara/spec/session/assert_title.rb +13 -3
  65. data/lib/capybara/spec/session/attach_file_spec.rb +51 -30
  66. data/lib/capybara/spec/session/body_spec.rb +1 -0
  67. data/lib/capybara/spec/session/check_spec.rb +7 -6
  68. data/lib/capybara/spec/session/choose_spec.rb +5 -4
  69. data/lib/capybara/spec/session/click_button_spec.rb +24 -32
  70. data/lib/capybara/spec/session/click_link_or_button_spec.rb +8 -7
  71. data/lib/capybara/spec/session/click_link_spec.rb +8 -7
  72. data/lib/capybara/spec/session/current_scope_spec.rb +4 -3
  73. data/lib/capybara/spec/session/current_url_spec.rb +17 -6
  74. data/lib/capybara/spec/session/dismiss_confirm_spec.rb +1 -1
  75. data/lib/capybara/spec/session/dismiss_prompt_spec.rb +1 -0
  76. data/lib/capybara/spec/session/element/assert_match_selector.rb +1 -1
  77. data/lib/capybara/spec/session/element/match_xpath_spec.rb +1 -1
  78. data/lib/capybara/spec/session/element/matches_selector_spec.rb +5 -5
  79. data/lib/capybara/spec/session/evaluate_async_script_spec.rb +3 -2
  80. data/lib/capybara/spec/session/evaluate_script_spec.rb +4 -3
  81. data/lib/capybara/spec/session/execute_script_spec.rb +4 -3
  82. data/lib/capybara/spec/session/fill_in_spec.rb +30 -5
  83. data/lib/capybara/spec/session/find_button_spec.rb +4 -3
  84. data/lib/capybara/spec/session/find_by_id_spec.rb +2 -1
  85. data/lib/capybara/spec/session/find_field_spec.rb +9 -15
  86. data/lib/capybara/spec/session/find_link_spec.rb +6 -5
  87. data/lib/capybara/spec/session/find_spec.rb +37 -31
  88. data/lib/capybara/spec/session/first_spec.rb +60 -33
  89. data/lib/capybara/spec/session/frame/frame_title_spec.rb +23 -0
  90. data/lib/capybara/spec/session/frame/frame_url_spec.rb +23 -0
  91. data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +2 -1
  92. data/lib/capybara/spec/session/frame/within_frame_spec.rb +9 -16
  93. data/lib/capybara/spec/session/go_back_spec.rb +1 -0
  94. data/lib/capybara/spec/session/go_forward_spec.rb +1 -0
  95. data/lib/capybara/spec/session/has_all_selectors_spec.rb +15 -15
  96. data/lib/capybara/spec/session/has_button_spec.rb +2 -1
  97. data/lib/capybara/spec/session/has_css_spec.rb +3 -2
  98. data/lib/capybara/spec/session/has_current_path_spec.rb +12 -28
  99. data/lib/capybara/spec/session/has_field_spec.rb +4 -3
  100. data/lib/capybara/spec/session/has_link_spec.rb +1 -0
  101. data/lib/capybara/spec/session/has_none_selectors_spec.rb +17 -17
  102. data/lib/capybara/spec/session/has_select_spec.rb +30 -29
  103. data/lib/capybara/spec/session/has_selector_spec.rb +5 -4
  104. data/lib/capybara/spec/session/has_table_spec.rb +2 -1
  105. data/lib/capybara/spec/session/has_text_spec.rb +9 -13
  106. data/lib/capybara/spec/session/has_title_spec.rb +1 -0
  107. data/lib/capybara/spec/session/has_xpath_spec.rb +1 -0
  108. data/lib/capybara/spec/session/headers.rb +2 -1
  109. data/lib/capybara/spec/session/html_spec.rb +1 -0
  110. data/lib/capybara/spec/session/node_spec.rb +91 -56
  111. data/lib/capybara/spec/session/node_wrapper_spec.rb +36 -0
  112. data/lib/capybara/spec/session/refresh_spec.rb +6 -2
  113. data/lib/capybara/spec/session/reset_session_spec.rb +19 -0
  114. data/lib/capybara/spec/session/response_code.rb +1 -0
  115. data/lib/capybara/spec/session/save_and_open_page_spec.rb +1 -0
  116. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +6 -11
  117. data/lib/capybara/spec/session/save_page_spec.rb +1 -17
  118. data/lib/capybara/spec/session/save_screenshot_spec.rb +3 -3
  119. data/lib/capybara/spec/session/select_spec.rb +20 -20
  120. data/lib/capybara/spec/session/selectors_spec.rb +2 -2
  121. data/lib/capybara/spec/session/sibling_spec.rb +1 -1
  122. data/lib/capybara/spec/session/text_spec.rb +17 -3
  123. data/lib/capybara/spec/session/title_spec.rb +11 -1
  124. data/lib/capybara/spec/session/uncheck_spec.rb +4 -3
  125. data/lib/capybara/spec/session/unselect_spec.rb +6 -5
  126. data/lib/capybara/spec/session/visit_spec.rb +9 -3
  127. data/lib/capybara/spec/session/window/become_closed_spec.rb +2 -1
  128. data/lib/capybara/spec/session/window/current_window_spec.rb +1 -0
  129. data/lib/capybara/spec/session/window/open_new_window_spec.rb +1 -0
  130. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +2 -1
  131. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +2 -1
  132. data/lib/capybara/spec/session/window/window_spec.rb +12 -12
  133. data/lib/capybara/spec/session/window/windows_spec.rb +2 -3
  134. data/lib/capybara/spec/session/window/within_window_spec.rb +15 -71
  135. data/lib/capybara/spec/session/within_spec.rb +1 -0
  136. data/lib/capybara/spec/spec_helper.rb +34 -18
  137. data/lib/capybara/spec/test_app.rb +17 -9
  138. data/lib/capybara/spec/views/form.erb +7 -0
  139. data/lib/capybara/spec/views/with_html.erb +23 -1
  140. data/lib/capybara/spec/views/within_frames.erb +4 -1
  141. data/lib/capybara/version.rb +2 -1
  142. data/lib/capybara/window.rb +6 -10
  143. data/lib/capybara.rb +28 -25
  144. data/spec/basic_node_spec.rb +1 -0
  145. data/spec/capybara_spec.rb +11 -50
  146. data/spec/dsl_spec.rb +5 -13
  147. data/spec/filter_set_spec.rb +5 -4
  148. data/spec/fixtures/selenium_driver_rspec_failure.rb +2 -1
  149. data/spec/fixtures/selenium_driver_rspec_success.rb +3 -2
  150. data/spec/minitest_spec.rb +4 -3
  151. data/spec/minitest_spec_spec.rb +3 -2
  152. data/spec/per_session_config_spec.rb +9 -8
  153. data/spec/rack_test_spec.rb +21 -20
  154. data/spec/result_spec.rb +17 -16
  155. data/spec/rspec/features_spec.rb +17 -14
  156. data/spec/rspec/scenarios_spec.rb +5 -7
  157. data/spec/rspec/shared_spec_matchers.rb +96 -99
  158. data/spec/rspec/views_spec.rb +2 -1
  159. data/spec/rspec_matchers_spec.rb +18 -2
  160. data/spec/rspec_spec.rb +11 -15
  161. data/spec/selector_spec.rb +5 -6
  162. data/spec/selenium_spec_chrome.rb +9 -4
  163. data/spec/selenium_spec_edge.rb +27 -0
  164. data/spec/selenium_spec_ie.rb +31 -0
  165. data/spec/selenium_spec_marionette.rb +28 -12
  166. data/spec/server_spec.rb +33 -33
  167. data/spec/session_spec.rb +2 -1
  168. data/spec/shared_selenium_session.rb +36 -22
  169. data/spec/spec_helper.rb +3 -6
  170. metadata +68 -85
  171. data/lib/capybara/query.rb +0 -7
  172. data/spec/selenium_spec_firefox.rb +0 -68
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Capybara
3
4
  module Node
4
5
  module Matchers
5
-
6
6
  ##
7
7
  #
8
8
  # Checks if a given selector is on the page or a descendant of the current node.
@@ -39,7 +39,7 @@ module Capybara
39
39
  def has_selector?(*args, &optional_filter_block)
40
40
  assert_selector(*args, &optional_filter_block)
41
41
  rescue Capybara::ExpectationNotMet
42
- return false
42
+ false
43
43
  end
44
44
 
45
45
  ##
@@ -53,7 +53,7 @@ module Capybara
53
53
  def has_no_selector?(*args, &optional_filter_block)
54
54
  assert_no_selector(*args, &optional_filter_block)
55
55
  rescue Capybara::ExpectationNotMet
56
- return false
56
+ false
57
57
  end
58
58
 
59
59
  ##
@@ -91,7 +91,7 @@ module Capybara
91
91
  #
92
92
  def assert_selector(*args, &optional_filter_block)
93
93
  _verify_selector_result(args, optional_filter_block) do |result, query|
94
- unless result.matches_count? && ((!result.empty?) || query.expects_none?)
94
+ unless result.matches_count? && (!result.empty? || query.expects_none?)
95
95
  raise Capybara::ExpectationNotMet, result.failure_message
96
96
  end
97
97
  end
@@ -112,10 +112,9 @@ module Capybara
112
112
  #
113
113
  # @overload assert_all_of_selectors([kind = Capybara.default_selector], *locators, options = {})
114
114
  #
115
- def assert_all_of_selectors(*args, &optional_filter_block)
116
- options = if args.last.is_a?(Hash) then args.pop.dup else {} end
117
- selector = if args.first.is_a?(Symbol) then args.shift else session_options.default_selector end
118
- wait = options.fetch(:wait, session_options.default_max_wait_time)
115
+ def assert_all_of_selectors(*args, wait: nil, **options, &optional_filter_block)
116
+ wait = session_options.default_max_wait_time if wait.nil?
117
+ selector = args.first.is_a?(Symbol) ? args.shift : session_options.default_selector
119
118
  synchronize(wait) do
120
119
  args.each do |locator|
121
120
  assert_selector(selector, locator, options, &optional_filter_block)
@@ -138,10 +137,9 @@ module Capybara
138
137
  #
139
138
  # @overload assert_none_of_selectors([kind = Capybara.default_selector], *locators, options = {})
140
139
  #
141
- def assert_none_of_selectors(*args, &optional_filter_block)
142
- options = if args.last.is_a?(Hash) then args.pop.dup else {} end
143
- selector = if args.first.is_a?(Symbol) then args.shift else session_options.default_selector end
144
- wait = options.fetch(:wait, session_options.default_max_wait_time)
140
+ def assert_none_of_selectors(*args, wait: nil, **options, &optional_filter_block)
141
+ wait = session_options.default_max_wait_time if wait.nil?
142
+ selector = args.first.is_a?(Symbol) ? args.shift : session_options.default_selector
145
143
  synchronize(wait) do
146
144
  args.each do |locator|
147
145
  assert_no_selector(selector, locator, options, &optional_filter_block)
@@ -167,7 +165,7 @@ module Capybara
167
165
  #
168
166
  def assert_no_selector(*args, &optional_filter_block)
169
167
  _verify_selector_result(args, optional_filter_block) do |result, query|
170
- if result.matches_count? && ((!result.empty?) || query.expects_none?)
168
+ if result.matches_count? && (!result.empty? || query.expects_none?)
171
169
  raise Capybara::ExpectationNotMet, result.negative_failure_message
172
170
  end
173
171
  end
@@ -203,7 +201,7 @@ module Capybara
203
201
  # @option options [Integer] :count (nil) Number of times the expression should occur
204
202
  # @return [Boolean] If the expression exists
205
203
  #
206
- def has_xpath?(path, options={}, &optional_filter_block)
204
+ def has_xpath?(path, **options, &optional_filter_block)
207
205
  has_selector?(:xpath, path, options, &optional_filter_block)
208
206
  end
209
207
 
@@ -215,7 +213,7 @@ module Capybara
215
213
  # @param (see Capybara::Node::Finders#has_xpath?)
216
214
  # @return [Boolean]
217
215
  #
218
- def has_no_xpath?(path, options={}, &optional_filter_block)
216
+ def has_no_xpath?(path, **options, &optional_filter_block)
219
217
  has_no_selector?(:xpath, path, options, &optional_filter_block)
220
218
  end
221
219
 
@@ -242,7 +240,7 @@ module Capybara
242
240
  # @option options [Integer] :count (nil) Number of times the selector should occur
243
241
  # @return [Boolean] If the selector exists
244
242
  #
245
- def has_css?(path, options={}, &optional_filter_block)
243
+ def has_css?(path, **options, &optional_filter_block)
246
244
  has_selector?(:css, path, options, &optional_filter_block)
247
245
  end
248
246
 
@@ -254,7 +252,7 @@ module Capybara
254
252
  # @param (see Capybara::Node::Finders#has_css?)
255
253
  # @return [Boolean]
256
254
  #
257
- def has_no_css?(path, options={}, &optional_filter_block)
255
+ def has_no_css?(path, **options, &optional_filter_block)
258
256
  has_no_selector?(:css, path, options, &optional_filter_block)
259
257
  end
260
258
 
@@ -268,8 +266,7 @@ module Capybara
268
266
  # @option options [String, Regexp] :href The value the href attribute must be
269
267
  # @return [Boolean] Whether it exists
270
268
  #
271
- def has_link?(locator=nil, options={}, &optional_filter_block)
272
- locator, options = nil, locator if locator.is_a? Hash
269
+ def has_link?(locator = nil, **options, &optional_filter_block)
273
270
  has_selector?(:link, locator, options, &optional_filter_block)
274
271
  end
275
272
 
@@ -281,8 +278,7 @@ module Capybara
281
278
  # @param (see Capybara::Node::Finders#has_link?)
282
279
  # @return [Boolean] Whether it doesn't exist
283
280
  #
284
- def has_no_link?(locator=nil, options={}, &optional_filter_block)
285
- locator, options = nil, locator if locator.is_a? Hash
281
+ def has_no_link?(locator = nil, **options, &optional_filter_block)
286
282
  has_no_selector?(:link, locator, options, &optional_filter_block)
287
283
  end
288
284
 
@@ -294,8 +290,7 @@ module Capybara
294
290
  # @param [String] locator The text, value or id of a button to check for
295
291
  # @return [Boolean] Whether it exists
296
292
  #
297
- def has_button?(locator=nil, options={}, &optional_filter_block)
298
- locator, options = nil, locator if locator.is_a? Hash
293
+ def has_button?(locator = nil, **options, &optional_filter_block)
299
294
  has_selector?(:button, locator, options, &optional_filter_block)
300
295
  end
301
296
 
@@ -307,8 +302,7 @@ module Capybara
307
302
  # @param [String] locator The text, value or id of a button to check for
308
303
  # @return [Boolean] Whether it doesn't exist
309
304
  #
310
- def has_no_button?(locator=nil, options={}, &optional_filter_block)
311
- locator, options = nil, locator if locator.is_a? Hash
305
+ def has_no_button?(locator = nil, **options, &optional_filter_block)
312
306
  has_no_selector?(:button, locator, options, &optional_filter_block)
313
307
  end
314
308
 
@@ -334,8 +328,7 @@ module Capybara
334
328
  # @option options [String] :type The type attribute of the field
335
329
  # @return [Boolean] Whether it exists
336
330
  #
337
- def has_field?(locator=nil, options={}, &optional_filter_block)
338
- locator, options = nil, locator if locator.is_a? Hash
331
+ def has_field?(locator = nil, **options, &optional_filter_block)
339
332
  has_selector?(:field, locator, options, &optional_filter_block)
340
333
  end
341
334
 
@@ -349,8 +342,7 @@ module Capybara
349
342
  # @option options [String] :type The type attribute of the field
350
343
  # @return [Boolean] Whether it doesn't exist
351
344
  #
352
- def has_no_field?(locator=nil, options={}, &optional_filter_block)
353
- locator, options = nil, locator if locator.is_a? Hash
345
+ def has_no_field?(locator = nil, **options, &optional_filter_block)
354
346
  has_no_selector?(:field, locator, options, &optional_filter_block)
355
347
  end
356
348
 
@@ -363,8 +355,7 @@ module Capybara
363
355
  # @param [String] locator The label, name or id of a checked field
364
356
  # @return [Boolean] Whether it exists
365
357
  #
366
- def has_checked_field?(locator=nil, options={}, &optional_filter_block)
367
- locator, options = nil, locator if locator.is_a? Hash
358
+ def has_checked_field?(locator = nil, **options, &optional_filter_block)
368
359
  has_selector?(:field, locator, options.merge(checked: true), &optional_filter_block)
369
360
  end
370
361
 
@@ -377,8 +368,7 @@ module Capybara
377
368
  # @param [String] locator The label, name or id of a checked field
378
369
  # @return [Boolean] Whether it doesn't exist
379
370
  #
380
- def has_no_checked_field?(locator=nil, options={}, &optional_filter_block)
381
- locator, options = nil, locator if locator.is_a? Hash
371
+ def has_no_checked_field?(locator = nil, **options, &optional_filter_block)
382
372
  has_no_selector?(:field, locator, options.merge(checked: true), &optional_filter_block)
383
373
  end
384
374
 
@@ -391,8 +381,7 @@ module Capybara
391
381
  # @param [String] locator The label, name or id of an unchecked field
392
382
  # @return [Boolean] Whether it exists
393
383
  #
394
- def has_unchecked_field?(locator=nil, options={}, &optional_filter_block)
395
- locator, options = nil, locator if locator.is_a? Hash
384
+ def has_unchecked_field?(locator = nil, **options, &optional_filter_block)
396
385
  has_selector?(:field, locator, options.merge(unchecked: true), &optional_filter_block)
397
386
  end
398
387
 
@@ -405,8 +394,7 @@ module Capybara
405
394
  # @param [String] locator The label, name or id of an unchecked field
406
395
  # @return [Boolean] Whether it doesn't exist
407
396
  #
408
- def has_no_unchecked_field?(locator=nil, options={}, &optional_filter_block)
409
- locator, options = nil, locator if locator.is_a? Hash
397
+ def has_no_unchecked_field?(locator = nil, **options, &optional_filter_block)
410
398
  has_no_selector?(:field, locator, options.merge(unchecked: true), &optional_filter_block)
411
399
  end
412
400
 
@@ -439,8 +427,7 @@ module Capybara
439
427
  # @option options [String, Array] :with_selected Partial set of options which should minimally be selected
440
428
  # @return [Boolean] Whether it exists
441
429
  #
442
- def has_select?(locator=nil, options={}, &optional_filter_block)
443
- locator, options = nil, locator if locator.is_a? Hash
430
+ def has_select?(locator = nil, **options, &optional_filter_block)
444
431
  has_selector?(:select, locator, options, &optional_filter_block)
445
432
  end
446
433
 
@@ -452,8 +439,7 @@ module Capybara
452
439
  # @param (see Capybara::Node::Matchers#has_select?)
453
440
  # @return [Boolean] Whether it doesn't exist
454
441
  #
455
- def has_no_select?(locator=nil, options={}, &optional_filter_block)
456
- locator, options = nil, locator if locator.is_a? Hash
442
+ def has_no_select?(locator = nil, **options, &optional_filter_block)
457
443
  has_no_selector?(:select, locator, options, &optional_filter_block)
458
444
  end
459
445
 
@@ -467,8 +453,7 @@ module Capybara
467
453
  # @param [String] locator The id or caption of a table
468
454
  # @return [Boolean] Whether it exist
469
455
  #
470
- def has_table?(locator=nil, options={}, &optional_filter_block)
471
- locator, options = nil, locator if locator.is_a? Hash
456
+ def has_table?(locator = nil, **options, &optional_filter_block)
472
457
  has_selector?(:table, locator, options, &optional_filter_block)
473
458
  end
474
459
 
@@ -480,8 +465,7 @@ module Capybara
480
465
  # @param (see Capybara::Node::Matchers#has_table?)
481
466
  # @return [Boolean] Whether it doesn't exist
482
467
  #
483
- def has_no_table?(locator=nil, options={}, &optional_filter_block)
484
- locator, options = nil, locator if locator.is_a? Hash
468
+ def has_no_table?(locator = nil, **options, &optional_filter_block)
485
469
  has_no_selector?(:table, locator, options, &optional_filter_block)
486
470
  end
487
471
 
@@ -534,7 +518,7 @@ module Capybara
534
518
  # @param [String, XPath::Expression] xpath The XPath expression to match against the current code
535
519
  # @return [Boolean]
536
520
  #
537
- def matches_xpath?(xpath, options={}, &optional_filter_block)
521
+ def matches_xpath?(xpath, **options, &optional_filter_block)
538
522
  matches_selector?(:xpath, xpath, options, &optional_filter_block)
539
523
  end
540
524
 
@@ -545,7 +529,7 @@ module Capybara
545
529
  # @param [String] css The CSS selector to match against the current code
546
530
  # @return [Boolean]
547
531
  #
548
- def matches_css?(css, options={}, &optional_filter_block)
532
+ def matches_css?(css, **options, &optional_filter_block)
549
533
  matches_selector?(:css, css, options, &optional_filter_block)
550
534
  end
551
535
 
@@ -570,7 +554,7 @@ module Capybara
570
554
  # @param [String, XPath::Expression] xpath The XPath expression to match against the current code
571
555
  # @return [Boolean]
572
556
  #
573
- def not_matches_xpath?(xpath, options={}, &optional_filter_block)
557
+ def not_matches_xpath?(xpath, **options, &optional_filter_block)
574
558
  not_matches_selector?(:xpath, xpath, options, &optional_filter_block)
575
559
  end
576
560
 
@@ -581,11 +565,10 @@ module Capybara
581
565
  # @param [String] css The CSS selector to match against the current code
582
566
  # @return [Boolean]
583
567
  #
584
- def not_matches_css?(css, options={}, &optional_filter_block)
568
+ def not_matches_css?(css, **options, &optional_filter_block)
585
569
  not_matches_selector?(:css, css, options, &optional_filter_block)
586
570
  end
587
571
 
588
-
589
572
  ##
590
573
  # Asserts that the page or current node has the given text content,
591
574
  # ignoring any HTML tags.
@@ -656,7 +639,7 @@ module Capybara
656
639
  def has_text?(*args)
657
640
  assert_text(*args)
658
641
  rescue Capybara::ExpectationNotMet
659
- return false
642
+ false
660
643
  end
661
644
  alias_method :has_content?, :has_text?
662
645
 
@@ -670,53 +653,49 @@ module Capybara
670
653
  def has_no_text?(*args)
671
654
  assert_no_text(*args)
672
655
  rescue Capybara::ExpectationNotMet
673
- return false
656
+ false
674
657
  end
675
658
  alias_method :has_no_content?, :has_no_text?
676
659
 
677
660
  def ==(other)
678
- self.eql?(other) || (other.respond_to?(:base) && base == other.base)
661
+ eql?(other) || (other.respond_to?(:base) && base == other.base)
679
662
  end
680
663
 
681
664
  private
682
665
 
683
- def _verify_selector_result(query_args, optional_filter_block, &result_block)
684
- _set_query_session_options(query_args)
666
+ def _verify_selector_result(query_args, optional_filter_block)
667
+ query_args = _set_query_session_options(*query_args)
685
668
  query = Capybara::Queries::SelectorQuery.new(*query_args, &optional_filter_block)
686
669
  synchronize(query.wait) do
687
670
  result = query.resolve_for(self)
688
- result_block.call(result, query)
671
+ yield result, query
689
672
  end
690
- return true
673
+ true
691
674
  end
692
675
 
693
- def _verify_match_result(query_args, optional_filter_block, &result_block)
694
- _set_query_session_options(query_args)
676
+ def _verify_match_result(query_args, optional_filter_block)
677
+ query_args = _set_query_session_options(*query_args)
695
678
  query = Capybara::Queries::MatchQuery.new(*query_args, &optional_filter_block)
696
679
  synchronize(query.wait) do
697
- result = query.resolve_for(self.query_scope)
698
- result_block.call(result)
680
+ result = query.resolve_for(query_scope)
681
+ yield result
699
682
  end
700
- return true
683
+ true
701
684
  end
702
685
 
703
686
  def _verify_text(query_args)
704
- _set_query_session_options(query_args)
687
+ query_args = _set_query_session_options(*query_args)
705
688
  query = Capybara::Queries::TextQuery.new(*query_args)
706
689
  synchronize(query.wait) do
707
690
  count = query.resolve_for(self)
708
691
  yield(count, query)
709
692
  end
710
- return true
693
+ true
711
694
  end
712
695
 
713
- def _set_query_session_options(query_args)
714
- if query_args.last.is_a? Hash
715
- query_args.last[:session_options] = session_options
716
- else
717
- query_args.push(session_options: session_options)
718
- end
719
- query_args
696
+ def _set_query_session_options(*query_args, **query_options)
697
+ query_options[:session_options] = session_options
698
+ query_args.push(query_options)
720
699
  end
721
700
  end
722
701
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Capybara
3
4
  module Node
4
-
5
5
  ##
6
6
  #
7
7
  # A {Capybara::Node::Simple} is a simpler version of {Capybara::Node::Base} which
@@ -28,7 +28,7 @@ module Capybara
28
28
  #
29
29
  # @return [String] The text of the element
30
30
  #
31
- def text(type=nil)
31
+ def text(_type = nil)
32
32
  native.text
33
33
  end
34
34
 
@@ -45,7 +45,7 @@ module Capybara
45
45
  attr_name = name.to_s
46
46
  if attr_name == 'value'
47
47
  value
48
- elsif 'input' == tag_name and 'checkbox' == native[:type] and 'checked' == attr_name
48
+ elsif tag_name == 'input' and native[:type] == 'checkbox' and attr_name == 'checked'
49
49
  native['checked'] == 'checked'
50
50
  else
51
51
  native[attr_name]
@@ -79,12 +79,12 @@ module Capybara
79
79
  native['_capybara_raw_value']
80
80
  elsif tag_name == 'select'
81
81
  if native['multiple'] == 'multiple'
82
- native.xpath(".//option[@selected='selected']").map { |option| option[:value] || option.content }
82
+ native.xpath(".//option[@selected='selected']").map { |option| option[:value] || option.content }
83
83
  else
84
84
  option = native.xpath(".//option[@selected='selected']").first || native.xpath(".//option").first
85
85
  option[:value] || option.content if option
86
86
  end
87
- elsif tag_name == 'input' && %w(radio checkbox).include?(native[:type])
87
+ elsif tag_name == 'input' && %w[radio checkbox].include?(native[:type])
88
88
  native[:value] || 'on'
89
89
  else
90
90
  native[:value]
@@ -100,14 +100,13 @@ module Capybara
100
100
  # @return [Boolean] Whether the element is visible
101
101
  #
102
102
  def visible?(check_ancestors = true)
103
- return false if (tag_name == 'input') && (native[:type]=="hidden")
103
+ return false if (tag_name == 'input') && (native[:type] == "hidden")
104
104
 
105
105
  if check_ancestors
106
- #check size because oldest supported nokogiri doesnt support xpath boolean() function
107
- native.xpath("./ancestor-or-self::*[contains(@style, 'display:none') or contains(@style, 'display: none') or @hidden or name()='script' or name()='head']").size() == 0
106
+ !native.xpath("boolean(./ancestor-or-self::*[contains(@style, 'display:none') or contains(@style, 'display: none') or @hidden or name()='script' or name()='head'])")
108
107
  else
109
- #no need for an xpath if only checking the current element
110
- !(native.has_attribute?('hidden') || (native[:style] =~ /display:\s?none/) || %w(script head).include?(tag_name))
108
+ # No need for an xpath if only checking the current element
109
+ !(native.has_attribute?('hidden') || (native[:style] =~ /display:\s?none/) || %w[script head].include?(tag_name))
111
110
  end
112
111
  end
113
112
 
@@ -140,7 +139,7 @@ module Capybara
140
139
  native.has_attribute?('selected')
141
140
  end
142
141
 
143
- def synchronize(seconds=nil)
142
+ def synchronize(_seconds = nil)
144
143
  yield # simple nodes don't need to wait
145
144
  end
146
145
 
@@ -152,12 +151,7 @@ module Capybara
152
151
  #
153
152
  # @return [String] The title of the document
154
153
  def title
155
- if native.respond_to? :title
156
- native.title
157
- else
158
- #old versions of nokogiri don't have #title - remove in 3.0
159
- native.xpath('/html/head/title | /html/title').first.text
160
- end
154
+ native.title
161
155
  end
162
156
 
163
157
  def inspect
@@ -1,25 +1,29 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Capybara
3
4
  module Queries
4
- class AncestorQuery < MatchQuery
5
+ class AncestorQuery < Capybara::Queries::SelectorQuery
5
6
  # @api private
6
7
  def resolve_for(node, exact = nil)
7
8
  @child_node = node
8
9
  node.synchronize do
9
10
  match_results = super(node.session.current_scope, exact)
10
- node.all(:xpath, XPath.ancestor) do |el|
11
- match_results.include?(el)
12
- end
11
+ node.all(:xpath, XPath.ancestor) { |el| match_results.include?(el) }
13
12
  end
14
13
  end
15
14
 
16
15
  def description
16
+ child_query = @child_node && @child_node.instance_variable_get(:@query)
17
17
  desc = super
18
- if @child_node && (child_query = @child_node.instance_variable_get(:@query))
19
- desc += " that is an ancestor of #{child_query.description}"
20
- end
18
+ desc += " that is an ancestor of #{child_query.description}" if child_query
21
19
  desc
22
20
  end
21
+
22
+ private
23
+
24
+ def valid_keys
25
+ super - COUNT_KEYS
26
+ end
23
27
  end
24
28
  end
25
29
  end
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Capybara
3
4
  # @api private
4
5
  module Queries
5
6
  class BaseQuery
6
- COUNT_KEYS = [:count, :minimum, :maximum, :between]
7
+ COUNT_KEYS = %i[count minimum maximum between].freeze
7
8
 
8
9
  attr_reader :options
9
10
  attr_writer :session_options
@@ -20,8 +21,11 @@ module Capybara
20
21
  self.class.wait(options, session_options.default_max_wait_time)
21
22
  end
22
23
 
23
- def self.wait(options, default=Capybara.default_max_wait_time)
24
- options.fetch(:wait, default) || 0
24
+ def self.wait(options, default = Capybara.default_max_wait_time)
25
+ # if no value or nil for the :wait option is passed it should default to the default
26
+ w = options.fetch(:wait, nil)
27
+ w = default if w.nil?
28
+ w || 0
25
29
  end
26
30
 
27
31
  ##
@@ -30,11 +34,7 @@ module Capybara
30
34
  # Returns false if query does not have any count options specified.
31
35
  #
32
36
  def expects_none?
33
- if COUNT_KEYS.any? { |k| options.has_key? k }
34
- matches_count?(0)
35
- else
36
- false
37
- end
37
+ count_specified? ? matches_count?(0) : false
38
38
  end
39
39
 
40
40
  ##
@@ -47,11 +47,11 @@ module Capybara
47
47
  # @param [Integer] count The actual number. Should be coercible via Integer()
48
48
  #
49
49
  def matches_count?(count)
50
- return (Integer(options[:count]) == count) if options[:count]
50
+ return (Integer(options[:count]) == count) if options[:count]
51
51
  return false if options[:maximum] && (Integer(options[:maximum]) < count)
52
52
  return false if options[:minimum] && (Integer(options[:minimum]) > count)
53
- return false if options[:between] && !(options[:between] === count)
54
- return true
53
+ return false if options[:between] && !options[:between].include?(count)
54
+ true
55
55
  end
56
56
 
57
57
  ##
@@ -66,10 +66,14 @@ module Capybara
66
66
  String.new("expected not to find #{description}") << count_message
67
67
  end
68
68
 
69
- private
69
+ private
70
+
71
+ def count_specified?
72
+ COUNT_KEYS.any? { |k| options.key? k }
73
+ end
70
74
 
71
75
  def count_message
72
- message = String.new()
76
+ message = "".dup
73
77
  if options[:count]
74
78
  message << " #{options[:count]} #{Capybara::Helpers.declension('time', 'times', options[:count])}"
75
79
  elsif options[:between]
@@ -84,11 +88,11 @@ module Capybara
84
88
 
85
89
  def assert_valid_keys
86
90
  invalid_keys = @options.keys - valid_keys
87
- unless invalid_keys.empty?
88
- invalid_names = invalid_keys.map(&:inspect).join(", ")
89
- valid_names = valid_keys.map(&:inspect).join(", ")
90
- raise ArgumentError, "invalid keys #{invalid_names}, should be one of #{valid_names}"
91
- end
91
+ return if invalid_keys.empty?
92
+
93
+ invalid_names = invalid_keys.map(&:inspect).join(", ")
94
+ valid_names = valid_keys.map(&:inspect).join(", ")
95
+ raise ArgumentError, "invalid keys #{invalid_names}, should be one of #{valid_names}"
92
96
  end
93
97
  end
94
98
  end
@@ -1,34 +1,25 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'addressable/uri'
3
4
 
4
5
  module Capybara
5
6
  # @api private
6
7
  module Queries
7
8
  class CurrentPathQuery < BaseQuery
8
- def initialize(expected_path, options = {})
9
+ def initialize(expected_path, **options)
9
10
  super(options)
10
11
  @expected_path = expected_path
11
- warn "DEPRECATED: The :only_path option is deprecated in favor of the :ignore_query option" if options.has_key?(:only_path)
12
-
13
12
  @options = {
14
13
  url: !@expected_path.is_a?(Regexp) && !::Addressable::URI.parse(@expected_path || "").hostname.nil?,
15
- only_path: false,
16
- ignore_query: false }.merge(options)
14
+ ignore_query: false
15
+ }.merge(options)
17
16
  assert_valid_keys
18
17
  end
19
18
 
20
19
  def resolves_for?(session)
21
20
  uri = ::Addressable::URI.parse(session.current_url)
22
21
  uri.query = nil if uri && options[:ignore_query]
23
- @actual_path = if options[:url]
24
- uri.to_s
25
- else
26
- if options[:only_path]
27
- uri && uri.path
28
- else
29
- uri && uri.request_uri
30
- end
31
- end
22
+ @actual_path = options[:url] ? uri.to_s : uri && uri.request_uri
32
23
 
33
24
  if @expected_path.is_a? Regexp
34
25
  @actual_path.to_s.match(@expected_path)
@@ -45,22 +36,15 @@ module Capybara
45
36
  failure_message_helper(' not')
46
37
  end
47
38
 
48
- private
39
+ private
49
40
 
50
41
  def failure_message_helper(negated = '')
51
- verb = (@expected_path.is_a?(Regexp))? 'match' : 'equal'
42
+ verb = @expected_path.is_a?(Regexp) ? 'match' : 'equal'
52
43
  "expected #{@actual_path.inspect}#{negated} to #{verb} #{@expected_path.inspect}"
53
44
  end
54
45
 
55
46
  def valid_keys
56
- [:wait, :url, :only_path, :ignore_query]
57
- end
58
-
59
- def assert_valid_keys
60
- super
61
- if options[:url] && options[:only_path]
62
- raise ArgumentError, "the :url and :only_path options cannot both be true"
63
- end
47
+ %i[wait url ignore_query]
64
48
  end
65
49
  end
66
50
  end
@@ -2,18 +2,14 @@ module Capybara
2
2
  module Queries
3
3
  class MatchQuery < Capybara::Queries::SelectorQuery
4
4
  def visible
5
- if options.has_key?(:visible)
6
- super
7
- else
8
- :all
9
- end
5
+ options.key?(:visible) ? super : :all
10
6
  end
11
7
 
12
- private
8
+ private
13
9
 
14
10
  def valid_keys
15
11
  super - COUNT_KEYS
16
12
  end
17
13
  end
18
14
  end
19
- end
15
+ end