capybara 2.18.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb46b7bc5ae7408ca3870b781d015a84bd84abd0a9c7e3ea2bcdf3d8fff85ce8
4
- data.tar.gz: 1865dc1efa384c3792161a134bc536c56dca3aa0670ca298ad9f3aa12b49830d
3
+ metadata.gz: 8389b150e2b44270ed1d94b8f6e0f48af613f1a2f28b8ad772e35cb7db635ad7
4
+ data.tar.gz: bace2657813bc0681e4586ba2c96a66e824e12651f0e839a8649ed491f0eafa1
5
5
  SHA512:
6
- metadata.gz: 9bc2cb739af408323d977b7ca829aa0862ef68ab7d1778c5ae67fb127a47a09258c1f5b53f9d7955bcfcd2892c869a136d7a5346b9115a9e55713ea47c95ebb3
7
- data.tar.gz: e8d234ded45305e026b615c60e4eb8597e31fd67b7daefff51d13ab3d79868745e21668a6b45452366ac5a552b38e8c01dc669e73dbe45a9b38ecf8363b54e83
6
+ metadata.gz: 5ffed0a0be90e5d8bf022b48d261aa160646562095114ca383a446431ab57403d67a6ccf252129a477484a6ea1bdc1edfefa6930571961e6307b5ce180c6aa30
7
+ data.tar.gz: e5956efba3a7e4a6833a9b63e61c6f136a3210eb77ac44d8b1603b81b6e5bea7bde1ea3fd4c76b8eda6a10f61c1e0e805aef7f8aa4bcf801061c46a7fded1c02
data/History.md CHANGED
@@ -1,4 +1,56 @@
1
- #Version 2.18.0
1
+ # Version 3.0.0
2
+ Release date: 2018-04-05
3
+
4
+ ### Changed
5
+
6
+ * Selenium driver only closes extra windows for browsers where that is known to work (Firefox, Chrome)
7
+ * "threadsafe" mode is no longer considered beta
8
+
9
+ ### Fixes
10
+
11
+ * Multiple file attach_file with Firefox
12
+ * Use Puma::Server directly rather than Rack::Handler::Puma so signal handlers don't prevent test quitting
13
+
14
+ # Version 3.0.0.rc2
15
+ Release date: 2018-03-23
16
+
17
+ ### Changed
18
+
19
+ * Drivers are now expected to return visible text more in line with the WebDriver spec for visible text
20
+ * Drivers are expected to close extra windows when resetting the session
21
+ * Selenium driver supports Date/Time when filling in date/time/datetime-local inputs
22
+ * `current_url` returns the url for the top level browsing context
23
+ * `title` returns the title for the top level browsing context
24
+
25
+ ### Added
26
+
27
+ * `Driver#frame_url` returns the url for the current frame
28
+ * `Driver#frame_title` returns the title for the current frame
29
+
30
+ # Version 3.0.0.rc1
31
+ Release date: 2018-03-02
32
+
33
+ ### Added
34
+ * Support for libraries wrapping Capybara elements and providing a `#to_capybara_node` method
35
+
36
+ ### Changed
37
+
38
+ * `first` now raises ElementNotFound, by default, instead of returning nil when no matches are found - Issue #1507
39
+ * 'all' now waits for at least one matching element by default. Pass `wait: false` if you want the previous
40
+ behavior where an empty result would be returned immediately if no matching elements exist yet.
41
+ * ArgumentError raised if extra parameters passed to selector queries
42
+
43
+ ### Removed
44
+
45
+ * Ruby < 2.2.2 support
46
+ * `Capybara.exact_options` no longer exists. Just use `exact: true` on relevant actions/finders if necessary.
47
+ * All previously deprecated methods removed
48
+ * RSpec 2.x support
49
+ * selenium-webdriver 2.x support
50
+ * Nokogiri < 1.8 support
51
+ * `field_labeled` alias for `find_field`
52
+
53
+ # Version 2.18.0
2
54
  Release date: 2018-02-12
