capybara 3.33.0 → 3.35.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +83 -15
  3. data/README.md +0 -2
  4. data/lib/capybara.rb +1 -1
  5. data/lib/capybara/config.rb +4 -6
  6. data/lib/capybara/driver/base.rb +4 -0
  7. data/lib/capybara/helpers.rb +25 -1
  8. data/lib/capybara/minitest.rb +2 -2
  9. data/lib/capybara/minitest/spec.rb +14 -11
  10. data/lib/capybara/node/actions.rb +1 -2
  11. data/lib/capybara/node/base.rb +6 -6
  12. data/lib/capybara/node/element.rb +1 -5
  13. data/lib/capybara/node/finders.rb +7 -6
  14. data/lib/capybara/node/matchers.rb +8 -6
  15. data/lib/capybara/node/simple.rb +5 -1
  16. data/lib/capybara/queries/ancestor_query.rb +1 -1
  17. data/lib/capybara/queries/current_path_query.rb +14 -4
  18. data/lib/capybara/queries/selector_query.rb +32 -17
  19. data/lib/capybara/queries/sibling_query.rb +1 -1
  20. data/lib/capybara/queries/text_query.rb +2 -2
  21. data/lib/capybara/rack_test/browser.rb +7 -3
  22. data/lib/capybara/rack_test/driver.rb +1 -0
  23. data/lib/capybara/rack_test/form.rb +1 -1
  24. data/lib/capybara/rack_test/node.rb +1 -1
  25. data/lib/capybara/registration_container.rb +3 -3
  26. data/lib/capybara/registrations/drivers.rb +18 -12
  27. data/lib/capybara/registrations/patches/puma_ssl.rb +3 -1
  28. data/lib/capybara/registrations/servers.rb +2 -1
  29. data/lib/capybara/result.rb +6 -10
  30. data/lib/capybara/rspec.rb +2 -0
  31. data/lib/capybara/rspec/matcher_proxies.rb +1 -1
  32. data/lib/capybara/rspec/matchers.rb +7 -6
  33. data/lib/capybara/rspec/matchers/have_current_path.rb +2 -2
  34. data/lib/capybara/rspec/matchers/match_style.rb +5 -0
  35. data/lib/capybara/selector.rb +2 -2
  36. data/lib/capybara/selector/builders/css_builder.rb +1 -1
  37. data/lib/capybara/selector/builders/xpath_builder.rb +3 -1
  38. data/lib/capybara/selector/definition.rb +6 -5
  39. data/lib/capybara/selector/definition/button.rb +26 -15
  40. data/lib/capybara/selector/definition/css.rb +1 -1
  41. data/lib/capybara/selector/definition/datalist_input.rb +1 -1
  42. data/lib/capybara/selector/definition/element.rb +2 -1
  43. data/lib/capybara/selector/definition/label.rb +1 -1
  44. data/lib/capybara/selector/definition/select.rb +1 -1
  45. data/lib/capybara/selector/definition/table_row.rb +2 -2
  46. data/lib/capybara/selector/filter_set.rb +2 -2
  47. data/lib/capybara/selector/selector.rb +5 -1
  48. data/lib/capybara/selenium/atoms/src/isDisplayed.js +1 -1
  49. data/lib/capybara/selenium/driver.rb +47 -5
  50. data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +3 -3
  51. data/lib/capybara/selenium/driver_specializations/edge_driver.rb +3 -3
  52. data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +1 -1
  53. data/lib/capybara/selenium/extensions/find.rb +4 -4
  54. data/lib/capybara/selenium/extensions/scroll.rb +8 -10
  55. data/lib/capybara/selenium/logger_suppressor.rb +8 -2
  56. data/lib/capybara/selenium/node.rb +6 -3
  57. data/lib/capybara/selenium/nodes/chrome_node.rb +23 -5
  58. data/lib/capybara/selenium/nodes/firefox_node.rb +6 -1
  59. data/lib/capybara/selenium/nodes/safari_node.rb +1 -1
  60. data/lib/capybara/selenium/patches/atoms.rb +4 -4
  61. data/lib/capybara/selenium/patches/logs.rb +4 -4
  62. data/lib/capybara/server/animation_disabler.rb +8 -3
  63. data/lib/capybara/server/middleware.rb +4 -2
  64. data/lib/capybara/session.rb +20 -11
  65. data/lib/capybara/session/matchers.rb +11 -11
  66. data/lib/capybara/spec/public/test.js +6 -1
  67. data/lib/capybara/spec/session/accept_alert_spec.rb +1 -1
  68. data/lib/capybara/spec/session/check_spec.rb +6 -0
  69. data/lib/capybara/spec/session/click_link_or_button_spec.rb +9 -0
  70. data/lib/capybara/spec/session/current_url_spec.rb +11 -1
  71. data/lib/capybara/spec/session/has_button_spec.rb +35 -0
  72. data/lib/capybara/spec/session/has_css_spec.rb +2 -1
  73. data/lib/capybara/spec/session/has_current_path_spec.rb +13 -0
  74. data/lib/capybara/spec/session/has_text_spec.rb +0 -11
  75. data/lib/capybara/spec/session/html_spec.rb +1 -1
  76. data/lib/capybara/spec/session/matches_style_spec.rb +2 -2
  77. data/lib/capybara/spec/session/node_spec.rb +23 -3
  78. data/lib/capybara/spec/session/refresh_spec.rb +2 -1
  79. data/lib/capybara/spec/session/save_page_spec.rb +4 -4
  80. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +1 -1
  81. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +1 -1
  82. data/lib/capybara/spec/session/window/window_spec.rb +1 -1
  83. data/lib/capybara/spec/session/window/windows_spec.rb +1 -1
  84. data/lib/capybara/spec/spec_helper.rb +11 -12
  85. data/lib/capybara/spec/test_app.rb +9 -3
  86. data/lib/capybara/spec/views/form.erb +23 -1
  87. data/lib/capybara/spec/views/with_animation.erb +8 -0
  88. data/lib/capybara/spec/views/with_jquery_animation.erb +24 -0
  89. data/lib/capybara/spec/views/with_js.erb +2 -0
  90. data/lib/capybara/spec/views/with_sortable_js.erb +1 -1
  91. data/lib/capybara/version.rb +1 -1
  92. data/lib/capybara/window.rb +3 -7
  93. data/spec/basic_node_spec.rb +9 -8
  94. data/spec/dsl_spec.rb +1 -1
  95. data/spec/fixtures/selenium_driver_rspec_success.rb +1 -1
  96. data/spec/minitest_spec.rb +2 -1
  97. data/spec/rack_test_spec.rb +15 -5
  98. data/spec/rspec/features_spec.rb +3 -1
  99. data/spec/rspec/scenarios_spec.rb +4 -0
  100. data/spec/rspec/shared_spec_matchers.rb +2 -2
  101. data/spec/rspec_spec.rb +4 -0
  102. data/spec/selector_spec.rb +16 -1
  103. data/spec/selenium_spec_chrome.rb +39 -18
  104. data/spec/selenium_spec_chrome_remote.rb +5 -1
  105. data/spec/selenium_spec_firefox.rb +15 -13
  106. data/spec/server_spec.rb +19 -0
  107. data/spec/shared_selenium_session.rb +74 -1
  108. metadata +47 -13
  109. data/lib/capybara/spec/session/source_spec.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab64d9d47c6374c4f203945be70b868fb9e4c48d3fdca087ba4e66498e40b91c