3
55
 
4
56
  ### Fixed
@@ -10,6 +62,7 @@ Release date: 2018-02-12
10
62
 
11
63
  * Headless chrome modal JS injection that is no longer needed for Chrome 64+/chromedriver 2.35+
12
64
 
65
+
13
66
  # Version 2.17.0
14
67
  Release date: 2018-01-02
15
68
 
@@ -253,6 +306,7 @@ Release date: 2016-10-05
253
306
  Release date: 2016-09-29
254
307
 
255
308
  ### Fixed
309
+
256
310
  * :label built-in selector finds nested label/control by control id if the label has no 'for' attribute [Thomas Walpole]
257
311
  * Warning issued if an unknown selector type is specified [Thomas Walpole]
258
312
 
data/README.md CHANGED
@@ -1,10 +1,15 @@
1
1
  # Capybara
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/teamcapybara/capybara.svg)](https://travis-ci.org/teamcapybara/capybara)
4
+ [![Build Status](https://ci.appveyor.com/api/projects/status/github/teamcapybara/capybara?svg=true)](https://ci.appveyor.com/api/projects/github/teamcapybara/capybara)
4
5
  [![Dependency Status](https://gemnasium.com/teamcapybara/capybara.svg)](https://gemnasium.com/teamcapybara/capybara)
5
6
  [![Code Climate](https://codeclimate.com/github/teamcapybara/capybara.svg)](https://codeclimate.com/github/teamcapybara/capybara)
6
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)
7
8
 
9
+ **Note** You are viewing the README for the development version of Capybara. If you are using the current release version
10
+ you can find the README at https://github.com/teamcapybara/capybara/blob/3.0_stable/README.md
11
+
12
+
8
13
  Capybara helps you test web applications by simulating how a real user would
9
14
  interact with your app. It is agnostic about the driver running your tests and
10
15
  comes with Rack::Test and Selenium support built in. WebKit is supported
@@ -71,24 +76,19 @@ GitHub): http://groups.google.com/group/ruby-capybara
71
76
 
72
77
  ## <a name="setup"></a>Setup
73
78
 
74
- Capybara requires Ruby 1.9.3 or later. To install, add this line to your
79
+ Capybara requires Ruby 2.2.2 or later. To install, add this line to your
75
80
  `Gemfile` and run `bundle install`:
76
81
 
77
82
  ```ruby
78
83
  gem 'capybara'
79
84
  ```
80
85
 
81
- **Note:** If using Ruby < 2.0 you will also need to limit the version of rack to < 2.0
82
-
83
86
  If the application that you are testing is a Rails app, add this line to your test helper file:
84
87
 
85
88
  ```ruby
86
89
  require 'capybara/rails'
87
90
  ```
88
91
 
89
- **Note:** In Rails 4.0/4.1 the default test environment (`config/environments/test.rb`) is [not threadsafe](https://github.com/rails/rails/issues/15089).
90
- If you experience random errors about missing constants, add `config.allow_concurrency = false` to `config/environments/test.rb`.
91
-
92
92
  If the application that you are testing is a Rack app, but not Rails, set Capybara.app to your Rack app:
93
93
 
94
94
  ```ruby
@@ -140,26 +140,26 @@ There are also explicit tags for each registered driver set up for you (`@seleni
140
140
 
141
141
  ## <a name="using-capybara-with-rspec"></a>Using Capybara with RSpec
142
142
 
143
- Load RSpec 2+ support by adding the following line (typically to your
143
+ Load RSpec 3.x support by adding the following line (typically to your
144
144
  `spec_helper.rb` file):
145
145
 
146
146
  ```ruby
147
147
  require 'capybara/rspec'
148
148
  ```
149
149
 
150
- If you are using Rails, put your Capybara specs in `spec/features` (only works
150
+ If you are using Rails, put your Capybara specs in `spec/features` or `spec/system` (only works
151
151
  if [you have it configured in
152
152
  RSpec](https://www.relishapp.com/rspec/rspec-rails/docs/upgrade#file-type-inference-disabled))
153
153
  and if you have your Capybara specs in a different directory, then tag the
154
- example groups with `:type => :feature`.
154
+ example groups with `type: :feature` or `type: :system` depending on which type of test you're writing.
155
155
 
156
156
  If you are not using Rails, tag all the example groups in which you want to use
157
- Capybara with `:type => :feature`.
157
+ Capybara with `type: :feature`.
158
158
 
159
159
  You can now write your specs like so:
160
160
 
161
161
  ```ruby
162
- describe "the signin process", :type => :feature do
162
+ describe "the signin process", type: :feature do
163
163
  before :each do
164
164
  User.make(email: 'user@example.com', password: 'password')
165
165
  end
@@ -183,7 +183,7 @@ to one specific driver. For example:
183
183
  ```ruby
184
184
  describe 'some stuff which requires js', js: true do
185
185
  it 'will use the default js driver'
186
- it 'will switch to one specific driver', :driver => :webkit
186
+ it 'will switch to one specific driver', driver: :webkit
187
187
  end
188
188
  ```
189
189
 
@@ -219,11 +219,11 @@ feature "Signing in" do
219
219
  end
220
220
  ```
221
221
 
222
- `feature` is in fact just an alias for `describe ..., :type => :feature`,
222
+ `feature` is in fact just an alias for `describe ..., type:> :feature`,
223
223
  `background` is an alias for `before`, `scenario` for `it`, and
224
224
  `given`/`given!` aliases for `let`/`let!`, respectively.
225
225
 
226
- Finally, Capybara matchers are supported in view specs:
226
+ Finally, Capybara matchers are also supported in view specs:
227
227
 
228
228
  ```ruby
229
229
  RSpec.describe "todos/show.html.erb", type: :view do
@@ -742,7 +742,7 @@ Capybara 1.x, set `Capybara.match` to `:prefer_exact`.
742
742
 
743
743
  ## <a name="transactions-and-database-setup"></a>Transactions and database setup
744
744
 
745
- **Note:** Rails 5.1+ now "safely" shares the database connection between the app and test threads. Therefore,
745
+ **Note:** Rails 5.1+ "safely" shares the database connection between the app and test threads. Therefore,
746
746
  if using Rails 5.1+ you SHOULD be able to ignore this section.
747
747
 
748
748
  Some Capybara drivers need to run against an actual HTTP server. Capybara takes
@@ -1047,7 +1047,7 @@ additional info about how the underlying driver can be configured.
1047
1047
  are testing for specific server errors and using multiple sessions make sure to test for the
1048
1048
  errors using the initial session (usually :default)
1049
1049
 
1050
- ## <a name="threadsafe"></a>"Threadsafe" mode - BETA - may change
1050
+ ## <a name="threadsafe"></a>"Threadsafe" mode
1051
1051
 
1052
1052
  In normal mode most of Capybara's configuration options are global settings which can cause issues
1053
1053
  if using multiple sessions and wanting to change a setting for only one of the sessions. To provide
@@ -1082,7 +1082,8 @@ To set up a development environment, simply do:
1082
1082
 
1083
1083
  ```bash
1084
1084
  bundle install
1085
- bundle exec rake # run the test suite
1085
+ bundle exec rake # run the test suite with Firefox - requires `geckodriver` to be installed
1086
+ bundle exec rake spec_chrome # run the test suite with Chrome - require `chromedriver` to be installed
1086
1087
  ```
1087
1088
 
1088
1089
  See
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'forwardable'
3
4
  require 'capybara/session/config'
4
5
 
@@ -6,7 +7,7 @@ module Capybara
6
7
  class Config
7
8
  extend Forwardable
8
9
 
9
- OPTIONS = [:app, :reuse_server, :threadsafe, :default_wait_time, :server, :default_driver, :javascript_driver]
10
+ OPTIONS = %i[app reuse_server threadsafe default_wait_time server default_driver javascript_driver].freeze
10
11
 
11
12
  attr_accessor :app
12
13
  attr_reader :reuse_server, :threadsafe
@@ -21,12 +22,9 @@ module Capybara
21
22
  @session_options = Capybara::SessionConfig.new
22
23
  end
23
24
 
24
- def reuse_server=(bool)
25
- @reuse_server = bool
26
- end
25
+ attr_writer :reuse_server
27
26
 
28
27
  def threadsafe=(bool)
29
- warn "Capybara.threadsafe == true is a BETA feature and may change in future minor versions" if bool
30
28
  raise "Threadsafe setting cannot be changed once a session is created" if (bool != threadsafe) && Session.instance_created?
31
29
  @threadsafe = bool
32
30
  end
@@ -35,16 +33,9 @@ module Capybara
35
33
  #
36
34
  # Return the proc that Capybara will call to run the Rack application.
37
35
  # The block returned receives a rack app, port, and host/ip and should run a Rack handler
38
- # By default, Capybara will try to run webrick.
36
+ # By default, Capybara will try to use puma.
39
37
  #
40
- def server(&block)
41
- if block_given?
42
- warn "DEPRECATED: Passing a block to Capybara::server is deprecated, please use Capybara::register_server instead"
43
- @server = block
44
- else
45
- @server
46
- end
47
- end
38
+ attr_reader :server
48
39
 
49
40
  ##
50
41
  #
@@ -62,14 +53,10 @@ module Capybara
62
53
  #
63
54
  def server=(name)
64
55
  name, options = *name if name.is_a? Array
65
- @server = if name.respond_to? :call
66
- name
56
+ @server = if options
57
+ proc { |app, port, host| Capybara.servers[name.to_sym].call(app, port, host, options) }
67
58
  else
68
- if options
69
- Proc.new { |app, port, host| Capybara.servers[name.to_sym].call(app,port,host,options) }
70
- else
71
- Capybara.servers[name.to_sym]
72
- end
59
+ Capybara.servers[name.to_sym]
73
60
  end
74
61
  end
75
62
 
@@ -89,44 +76,10 @@ module Capybara
89
76
  @javascript_driver || :selenium
90
77
  end
91
78
 
92
- # @deprecated Use default_max_wait_time instead
93
- def default_wait_time
94
- deprecate('default_wait_time', 'default_max_wait_time', true)
95
- default_max_wait_time
96
- end
97
-
98
- # @deprecated Use default_max_wait_time= instead
99
- def default_wait_time=(t)
100
- deprecate('default_wait_time=', 'default_max_wait_time=')
101
- self.default_max_wait_time = t
102
- end
103
-
104
- def deprecate(method, alternate_method, once=false)
79
+ def deprecate(method, alternate_method, once = false)
105
80
  @deprecation_notified ||= {}
106
81
  warn "DEPRECATED: ##{method} is deprecated, please use ##{alternate_method} instead" unless once and @deprecation_notified[method]
107
- @deprecation_notified[method]=true
108
- end
109
- end
110
-
111
- # @api private
112
- class ConfigureDeprecator
113
- def initialize(config)
114
- @config = config
115
- end
116
-
117
- def method_missing(m, *args, &block)
118
- if @config.respond_to?(m)
119
- @config.public_send(m, *args, &block)
120
- elsif Capybara.respond_to?(m)
121
- warn "Calling #{m} from Capybara.configure is deprecated - please call it on Capybara directly ( Capybara.#{m}(...) )"
122
- Capybara.public_send(m, *args, &block)
123
- else
124
- super
125
- end
126
- end
127
-
128
- def respond_to_missing?(m, include_private = false)
129
- @config.respond_to?(m) || Capybara.respond_to?(m) || super
82
+ @deprecation_notified[method] = true
130
83
  end
131
84
  end
132
- end
85
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'capybara/dsl'
3
4
  require 'capybara/rspec/matchers'
4
5
  require 'capybara/rspec/matcher_proxies'
@@ -21,8 +22,6 @@ end
21
22
  Before do |scenario|
22
23
  scenario.source_tag_names.each do |tag|
23
24
  driver_name = tag.sub(/^@/, '').to_sym
24
- if Capybara.drivers.has_key?(driver_name)
25
- Capybara.current_driver = driver_name
26
- end
25
+ Capybara.current_driver = driver_name if Capybara.drivers.key?(driver_name)
27
26
  end
28
27
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Capybara::Driver::Base
3
4
  attr_writer :session
4
5
 
@@ -46,7 +47,7 @@ class Capybara::Driver::Base
46
47
  raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#evaluate_script_asnyc'
47
48
  end
48
49
 
49
- def save_screenshot(path, options={})
50
+ def save_screenshot(path, **options)
50
51
  raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#save_screenshot'
51
52
  end
52
53
 
@@ -66,6 +67,16 @@ class Capybara::Driver::Base
66
67
  raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#switch_to_frame'
67
68
  end
68
69
 
70
+ def frame_title
71
+ find_xpath('/html/head/title').map(&:all_text).first.to_s
72
+ end
73
+
74
+ def frame_url
75
+ evaluate_script('document.location.href')
76
+ rescue Capybara::NotSupportedByDriverError
77
+ raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#frame_title'
78
+ end
79
+
69
80
  def current_window_handle
70
81
  raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#current_window_handle'
71
82
  end
@@ -98,15 +109,10 @@ class Capybara::Driver::Base
98
109
  raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#switch_to_window'
99
110
  end
100
111
 
101
- def within_window(locator)
102
- raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#within_window'
103
- end
104
-
105
112
  def no_such_window_error
106
113
  raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#no_such_window_error'
107
114
  end
108
115
 
109
-
110
116
  ##
111
117
  #
112
118
  # Execute the block, and then accept the modal opened.
@@ -117,7 +123,7 @@ class Capybara::Driver::Base
117
123
  # @return [String] the message shown in the modal
118
124
  # @raise [Capybara::ModalNotFound] if modal dialog hasn't been found
119
125
  #
120
- def accept_modal(type, options={}, &blk)
126
+ def accept_modal(type, **options, &blk)
121
127
  raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#accept_modal'
122
128
  end
123
129
 
@@ -130,7 +136,7 @@ class Capybara::Driver::Base
130
136
  # @return [String] the message shown in the modal
131
137
  # @raise [Capybara::ModalNotFound] if modal dialog hasn't been found
132
138
  #
133
- def dismiss_modal(type, options={}, &blk)
139
+ def dismiss_modal(type, **options, &blk)
134
140
  raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#dismiss_modal'
135
141
  end
136
142
 
@@ -142,8 +148,7 @@ class Capybara::Driver::Base
142
148
  false
143
149
  end
144
150
 
145
- def reset!
146
- end
151
+ def reset!; end
147
152
 
148
153
  def needs_server?
149
154
  false
@@ -152,10 +157,4 @@ class Capybara::Driver::Base
152
157
  def session_options
153
158
  (@session && @session.config) || Capybara.session_options
154
159
  end
155
-
156
- # @deprecated This method is being removed
157
- def browser_initialized?
158
- warn "DEPRECATED: #browser_initialized? is deprecated and will be removed in the next version of Capybara"
159
- true
160
- end
161
160
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Capybara
3
4
  module Driver
4
5
  class Node
@@ -27,7 +28,7 @@ module Capybara
27
28
 
28
29
  # @param value String or Array. Array is only allowed if node has 'multiple' attribute
29
30
  # @param options [Hash{}] Driver specific options for how to set a value on a node
30
- def set(value, options={})
31
+ def set(value, **options)
31
32
  raise NotImplementedError
32
33
  end
33
34
 
@@ -39,15 +40,15 @@ module Capybara
39
40
  raise NotImplementedError
40
41
  end
41
42
 
42
- def click
43
+ def click(keys = [], options = {})
43
44
  raise NotImplementedError
44
45
  end
45
46
 
46
- def right_click
47
+ def right_click(keys = [], options = {})
47
48
  raise NotImplementedError
48
49
  end
49
50
 
50
- def double_click
51
+ def double_click(keys = [], options = {})
51
52
  raise NotImplementedError
52
53
  end
53
54
 
data/lib/capybara/dsl.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'capybara'
3
4
 
4
5
  module Capybara
@@ -1,14 +1,12 @@
1
- # encoding: UTF-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module Capybara
5
-
6
4
  # @api private
7
5
  module Helpers
8
6
  extend self
9
7
 
10
8
  ##
11
- #
9
+ # @deprecated
12
10
  # Normalizes whitespace space by stripping leading and trailing
13
11
  # whitespace and replacing sequences of whitespace characters
14
12
  # with a single space.
@@ -17,6 +15,7 @@ module Capybara
17
15
  # @return [String] Normalized text
18
16
  #
19
17
  def normalize_whitespace(text)
18
+ warn "DEPRECATED: Capybara::Helpers::normalize_whitespace is deprecated, please update your driver"
20
19
  text.to_s.gsub(/[[:space:]]+/, ' ').strip
21
20
  end
22
21
 
@@ -26,16 +25,17 @@ module Capybara
26
25
  # if text is not a regexp
27
26
  #
28
27
  # @param [String] text Text to escape
29
- # @return [String] Escaped text
28
+ # @param [Boolean] exact (false) Whether or not this should be an exact text match
29
+ # @param [Fixnum, Boolean, nil] options Options passed to Regexp.new when creating the Regexp
30
+ # @return [Regexp] Regexp to match the passed in text and options
30
31
  #
31
- def to_regexp(text, regexp_options=nil, exact=false)
32
- if text.is_a?(Regexp)
33
- text
34
- else
35
- escaped = Regexp.escape(normalize_whitespace(text))
36
- escaped = "\\A#{escaped}\\z" if exact
37
- Regexp.new(escaped, regexp_options)
38
- end
32
+ def to_regexp(text, exact: false, all_whitespace: false, options: nil)
33
+ return text if text.is_a?(Regexp)
34
+
35
+ escaped = Regexp.escape(text)
36
+ escaped = escaped.gsub("\\ ", "[[:blank:]]") if all_whitespace
37
+ escaped = "\\A#{escaped}\\z" if exact
38
+ Regexp.new(escaped, options)
39
39
  end
40
40
 
41
41
  ##
@@ -44,16 +44,14 @@ module Capybara
44
44
  # `Capybara.asset_host`.
45
45
  #
46
46
  # @param [String] html HTML code to inject into
47
+ # @param [URL] host (Capybara.asset_host) The host from which assets should be loaded
47
48
  # @return [String] The modified HTML code
48
49
  #
49
- def inject_asset_host(html, asset_host = Capybara.asset_host)
50
- if asset_host && Nokogiri::HTML(html).css("base").empty?
50
+ def inject_asset_host(html, host: Capybara.asset_host)
51
+ if host && Nokogiri::HTML(html).css("base").empty?
51
52
  match = html.match(/<head[^<]*?>/)
52
- if match
53
- return html.clone.insert match.end(0), "<base href='#{asset_host}' />"
54
- end
53
+ return html.clone.insert match.end(0), "<base href='#{host}' />" if match
55
54
  end
56
-
57
55
  html
58
56
  end
59
57
 
@@ -68,21 +66,13 @@ module Capybara
68
66
  # @param [Integer] count The number of items
69
67
  #
70
68
  def declension(singular, plural, count)
71
- if count == 1
72
- singular
73
- else
74
- plural
75
- end
69
+ count == 1 ? singular : plural
76
70
  end
77
71
 
78
72
  if defined?(Process::CLOCK_MONOTONIC)
79
- def monotonic_time
80
- Process.clock_gettime Process::CLOCK_MONOTONIC
81
- end
73
+ def monotonic_time; Process.clock_gettime Process::CLOCK_MONOTONIC; end
82
74
  else
83
- def monotonic_time
84
- Time.now.to_f
85
- end
75
+ def monotonic_time; Time.now.to_f; end
86
76
  end
87
77
  end
88
78
  end
@@ -3,32 +3,34 @@ require 'minitest/spec'
3
3
  module Capybara
4
4
  module Minitest
5
5
  module Expectations
6
- %w(text content title current_path).each do |assertion|
6
+ %w[text content title current_path].each do |assertion|
7
7
  infect_an_assertion "assert_#{assertion}", "must_have_#{assertion}", :reverse
8
8
  infect_an_assertion "refute_#{assertion}", "wont_have_#{assertion}", :reverse
9
9
  end
10
10
 
11
- (%w(selector xpath css link button field select table checked_field unchecked_field).flat_map do |assertion|
12
- [["assert_#{assertion}", "must_have_#{assertion}"],
13
- ["refute_#{assertion}", "wont_have_#{assertion}"]]
14
- end + [["assert_all_of_selectors", "must_have_all_of_selectors"],
15
- ["assert_none_of_selectors", "must_have_none_of_selectors"]] +
16
- %w(selector xpath css).flat_map do |assertion|
17
- [["assert_matches_#{assertion}", "must_match_#{assertion}"],
18
- ["refute_matches_#{assertion}", "wont_match_#{assertion}"]]
11
+ # rubocop:disable Style/MultilineBlockChain
12
+ (%w[selector xpath css link button field select table checked_field unchecked_field].flat_map do |assertion|
13
+ [%W[assert_#{assertion} must_have_#{assertion}],
14
+ %W[refute_#{assertion} wont_have_#{assertion}]]
15
+ end + [%w[assert_all_of_selectors must_have_all_of_selectors],
16
+ %w[assert_none_of_selectors must_have_none_of_selectors]] +
17
+ %w[selector xpath css].flat_map do |assertion|
18
+ [%W[assert_matches_#{assertion} must_match_#{assertion}],
19
+ %W[refute_matches_#{assertion} wont_match_#{assertion}]]
19
20
  end).each do |(meth, new_name)|
20
- self.class_eval <<-EOM, __FILE__, __LINE__ + 1
21
+ class_eval <<-ASSERTION, __FILE__, __LINE__ + 1
21
22
  def #{new_name} *args, &block
22
23
  ::Minitest::Expectation.new(self, ::Minitest::Spec.current).#{new_name}(*args, &block)
23
24
  end
24
- EOM
25
+ ASSERTION
25
26
 
26
- ::Minitest::Expectation.class_eval <<-EOM, __FILE__, __LINE__ + 1
27
+ ::Minitest::Expectation.class_eval <<-ASSERTION, __FILE__, __LINE__ + 1
27
28
  def #{new_name} *args, &block
28
29
  ctx.#{meth}(target, *args, &block)
29
30
  end
30
- EOM
31
+ ASSERTION
31
32
  end
33
+ # rubocop:enable Style/MultilineBlockChain
32
34
 
33
35
  ##
34
36
  # Expectation that there is xpath
@@ -159,7 +161,6 @@ module Capybara
159
161
  #
160
162
  # @!method wont_have_current_path
161
163
  # see {Capybara::SessionMatchers#assert_no_current_path}
162
-
163
164
  end
164
165
  end
165
166
  end