4
- data.tar.gz: 451c97390c148b5b0fad1b06107a4f0de87f17f7b8cef7156fb76ad2ee503f76
3
+ metadata.gz: 516861530f59d3d9713daba7379838146575b920f787ac2c3f5c4bbffc6bf44d
4
+ data.tar.gz: 85b3fb81bf05e43122c2eef320a7a2dbd500033723ebbc04ebc414b0a42d0881
5
5
  SHA512:
6
- metadata.gz: b0ca3fd8a4535e1df696ddc7f547e066b873d3f4be2b54655fdbb0b6588c5086a87b93500e241e0da031b586c0b6a30cdd8522f209309cf6729c683226bfcf7f
7
- data.tar.gz: d295dcd733856816a1c89810f4d54304a52c251d585afcc62b986a66d63e080e03ddc81bdc46cf51a044e29d2849ccce9bb3cb307a0757746e662394f648a717
6
+ metadata.gz: 7f745dac92b73afa56f43a2a509052c7fc5d1efa458863b0b3f05507c664847d6f67720a2c2a680e21126888e63a6eaf6a0e9be7d1a4df9d6aaa9ec61d832e29
7
+ data.tar.gz: 53532156dd31631879a0a8fda93126f259a5cd856a6cec82e6283f9f96e1cc2d98b788e4414ffee5756024d14819450d358529aa90d4c948618e82b878342ebd
data/History.md CHANGED
@@ -1,3 +1,70 @@
1
+ # Version 3.35.3
2
+ Release date: 2021-01-29
3
+
4
+ ### Fixed
5
+ * Just a release to have the correct dates in the History.md in released gem
6
+
7
+ # Version 3.35.2
8
+ Release date: 2021-01-29
9
+
10
+ ### Fixed
11
+
12
+ * Selenium deprecation suppressor with Selenium 3.x
13
+
14
+ # Version 3.35.1
15
+ Release date: 2021-01-26
16
+
17
+ ### Fixed
18
+
19
+ * Default chrome driver registrations use chrome - Issue #2442 [Yuriy Alekseyev]
20
+ * 'Capybara.test_id' usage with the :button selector - Issue #2443
21
+
22
+ # Version 3.35.0
23
+ Release date: 2021-01-25
24
+
25
+ ### Added
26
+
27
+ * Support Regexp matching for individual class names in :class filter passed an Array
28
+ * Animation disabler now supports JQuery animation disabling when JQuery loaded from body [Chien-Wei Huang]
29
+
30
+ ### Fixed
31
+
32
+ * :button selector type use with `enable_aria_role` [Sean Doyle]
33
+ * <label> elements don't associate with aria-role buttons
34
+ * Ignore Selenium::WebDriver::Error::InvalidSessionIdError when quitting driver [Robin Daugherty]
35
+ * Firefox: Don't click input when sending keys if already focused
36
+ * Miscellaneous issues with selenium-webdriver 4.0.0.alphas
37
+ * Nil return error in node details optimizations
38
+ * Animation disabler now inserts XHTML compliant content [Dale Morgan]
39
+
40
+ # Version 3.34.0
41
+ Release date: 2020-11-26
42
+
43
+ ### Added
44
+
45
+ * Ability to fill in with emoji when using Chrome with selenium driver (Firefox already worked)
46
+ * Current path assertions/expectations accept optional filter block
47
+ * Animation disabler now specifies `scroll-behavior: auto;` [Nathan Broadbent]
48
+ * :button selector can now find elements by label text [Sean Doyle]
49
+ * `Session#send_keys` to send keys to the current element with focus in drivers that support the
50
+ concept of a current element [Sean Doyle]
51
+
52
+ ### Changed
53
+
54
+ * Text query validates the type parameter to prevent undefined behavior
55
+
56
+ ### Fixed
57
+
58
+ * racktest driver better handles fragments and redirection to urls that include fragments
59
+ * Don't error when attempting to get XPath location of a shadow element
60
+ * Missing `readonly?` added to Node::Simple
61
+ * Selenium version detection when loaded via alternate method [Joel Hawksley]
62
+ * Connection count issue if REQUEST_URI value changed by app [Blake Williams]
63
+ * Maintain URI fragment when redirecting in rack-test driver
64
+ * Text query error message [Wojciech Wnętrzak]
65
+ * Checking a checkbox/radio button with `allow_label_click` now works if there are multiple labels (Issue #2421)
66
+ * `drop` with `Pathname` (Issue #2424)[Máximo Mussini]
67
+
1
68
  # Version 3.33.0
2
69
  Release date: 2020-06-21
3
70
 
@@ -7,11 +74,12 @@ Release date: 2020-06-21
7
74
  * Support for aria-role button when enabled [Seiei Miyagi]
8
75
  * Support for aria-role link when enabled
9
76
  * Support for `validation_message` filter with :field and :fillable_field selectors
77
+ * Deprecation warnings show source location [Koichi ITO]
10
78
 
11
79
  ### Changed
12
80
 
13
81
  * Ruby 2.5.0+ is now required
14
- * Deprecated direct manupulation of the driver and server registries
82
+ * Deprecated direct manipulation of the driver and server registries
15
83
 
16
84
  ### Fixed
17
85
 
@@ -41,7 +109,7 @@ Release date: 2020-03-29
41
109
  ### Added
42
110
 
43
111
  * Support `delay` setting on click with Selenium
44
- * Implement rapid set for values longer thn 30 characters in text fields with Selenium
112
+ * Implement rapid set for values longer than 30 characters in text fields with Selenium
45
113
 
46
114
  ### Fixed
47
115
 
@@ -162,8 +230,8 @@ Release date: 2019-06-27
162
230
 
163
231
  ### Fixed
164
232
 
165
- * Woraround issue with chromedriver 76/77 in W3C mode losing mouse state during legacy drag. Only fixed if
166
- both source and target are simultaenously inside the viewport - Issue #2223
233
+ * Work around issue with chromedriver 76/77 in W3C mode losing mouse state during legacy drag. Only fixed if
234
+ both source and target are simultaneously inside the viewport - Issue #2223
167
235
  * Negative ancestor expectations/predicates were incorrectly checking siblings rather than ancestors
168
236
 
169
237
  # Version 3.24.0
@@ -442,7 +510,7 @@ Release date: 2018-10-23
442
510
 
443
511
  ### Fixed
444
512
 
445
- * Selector `css` expression definiton declared filters now work again
513
+ * Selector `css` expression definition declared filters now work again
446
514
  * Cleaned up warnings [Yuji Yaginuma]
447
515
  * Workaround installation of rspec matcher proxies under jruby by reverting to the old solution not using prepend, so jruby bugs are not hit - Issue #2115
448
516
 
@@ -559,7 +627,7 @@ Release date: 2018-07-19
559
627
 
560
628
  ### Fixed
561
629
 
562
- * Make selenium driver :backspace clear stategy work even if caret location is in middle of field content [Champier Cyril]
630
+ * Make selenium driver :backspace clear strategy work even if caret location is in middle of field content [Champier Cyril]
563
631
  * Selenium issue with fieldset nested in disabled fieldset not being considered disabled
564
632
  * `Session#evaluate_script` and `Element#evaluate_script` now strip leading/trailing whitespace from scripts [Ian Lesperance]
565
633
 
@@ -658,7 +726,7 @@ Release date: 2018-04-13
658
726
  ### Fixes
659
727
 
660
728
  * Fix expression filter descriptions in some selector failure messages
661
- * Fix compounding of negated matechers - Issue #2010
729
+ * Fix compounding of negated matchers - Issue #2010
662
730
 
663
731
  # Version 3.0.1
664
732
  Release date: 2018-04-06
@@ -932,7 +1000,7 @@ Release date: 2016-12-05
932
1000
  * Options for clearing session/local storage on reset added to the Selenium driver
933
1001
  * Window size changes wait for the size to stabilize
934
1002
  * Defined return value for most actions
935
- * Ignore specific error when qutting selenium driver instance - Issue #1773 [Dylan Reichstadt, Thomas Walpole]
1003
+ * Ignore specific error when quitting selenium driver instance - Issue #1773 [Dylan Reichstadt, Thomas Walpole]
936
1004
  * Warn on selenium unknown errors rather than raising when quitting driver [Adam Pohorecki, Thomas Walpole]
937
1005
  * Capybara::Result#each now returns an `Enumerator` when called without a block - Issue #1777 [Thomas Walpole]
938
1006
 
@@ -994,7 +1062,7 @@ Release date: 2016-09-19
994
1062
 
995
1063
  ### Fixed
996
1064
 
997
- * Issue with rack-test driver and obselete mime-types when using `#attach_file` - Issue #1756 [Thomas Walpole]
1065
+ * Issue with rack-test driver and obsolete mime-types when using `#attach_file` - Issue #1756 [Thomas Walpole]
998
1066
 
999
1067
  ### Added
1000
1068
 
@@ -1061,7 +1129,7 @@ Release date: 2016-04-07
1061
1129
 
1062
1130
  ### Added
1063
1131
 
1064
- * Capybara now waits for requests to Capybaras server to complete while restting the session [John Hawthorn, Thomas Walpole]
1132
+ * Capybara now waits for requests to Capybaras server to complete while resetting the session [John Hawthorn, Thomas Walpole]
1065
1133
  * Capybara.reuse_server option to allow disabling of sharing server instance between sessions [Thomas Walpole]
1066
1134
  * :multiple filter added to relevant selectors [Thomas Walpole]
1067
1135
  * Provided server registrations for :webrick and :puma. Capybara.server = :puma for testing with Rails 5 [Thomas Walpole]
@@ -1075,7 +1143,7 @@ Release date: 2016-04-07
1075
1143
 
1076
1144
  # Version 2.6.2
1077
1145
 
1078
- Relase date: 2016-01-27
1146
+ Release date: 2016-01-27
1079
1147
 
1080
1148
  ### Fixed
1081
1149
 
@@ -1621,8 +1689,8 @@ Release date: 2011-06-14
1621
1689
  * Rack::Test driver honours maxlength on input fields [Guilherme Carvalho]
1622
1690
  * Rack::Test now works as expected with domains and subdomains [Jonas Nicklas]
1623
1691
  * Session is reset more thoroughly between tests. [Jonas Nicklas]
1624
- * Raise error when uploading non-existant file [Jonas Nicklas]
1625
- * Rack reponse body should respond to #each [Piotr Sarnacki]
1692
+ * Raise error when uploading non-existent file [Jonas Nicklas]
1693
+ * Rack response body should respond to #each [Piotr Sarnacki]
1626
1694
  * Deprecation warnings with selenium webdriver 0.2.0 [Aaron Gibraltar]
1627
1695
  * Selenium Chrome no longer YELLS tagname [Carl Jackson & David W. Frank]
1628
1696
  * Capybara no longer strips encoding before sending to Rack [Jonas Nicklas]
@@ -1764,7 +1832,7 @@ Release date: 2010-05-12
1764
1832
 
1765
1833
  Release date: 2010-04-09
1766
1834
 
1767
- This is a drop in compatible maintainance release. It's mostly
1835
+ This is a drop in compatible maintenance release. It's mostly
1768
1836
  important for driver authors.
1769
1837
 
1770
1838
  ### Added
@@ -1783,7 +1851,7 @@ important for driver authors.
1783
1851
 
1784
1852
  Release date: 2010-03-22
1785
1853
 
1786
- This is a maintainance release with minor bug fixes, should be
1854
+ This is a maintenance release with minor bug fixes, should be
1787
1855
  drop in compatible.
1788
1856
 
1789
1857
  ### Added
data/README.md CHANGED
@@ -7,8 +7,6 @@
7
7
  [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jnicklas/capybara?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
8
8
  [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=capybara&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=capybara&package-manager=bundler&version-scheme=semver)
9
9
 
10
- **Note** You are viewing the README for the 3.33.x release of Capybara.
11
-
12
10
  Capybara helps you test web applications by simulating how a real user would
13
11
  interact with your app. It is agnostic about the driver running your tests and
14
12
  comes with Rack::Test and Selenium support built in. WebKit is supported
@@ -484,7 +484,7 @@ module Capybara
484
484
  require 'capybara/rack_test/node'
485
485
  require 'capybara/rack_test/form'
486
486
  require 'capybara/rack_test/browser'
487
- require 'capybara/rack_test/css_handlers.rb'
487
+ require 'capybara/rack_test/css_handlers'
488
488
 
489
489
  require 'capybara/selenium/node'
490
490
  require 'capybara/selenium/driver'
@@ -9,11 +9,9 @@ module Capybara
9
9
 
10
10
  OPTIONS = %i[app reuse_server threadsafe server default_driver javascript_driver allow_gumbo].freeze
11
11
 
12
- attr_accessor :app
13
- attr_reader :reuse_server, :threadsafe
14
- attr_reader :session_options
12
+ attr_accessor :app, :allow_gumbo
13
+ attr_reader :reuse_server, :threadsafe, :session_options
15
14
  attr_writer :default_driver, :javascript_driver
16
- attr_accessor :allow_gumbo
17
15
 
18
16
  SessionConfig::OPTIONS.each do |method|
19
17
  def_delegators :session_options, method, "#{method}="
@@ -83,10 +81,10 @@ module Capybara
83
81
  @javascript_driver || :selenium
84
82
  end
85
83
 
86
- def deprecate(method, alternate_method, once = false)
84
+ def deprecate(method, alternate_method, once: false)
87
85
  @deprecation_notified ||= {}
88
86
  unless once && @deprecation_notified[method]
89
- warn "DEPRECATED: ##{method} is deprecated, please use ##{alternate_method} instead"
87
+ Capybara::Helpers.warn "DEPRECATED: ##{method} is deprecated, please use ##{alternate_method} instead: #{Capybara::Helpers.filter_backtrace(caller)}"
90
88
  end
91
89
  @deprecation_notified[method] = true
92
90
  end
@@ -59,6 +59,10 @@ class Capybara::Driver::Base
59
59
  raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#status_code'
60
60
  end
61
61
 
62
+ def send_keys(*)
63
+ raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#send_keys'
64
+ end
65
+
62
66
  ##
63
67
  #
64
68
  # @param frame [Capybara::Node::Element, :parent, :top] The iframe element to switch to
@@ -15,7 +15,7 @@ module Capybara
15
15
  # @return [String] Normalized text
16
16
  #
17
17
  def normalize_whitespace(text)
18
- warn 'DEPRECATED: Capybara::Helpers::normalize_whitespace is deprecated, please update your driver'
18
+ Capybara::Helpers.warn 'DEPRECATED: Capybara::Helpers::normalize_whitespace is deprecated, please update your driver'
19
19
  text.to_s.gsub(/[[:space:]]+/, ' ').strip
20
20
  end
21
21
 
@@ -70,6 +70,30 @@ module Capybara
70
70
  count == 1 ? singular : plural
71
71
  end
72
72
 
73
+ def filter_backtrace(trace)
74
+ return 'No backtrace' unless trace
75
+
76
+ filter = %r{lib/capybara/|lib/rspec/|lib/minitest/}
77
+ new_trace = trace.take_while { |line| line !~ filter }
78
+ new_trace = trace.reject { |line| line =~ filter } if new_trace.empty?
79
+ new_trace = trace.dup if new_trace.empty?
80
+
81
+ new_trace.first.split(/:in /, 2).first
82
+ end
83
+
84
+ def warn(message, uplevel: 1)
85
+ return Kernel.warn(message, uplevel: uplevel) if RUBY_VERSION >= '2.6'
86
+
87
+ # TODO: Remove when we drop support for Ruby 2.5
88
+ # Workaround for emulating `warn '...', uplevel: n` in Ruby 2.5 or lower.
89
+ if (match = /^(?<file>.+?):(?<line>\d+)(?::in `.*')?/.match(caller[uplevel]))
90
+ location = [match[:file], match[:line]].join(':')
91
+ Kernel.warn "#{location}: #{message}"
92
+ else
93
+ Kernel.warn message
94
+ end
95
+ end
96
+
73
97
  if defined?(Process::CLOCK_MONOTONIC)
74
98
  def monotonic_time; Process.clock_gettime Process::CLOCK_MONOTONIC; end
75
99
  else
@@ -50,10 +50,10 @@ module Capybara
50
50
 
51
51
  %w[text no_text title no_title current_path no_current_path].each do |assertion_name|
52
52
  class_eval <<-ASSERTION, __FILE__, __LINE__ + 1
53
- def assert_#{assertion_name}(*args, **kwargs)
53
+ def assert_#{assertion_name}(*args, **kwargs, &optional_filter_block)
54
54
  self.assertions +=1
55
55
  subject, args = determine_subject(args)
56
- subject.assert_#{assertion_name}(*args, **kwargs)
56
+ subject.assert_#{assertion_name}(*args, **kwargs, &optional_filter_block)
57
57
  rescue Capybara::ExpectationNotMet => e
58
58
  raise ::Minitest::Assertion, e.message
59
59
  end
@@ -209,13 +209,15 @@ module Capybara
209
209
  # @!method wont_have_xpath
210
210
  # See {Capybara::Node::Matchers#has_no_xpath?}
211
211
 
212
- %w[text content title current_path].each do |assertion|
213
- infect_an_assertion "assert_#{assertion}", "must_have_#{assertion}", :reverse
214
- infect_an_assertion "refute_#{assertion}", "wont_have_#{assertion}", :reverse
215
- end
212
+ # This currently doesn't work for Ruby 2.8 due to Minitest not forwarding keyword args separately
213
+ # %w[text content title current_path].each do |assertion|
214
+ # infect_an_assertion "assert_#{assertion}", "must_have_#{assertion}", :reverse
215
+ # infect_an_assertion "refute_#{assertion}", "wont_have_#{assertion}", :reverse
216
+ # end
216
217
 
217
218
  # rubocop:disable Style/MultilineBlockChain
218
- (%w[selector xpath css link button field select table checked_field unchecked_field
219
+ (%w[text content title current_path
220
+ selector xpath css link button field select table checked_field unchecked_field
219
221
  ancestor sibling].flat_map do |assertion|
220
222
  [%W[assert_#{assertion} must_have_#{assertion}],
221
223
  %W[refute_#{assertion} wont_have_#{assertion}]]
@@ -228,14 +230,15 @@ module Capybara
228
230
  %W[refute_matches_#{assertion} wont_match_#{assertion}]]
229
231
  end).each do |(meth, new_name)|
230
232
  class_eval <<-ASSERTION, __FILE__, __LINE__ + 1
231
- def #{new_name} *args, &block
232
- ::Minitest::Expectation.new(self, ::Minitest::Spec.current).#{new_name}(*args, &block)
233
+ def #{new_name} *args, **kw_args, &block
234
+ ::Minitest::Expectation.new(self, ::Minitest::Spec.current).#{new_name}(*args, **kw_args, &block)
233
235
  end
234
236
  ASSERTION
235
237
 
236
238
  ::Minitest::Expectation.class_eval <<-ASSERTION, __FILE__, __LINE__ + 1
237
- def #{new_name} *args, &block
238
- ctx.#{meth}(target, *args, &block)
239
+ def #{new_name} *args, **kw_args, &block
240
+ raise "Calling ##{new_name} outside of test." unless ctx
241
+ ctx.#{meth}(target, *args, **kw_args, &block)
239
242
  end
240
243
  ASSERTION
241
244
  end
@@ -243,9 +246,9 @@ module Capybara
243
246
 
244
247
  ##
245
248
  # @deprecated
246
- def must_have_style(*args, &block)
249
+ def must_have_style(*args, **kw_args, &block)
247
250
  warn 'must_have_style is deprecated, please use must_match_style'
248
- must_match_style(*args, &block)
251
+ must_match_style(*args, **kw_args, &block)
249
252
  end
250
253
  end
251
254
  end
@@ -363,7 +363,6 @@ module Capybara
363
363
  def _check_with_label(selector, checked, locator,
364
364
  allow_label_click: session_options.automatic_label_click, **options)
365
365
  options[:allow_self] = true if locator.nil?
366
-
367
366
  synchronize(Capybara::Queries::BaseQuery.wait(options, session_options.default_max_wait_time)) do
368
367
  el = find(selector, locator, **options)
369
368
  el.set(checked)
@@ -372,7 +371,7 @@ module Capybara
372
371
 
373
372
  begin
374
373
  el ||= find(selector, locator, **options.merge(visible: :all))
375
- el.session.find(:label, for: el, visible: true).click unless el.checked? == checked
374
+ el.session.find(:label, for: el, visible: true, match: :first).click unless el.checked? == checked
376
375
  rescue StandardError # swallow extra errors - raise original
377
376
  raise e
378
377
  end
@@ -103,19 +103,19 @@ module Capybara
103
103
 
104
104
  # @api private
105
105
  def find_css(css, **options)
106
- if base.method(:find_css).arity != 1
107
- base.find_css(css, **options)
108
- else
106
+ if base.method(:find_css).arity == 1
109
107
  base.find_css(css)
108
+ else
109
+ base.find_css(css, **options)
110
110
  end
111
111
  end
112
112
 
113
113
  # @api private
114
114
  def find_xpath(xpath, **options)
115
- if base.method(:find_xpath).arity != 1
116
- base.find_xpath(xpath, **options)
117
- else
115
+ if base.method(:find_xpath).arity == 1
118
116
  base.find_xpath(xpath)
117
+ else
118
+ base.find_xpath(xpath, **options)
119
119
  end
120
120
  end
121
121
 
@@ -435,11 +435,7 @@ module Capybara
435
435
  #
436
436
  # @return [Capybara::Node::Element] The element
437
437
  def drop(*args)
438
- options = args.map do |arg|
439
- return arg.to_path if arg.respond_to?(:to_path)
440
-
441
- arg
442
- end
438
+ options = args.map { |arg| arg.respond_to?(:to_path) ? arg.to_path : arg }
443
439
  synchronize { base.drop(*options) }
444
440
  self
445
441
  end
@@ -24,12 +24,13 @@ module Capybara
24
24
  # @option options [Boolean] normalize_ws
25
25
  # Whether the `text`/`exact_text` options are compared against elment text with whitespace normalized or as returned by the driver.
26
26
  # Defaults to {Capybara.configure default_normalize_ws}.
27
- # @option options [Boolean, Symbol] visible Only find elements with the specified visibility:
28
- # * true - only finds visible elements.
29
- # * false - finds invisible _and_ visible elements.
30
- # * :all - same as false; finds visible and invisible elements.
31
- # * :hidden - only finds invisible elements.
32
- # * :visible - same as true; only finds visible elements.
27
+ # @option options [Boolean, Symbol] visible
28
+ # Only find elements with the specified visibility. Defaults to behavior indicated by {Capybara.configure ignore_hidden_elements}.
29
+ # * true - only finds visible elements.
30
+ # * false - finds invisible _and_ visible elements.
31
+ # * :all - same as false; finds visible and invisible elements.
32
+ # * :hidden - only finds invisible elements.
33
+ # * :visible - same as true; only finds visible elements.
33
34
  # @option options [Boolean] obscured Only find elements with the specified obscured state:
34
35
  # * true - only find elements whose centerpoint is not in the viewport or is obscured by another non-descendant element.
35
36
  # * false - only find elements whose centerpoint is in the viewport and is not obscured by other non-descendant elements.
@@ -60,15 +60,16 @@ module Capybara
60
60
  # @param styles [Hash]
61
61
  # @return [Boolean] If the styles match
62
62
  #
63
- def matches_style?(styles, **options)
63
+ def matches_style?(styles = nil, **options)
64
+ styles, options = options, {} if styles.nil?
64
65
  make_predicate(options) { assert_matches_style(styles, **options) }
65
66
  end
66
67
 
67
68
  ##
68
69
  # @deprecated Use {#matches_style?} instead.
69
70
  #
70
- def has_style?(styles, **options)
71
- warn 'DEPRECATED: has_style? is deprecated, please use matches_style?'
71
+ def has_style?(styles = nil, **options)
72
+ Capybara::Helpers.warn "DEPRECATED: has_style? is deprecated, please use matches_style? : #{Capybara::Helpers.filter_backtrace(caller)}"
72
73
  matches_style?(styles, **options)
73
74
  end
74
75
 
@@ -122,7 +123,8 @@ module Capybara
122
123
  # @param styles [Hash]
123
124
  # @raise [Capybara::ExpectationNotMet] If the element doesn't have the specified styles
124
125
  #
125
- def assert_matches_style(styles, **options)
126
+ def assert_matches_style(styles = nil, **options)
127
+ styles, options = options, {} if styles.nil?
126
128
  query_args, query_opts = _set_query_session_options(styles, options)
127
129
  query = Capybara::Queries::StyleQuery.new(*query_args, **query_opts)
128
130
  synchronize(query.wait) do
@@ -134,7 +136,7 @@ module Capybara
134
136
  ##
135
137
  # @deprecated Use {#assert_matches_style} instead.
136
138
  #
137
- def assert_style(styles, **options)
139
+ def assert_style(styles = nil, **options)
138
140
  warn 'assert_style is deprecated, please use assert_matches_style instead'
139
141
  assert_matches_style(styles, **options)
140
142
  end
@@ -384,7 +386,7 @@ module Capybara
384
386
  #
385
387
  # page.has_field?('Email', type: 'email')
386
388
  #
387
- # Note: 'textarea' and 'select' are valid type values, matching the associated tag names.
389
+ # NOTE: 'textarea' and 'select' are valid type values, matching the associated tag names.
388
390
  #
389
391
  # @param [String] locator The label, name or id of a field to check for
390
392
  # @option options [String, Regexp] :with The text content of the field or a Regexp to match