capybara 2.13.0 → 2.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +82 -17
  3. data/README.md +29 -0
  4. data/lib/capybara.rb +81 -116
  5. data/lib/capybara/config.rb +121 -0
  6. data/lib/capybara/cucumber.rb +1 -0
  7. data/lib/capybara/driver/base.rb +6 -0
  8. data/lib/capybara/dsl.rb +1 -3
  9. data/lib/capybara/helpers.rb +3 -3
  10. data/lib/capybara/node/actions.rb +2 -2
  11. data/lib/capybara/node/base.rb +7 -2
  12. data/lib/capybara/node/element.rb +7 -1
  13. data/lib/capybara/node/finders.rb +13 -3
  14. data/lib/capybara/node/matchers.rb +15 -4
  15. data/lib/capybara/node/simple.rb +5 -0
  16. data/lib/capybara/queries/base_query.rb +8 -3
  17. data/lib/capybara/queries/selector_query.rb +11 -9
  18. data/lib/capybara/queries/text_query.rb +9 -4
  19. data/lib/capybara/rack_test/browser.rb +8 -5
  20. data/lib/capybara/rspec.rb +3 -1
  21. data/lib/capybara/rspec/matcher_proxies.rb +41 -0
  22. data/lib/capybara/rspec/matchers.rb +19 -5
  23. data/lib/capybara/selector.rb +13 -4
  24. data/lib/capybara/selector/selector.rb +3 -3
  25. data/lib/capybara/selenium/driver.rb +20 -6
  26. data/lib/capybara/selenium/node.rb +6 -2
  27. data/lib/capybara/server.rb +6 -5
  28. data/lib/capybara/session.rb +71 -14
  29. data/lib/capybara/session/config.rb +100 -0
  30. data/lib/capybara/spec/public/test.js +1 -1
  31. data/lib/capybara/spec/session/all_spec.rb +11 -0
  32. data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +24 -8
  33. data/lib/capybara/spec/session/fill_in_spec.rb +6 -0
  34. data/lib/capybara/spec/session/find_field_spec.rb +1 -0
  35. data/lib/capybara/spec/session/find_spec.rb +4 -3
  36. data/lib/capybara/spec/session/has_selector_spec.rb +1 -3
  37. data/lib/capybara/spec/session/node_spec.rb +23 -17
  38. data/lib/capybara/spec/session/reset_session_spec.rb +1 -1
  39. data/lib/capybara/spec/session/window/become_closed_spec.rb +4 -4
  40. data/lib/capybara/spec/spec_helper.rb +22 -0
  41. data/lib/capybara/spec/views/form.erb +6 -1
  42. data/lib/capybara/spec/views/with_html.erb +1 -0
  43. data/lib/capybara/version.rb +1 -1
  44. data/lib/capybara/window.rb +1 -1
  45. data/spec/capybara_spec.rb +14 -2
  46. data/spec/dsl_spec.rb +1 -0
  47. data/spec/per_session_config_spec.rb +67 -0
  48. data/spec/rspec/shared_spec_matchers.rb +2 -2
  49. data/spec/rspec/views_spec.rb +4 -0
  50. data/spec/rspec_spec.rb +77 -0
  51. data/spec/session_spec.rb +44 -0
  52. data/spec/shared_selenium_session.rb +9 -0
  53. data/spec/spec_helper.rb +4 -0
  54. metadata +7 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 266938107d80bacdd4f95cc21e79fe6b7af2e131
4
- data.tar.gz: dac8ea7395988fc218da8a556df246db661125b0
3
+ metadata.gz: 95059b9953d4a957739d739dadd55c294e39046b
4
+ data.tar.gz: fd4c944ff4a42c21661a1b6d39a243032b4ea7a8
5
5
  SHA512:
6
- metadata.gz: a548da527db279933776ebd86daa6ddf1d7e714bc9b22225959d58b67bbecfa8458f503cde377fc262f0d4442ef6d0f47a88a1bcf66efd58bc5014d80b80f87d
7
- data.tar.gz: f040e322ba5e591dbc3546b0e5c7672f21b6e9eab99ff848780f42e1e1d9e5ce87bdfe242ae0dbb7a45b4ecb37611d3c1c1a202cedcc1e16cc00040114422213
6
+ metadata.gz: b3bfd9f5c365c483b058461d58abe63e58f162b051e739794d30f69ea84e93ed7993245dfffc9ca48f96270022aa40df5e32a60bb6df29bbc93d85c0a7f714d3
7
+ data.tar.gz: bdb337934a2477819f03e9cfbbd683832a4d69775f6a688e5098079b48fc0ef630de10a8a5e7e78198ac9144cc2afe063dfeb9b73a15d73204688b789358d4a8
data/History.md CHANGED
@@ -1,4 +1,24 @@
1
- #Version 2.13.0
1
+ # Version 2.14.0
2
+
3
+ Release date: 2017-05-01
4
+
5
+ ### Added
6
+
7
+ * "threadsafe" mode that allows per-session configuration
8
+ * `:type` filter added to the `:fillable_field` selector
9
+ * Proxy methods when using RSpec for `all`/`within` that call either the Capybara::DSL or RSpec matchers
10
+ depending on arguments passed
11
+ * Support for the new errors in selenium-webdriver 3.4
12
+
13
+ ### Fixed
14
+
15
+ * Element#inspect doesn't raise an error on obsolete elements
16
+ * Setting a contenteditable element with Selenium and Chrome 59
17
+ * Workaround a hang while setting the window size when using geckodriver 0.16 and Firefox 53
18
+ * Clicking on url with a blank href goes to the current url when using the RackTest driver
19
+
20
+ # Version 2.13.0
21
+
2
22
  Release date: 2017-03-16
3
23
 
4
24
  ### Added
@@ -7,16 +27,19 @@ Release date: 2017-03-16
7
27
  * rack_test driver supports click on checkboxes and radio buttons to change their states [Thomas Walpole]
8
28
  * Support RSpec equivalent assertions and expectations for MiniTest [Thomas Walpole]
9
29
 
10
- ### Foxed
30
+ ### Fixed
31
+
11
32
  * Editing of content editable children with selenium
12
33
 
13
- #Version 2.12.1
34
+ # Version 2.12.1
35
+
14
36
  Release date: 2017-02-16
15
37
 
16
38
  ### Fixed
17
39
  * Disable lazy Capybara::Results evaluation for JRuby due to ongoing issues
18
40
 
19
- #Version 2.12.0
41
+ # Version 2.12.0
42
+
20
43
  Release date: 2017-01-22
21
44
 
22
45
  ### Added
@@ -35,6 +58,7 @@ Release date: 2017-01-22
35
58
  * `within_element` as an alias of `within` due to RSpec collision
36
59
 
37
60
  ### Fixed
61
+
38
62
  * Fields inside a disabled fieldset are now correctly considered disabled - Issue #1816 [Thomas Walpole]
39
63
  * Lazy Capybara::Results evaluation enabled for JRuby 9.1.6.0+
40
64
  * A driver returning nil for #current_url won't raise an exception when calling #current_path [Dylan Reichstadt]
@@ -42,10 +66,12 @@ Release date: 2017-01-22
42
66
  * RackTest driver no longer modifies the text content of textarea elements in order to behave more like a real browser [Thomas Walpole]
43
67
  * TextQuery (assert_text/have_text/etc) now ignores errors when trying to generate more helpful errors messages so the original error isn't hidden [Thomas Walpole]
44
68
 
45
- #Version 2.11.0
69
+ # Version 2.11.0
70
+
46
71
  Release date: 2016-12-05
47
72
 
48
73
  ### Added
74
+
49
75
  * Options for clearing session/local storage on reset added to the Selenium driver
50
76
  * Window size changes wait for the size to stabilize
51
77
  * Defined return value for most actions
@@ -54,17 +80,21 @@ Release date: 2016-12-05
54
80
  * Capybara::Result#each now returns an `Enumerator` when called without a block - Issue #1777 [Thomas Walpole]
55
81
 
56
82
  ### Fixed
83
+
57
84
  * Selenium driver with Chrome should support multiple file upload [Thomas Walpole]
58
85
  * Fix visible: :hidden with :text option behavior [Thomas Walpole]
59
86
 
60
- #Version 2.10.2
87
+ # Version 2.10.2
88
+
61
89
  Release date: 2016-11-30
62
90
 
63
91
  ### Fixed
92
+
64
93
  * App exceptions with multiple parameter initializers now re-raised correctly - Issue #1785 [Michael Lutsiuk]
65
94
  * Use Addressable::URI when parsing current_path since it's more lenient of technically invalid URLs - Issue #1801 [Marcos Duque, Thomas Walpole]
66
95
 
67
- #Version 2.10.1
96
+ # Version 2.10.1
97
+
68
98
  Release date: 2016-10-08
69
99
 
70
100
  ### Fixed
@@ -72,52 +102,64 @@ Release date: 2016-10-08
72
102
  * Capybara::Result optimization disabled in JRuby due to issue with lazy enumerator evaluation [Thomas Walpole]
73
103
  See: https://github.com/jruby/jruby/issues/4212
74
104
 
75
- #Version 2.10.0
105
+ # Version 2.10.0
106
+
76
107
  Release date: 2016-10-05
77
108
 
78
109
  ### Added
110
+
79
111
  * Select `<button>` elements with descendant images with `alt` attributes matching the locator [Ian Lesperance]
80
112
  * Locator string is optional in selector based matchers [Thomas Walpole]
81
113
  * Selectors can specify their default visible setting [Thomas Walpole]
82
114
  * Selector based finders and matchers can be passed a block to filter the results within the retry behavior [Thomas Walpole]
83
115
 
84
- #Version 2.9.2
116
+ # Version 2.9.2
117
+
85
118
  Release date: 2016-09-29
86
119
 
87
120
  ### Fixed
88
121
  * :label built-in selector finds nested label/control by control id if the label has no 'for' attribute [Thomas Walpole]
89
122
  * Warning issued if an unknown selector type is specified [Thomas Walpole]
90
123
 
91
- #Version 2.9.1
124
+ # Version 2.9.1
125
+
92
126
  Release date: 2016-09-23
93
127
 
94
128
  ### Fixed
129
+
95
130
  * allow_label_click option did not work in some cases with Poltergeist - Issue #1762 [Thomas Walpole]
96
131
  * matches_selector? should have access to all of a selectors options except the count options [Thomas Walpole]
97
132
 
98
- #Version 2.9.0
133
+ # Version 2.9.0
134
+
99
135
  Release date: 2016-09-19
100
136
 
101
137
  ### Fixed
138
+
102
139
  * Issue with rack-test driver and obselete mime-types when using `#attach_file` - Issue #1756 [Thomas Walpole]
103
140
 
104
141
  ### Added
142
+
105
143
  * `:class` option to many of the built-in selectors [Thomas Walpole]
106
144
  * Removed need to specify value when creating `:boolean` filter type in custom selectors [Thomas Walpole]
107
145
  * Filters can now be implemented through the XPath/CSS expressions in custom selectors [Thomas Walpole]
108
146
  * `Element#matches_xpath?` and `Element#matches_css?` [Thomas Walpole]
109
147
 
110
- #Version 2.8.1
148
+ # Version 2.8.1
149
+
111
150
  Release date: 2016-08-25
112
151
 
113
152
  ###Fixed
153
+
114
154
  * Fixed error message from have_text when text is not found but contains regex special characters [Ryunosuke Sato]
115
155
  * Warn when :exact option is passed that has no effect [Thomas Walpole]
116
156
 
117
157
  # Version 2.8.0
158
+
118
159
  Release date: 2016-08-16
119
160
 
120
161
  ### Fixed
162
+
121
163
  * Issue with modals present when closing the page using selenium - Issue #1696 [Jonas Nicklas, Thomas Walpole]
122
164
  * Server errors raised in test code have the cause set to an explanatory exception
123
165
  in rubies that support Exception#cause rather than a confusing ExpectationNotMet - Issue #1719 [Thomas Walpole]
@@ -125,6 +167,7 @@ Release date: 2016-08-16
125
167
  * Fixed setting of unexpectedAlertError now that Selenium will be freezing the Capabilities::DEFAULTS [Thomas Walpole]
126
168
 
127
169
  ### Added
170
+
128
171
  * 'check', 'uncheck', and 'choose' can now optionally click the associated label if the checkbox/radio button is not visible [Thomas Walpole]
129
172
  * Raise error if Capybara.app_host/default_host are specified incorrectly [Thomas Walpole]
130
173
  * Capybara::Selector::FilterSet allows for sharing filter definitions between selectors [Thomas Walpole]
@@ -136,19 +179,22 @@ Release date: 2016-08-16
136
179
  * Support matching on aria-label attribute when finding fields/links/buttons - Issue #1528 [Thomas Walpole]
137
180
  * Optimize Capybara::Result to only apply fields as necessary in common use-case of `.all[idx]` [Thomas Walpole]
138
181
 
139
- #Version 2.7.1
182
+ # Version 2.7.1
183
+
140
184
  Release date: 2016-05-01
141
185
 
142
186
  ### Fixed
187
+
143
188
  * Issue where within_Frame would fail with Selenium if the frame is removed from within itself [Thomas Walpole]
144
189
  * Reset sessions in reverse order so sessions with active servers are reset last - Issue #1692 [Jonas Nicklas, Thomas Walpole]
145
190
 
146
191
  # Version 2.7.0
192
+
147
193
  Release date: 2016-04-07
148
194
 
149
195
  ### Fixed
150
- * Element#visible?/checked?/disabled?/selected? Now return boolean
151
- as expected when using the rack_test driver [Thomas Walpole]
196
+
197
+ * Element#visible?/checked?/disabled?/selected? Now return boolean as expected when using the rack_test driver [Thomas Walpole]
152
198
  * The rack_test driver now considers \<input type="hidden"> elements as non-visible [Thomas Walpole]
153
199
  * A nil locator passed to the built-in html type selectors now behaves consistently, and finds elements of the expected types [Thomas Walpole]
154
200
  * Capybara::Server now searches for available ports on the same interface it binds to [Aaron Stone]
@@ -156,6 +202,7 @@ Release date: 2016-04-07
156
202
  * Warning output if unused parameters are passed to a selector query [Thomas Walpole]
157
203
 
158
204
  ### Added
205
+
159
206
  * Capybara now waits for requests to Capybaras server to complete while restting the session [John Hawthorn, Thomas Walpole]
160
207
  * Capybara.reuse_server option to allow disabling of sharing server instance between sessions [Thomas Walpole]
161
208
  * :multiple filter added to relevant selectors [Thomas Walpole]
@@ -168,22 +215,28 @@ Release date: 2016-04-07
168
215
  save_page/save_screenshot [Thomas Walpole]
169
216
  * :label selector [Thomas Walpole]
170
217
 
171
- #Version 2.6.2
218
+ # Version 2.6.2
219
+
172
220
  Relase date: 2016-01-27
173
221
 
174
222
  ### Fixed
223
+
175
224
  * support for more than just addressable 2.4.0 [Thomas Walpole]
176
225
 
177
226
  # Version 2.6.1
227
+
178
228
  Release date: 2016-01-27
179
229
 
180
230
  ### Fixed
231
+
181
232
  * Add missing require for addressable [Jorge Bejar]
182
233
 
183
234
  # Version 2.6.0
235
+
184
236
  Relase date: 2016-01-17
185
237
 
186
238
  ### Fixed
239
+
187
240
  * Fixed path escaping issue with current_path matchers [Thomas Walpole, Luke Rollans] (Issue #1611)
188
241
  * Fixed circular require [David Rodríguez]
189
242
  * Capybara::RackTest::Form no longer overrides Object#method [David Rodriguez]
@@ -192,6 +245,7 @@ Relase date: 2016-01-17
192
245
 
193
246
 
194
247
  ### Added
248
+
195
249
  * Capybara.modify_selector [Thomas Walpole]
196
250
  * xfeature and ffeature aliases added when using RSpec [Filip Bartuzi]
197
251
  * Selenium driver supports a :clear option to #set to handle different strategies for clearing a field [Thomas Walpole]
@@ -200,15 +254,18 @@ Relase date: 2016-01-17
200
254
  * Modal API methods now default wait time to Capybara.default_max_wait_time [Thomas Walpole]
201
255
 
202
256
  # Version 2.5.0
257
+
203
258
  Release date: 2015-08-25
204
259
 
205
260
  ### Fixed
261
+
206
262
  * Error message now raised correctly when invalid options passed to 'have_text'/'have_content' [Thomas Walpole]
207
263
  * Rack-test driver correctly gets document title when elements on the page have nested title elements (SVG) [Thomas Walpole]
208
264
  * 'save_page' no longer errors when using Capybara.asset_host if the page has no \<head> element [Travis Grathwell]
209
265
  * rack-test driver will ignore clicks on links with href starting with '#' or 'javascript:'
210
266
 
211
267
  ### Added
268
+
212
269
  * has_current_path? and associated asserts/matchers added [Thomas Walpole]
213
270
  * Implement Node#path in selenium driver [Soutaro Matsumoto]
214
271
  * 'using_session' is now nestable [Thomas Walpole]
@@ -226,25 +283,32 @@ Release date: 2015-08-25
226
283
  * Clear field using backspaces in Selenium driver by using `:fill_options => { :clear => :backspace }` [Joe Lencioni]
227
284
 
228
285
  ### Deprecated
286
+
229
287
  * Capybara.default_wait_time deprecated in favor of Capybara.default_max_wait_time to more clearly explain its purpose [Paul Pettengill]
230
288
 
231
- #Version 2.4.4
289
+ # Version 2.4.4
290
+
232
291
  Release date: 2014-10-13
233
292
 
234
293
  ### Fixed
294
+
235
295
  * Test for visit behavior updated [Phil Baker]
236
296
  * Removed concurrency prevention in favor of a note in the README - due to load order issues
237
297
 
238
298
  # Version 2.4.3
299
+
239
300
  Relase date: 2014-09-21
240
301
 
241
302
  ### Fixed
303
+
242
304
  * Update concurrency prevention to match Rails 4.2 behavior
243
305
 
244
306
  # Version 2.4.2
307
+
245
308
  Release date: 2014-09-20
246
309
 
247
310
  ### Fixed
311
+
248
312
  * Prevent concurrency issue when testing Rails app with default test environment [Thomas Walpole]
249
313
  * Tags for windows API tests fixed [Dmitry Vorotilin]
250
314
  * Documentation Fixes [Andrey Botalov]
@@ -279,6 +343,7 @@ Release date: 2014-07-03
279
343
  Release date: 2014-06-02
280
344
 
281
345
  ### Added
346
+
282
347
  * New window management API [Andrey Botalov]
283
348
  * Speed improvement for visible text detection in RackTest [Thomas Walpole]
284
349
  Thanks to Phillipe Creux for instigating this
data/README.md CHANGED
@@ -67,6 +67,7 @@ You can read more about the missing features [here](https://github.com/teamcapyb
67
67
  - [Beware the XPath // trap](#beware-the-xpath--trap)
68
68
  - [Configuring and adding drivers](#configuring-and-adding-drivers)
69
69
  - [Gotchas:](#gotchas)
70
+ - ["Threadsafe" mode](#threadsafe)
70
71
  - [Development](#development)
71
72
 
72
73
  ## <a name="key-benefits"></a>Key benefits
@@ -241,6 +242,9 @@ RSpec.describe "todos/show.html.erb", type: :view do
241
242
  end
242
243
  ```
243
244
 
245
+ **Note: When you require 'capybara/rspec' proxy methods are installed to work around name collisions between Capybara::DSL methods
246
+ `all`/`within` and the identically named built-in RSpec matchers. If you opt not to require 'capybara/rspec' you can install the proxy methods by requiring 'capybara/rspec/matcher_proxies' after requiring RSpec and 'capybara/dsl'**
247
+
244
248
  ## <a name="using-capybara-with-testunit"></a>Using Capybara with Test::Unit
245
249
 
246
250
  * If you are using `Test::Unit`, define a base class for your Capybara tests
@@ -1045,6 +1049,31 @@ additional info about how the underlying driver can be configured.
1045
1049
  are testing for specific server errors and using multiple sessions make sure to test for the
1046
1050
  errors using the initial session (usually :default)
1047
1051
 
1052
+ ## <a name="threadsafe"></a>"Threadsafe" mode - BETA - may change
1053
+
1054
+ In normal mode most of Capybara's configuration options are global settings which can cause issues
1055
+ if using multiple sessions and wanting to change a setting for only one of the sessions. To provide
1056
+ support for this type of usage Capybara now provides a "threadsafe" mode which can be enabled by setting
1057
+
1058
+ Capybara.threadsafe = true
1059
+
1060
+ This setting can only be changed before any sessions have been created. In "threadsafe" mode the following
1061
+ behaviors of Capybara change
1062
+
1063
+ * Most options can now be set on a session. These can either be set at session creation time or after, and
1064
+ default to the global options at the time of session creation. Options which are NOT session specific are
1065
+ `app`, `reuse_server`, `default_driver`, `javascript_driver`, and (obviously) `threadsafe`. Any drivers and servers
1066
+ registered through `register_driver` and `register_server` are also global.
1067
+
1068
+ my_session = Capybara::Session.new(:driver, some_app) do |config|
1069
+ config.automatic_label_click = true # only set for my_session
1070
+ end
1071
+ my_session.config.default_max_wait_time = 10 # only set for my_session
1072
+ Capybara.default_max_wait_time = 2 # will not change the default_max_wait in my_session
1073
+
1074
+ * `current_driver` and `session_name` are thread specific. This means that `using_session' and
1075
+ `using_driver` also only affect the current thread.
1076
+
1048
1077
  ## <a name="development"></a>Development
1049
1078
 
1050
1079
  To set up a development environment, simply do:
@@ -2,6 +2,8 @@
2
2
  require 'timeout'
3
3
  require 'nokogiri'
4
4
  require 'xpath'
5
+ require 'forwardable'
6
+ require 'capybara/config'
5
7
 
6
8
  module Capybara
7
9
  class CapybaraError < StandardError; end
@@ -19,18 +21,41 @@ module Capybara
19
21
  class WindowError < CapybaraError; end
20
22
  class ReadOnlyElementError < CapybaraError; end
21
23
 
24
+
22
25
  class << self
23
- attr_reader :app_host, :default_host
24
- attr_accessor :asset_host, :run_server, :always_include_port
25
- attr_accessor :server_port, :exact, :match, :exact_options, :visible_text_only, :enable_aria_label
26
- attr_accessor :default_selector, :default_max_wait_time, :ignore_hidden_elements
27
- attr_accessor :save_path, :wait_on_first_by_default, :automatic_label_click, :automatic_reload
28
- attr_reader :reuse_server
29
- attr_accessor :raise_server_errors, :server_errors
30
- attr_writer :default_driver, :current_driver, :javascript_driver, :session_name, :server_host
31
- attr_reader :save_and_open_page_path
32
- attr_accessor :exact_text
33
- attr_accessor :app
26
+ extend Forwardable
27
+
28
+ # DelegateCapybara global configurations
29
+ # @!method app
30
+ # See {Capybara#configure}
31
+ # @!method reuse_server
32
+ # See {Capybara#configure}
33
+ # @!method threadsafe
34
+ # See {Capybara#configure}
35
+ # @!method server
36
+ # See {Capybara#configure}
37
+ # @!method default_driver
38
+ # See {Capybara#configure}
39
+ # @!method javascript_driver
40
+ # See {Capybara#configure}
41
+ Config::OPTIONS.each do |method|
42
+ def_delegators :config, method, "#{method}="
43
+ end
44
+
45
+ # Delegate Capybara global configurations
46
+ # @!method default_selector
47
+ # See {Capybara#configure}
48
+ # @!method default_max_wait_time
49
+ # See {Capybara#configure}
50
+ # @!method app_host
51
+ # See {Capybara#configure}
52
+ # @!method always_include_port
53
+ # See {Capybara#configure}
54
+ # @!method wait_on_first_by_default
55
+ # See {Capybara#configure}
56
+ SessionConfig::OPTIONS.each do |method|
57
+ def_delegators :config, method, "#{method}="
58
+ end
34
59
 
35
60
  ##
36
61
  #
@@ -58,6 +83,9 @@ module Capybara
58
83
  # [automatic_label_click = Boolean] Whether Node#choose, Node#check, Node#uncheck will attempt to click the associated label element if the checkbox/radio button are non-visible (Default: false)
59
84
  # [enable_aria_label = Boolean] Whether fields, links, and buttons will match against aria-label attribute (Default: false)
60
85
  # [reuse_server = Boolean] Reuse the server thread between multiple sessions using the same app object (Default: true)
86
+ # [threadsafe = Boolean] Whether sessions can be configured individually (Default: false)
87
+ # [server = Symbol] The name of the registered server to use when running the app under test (Default: :webrick)
88
+ #
61
89
  # === DSL Options
62
90
  #
63
91
  # when using capybara/dsl, the following options are also available:
@@ -66,7 +94,7 @@ module Capybara
66
94
  # [javascript_driver = Symbol] The name of a driver to use for JavaScript enabled tests. (Default: :selenium)
67
95
  #
68
96
  def configure
69
- yield self
97
+ yield ConfigureDeprecator.new(config)
70
98
  end
71
99
 
72
100
  ##
@@ -163,45 +191,6 @@ module Capybara
163
191
  @servers ||= {}
164
192
  end
165
193
 
166
- ##
167
- #
168
- # Register a proc that Capybara will call to run the Rack application.
169
- #
170
- # Capybara.server do |app, port, host|
171
- # require 'rack/handler/mongrel'
172
- # Rack::Handler::Mongrel.run(app, :Port => port)
173
- # end
174
- #
175
- # By default, Capybara will try to run webrick.
176
- #
177
- # @yield [app, port, host] This block receives a rack app, port, and host/ip and should run a Rack handler
178
- #
179
- def server(&block)
180
- if block_given?
181
- warn "DEPRECATED: Passing a block to Capybara::server is deprecated, please use Capybara::register_server instead"
182
- @server = block
183
- else
184
- @server
185
- end
186
- end
187
-
188
- ##
189
- #
190
- # Set the server to use.
191
- #
192
- # Capybara.server = :webrick
193
- #
194
- # @param [Symbol] name Name of the server type to use
195
- # @see register_server
196
- #
197
- def server=(name)
198
- @server = if name.respond_to? :call
199
- name
200
- else
201
- servers[name.to_sym]
202
- end
203
- end
204
-
205
194
  ##
206
195
  #
207
196
  # Wraps the given string, which should contain an HTML document or fragment
@@ -251,29 +240,25 @@ module Capybara
251
240
  servers[:webrick].call(app, port, server_host)
252
241
  end
253
242
 
254
- ##
255
- #
256
- # @return [Symbol] The name of the driver to use by default
257
- #
258
- def default_driver
259
- @default_driver || :rack_test
260
- end
261
-
262
243
  ##
263
244
  #
264
245
  # @return [Symbol] The name of the driver currently in use
265
246
  #
266
247
  def current_driver
267
- @current_driver || default_driver
248
+ if threadsafe
249
+ Thread.current['capybara_current_driver']
250
+ else
251
+ @current_driver
252
+ end || default_driver
268
253
  end
269
254
  alias_method :mode, :current_driver
270
255
 
271
- ##
272
- #
273
- # @return [Symbol] The name of the driver used when JavaScript is needed
274
- #
275
- def javascript_driver
276
- @javascript_driver || :selenium
256
+ def current_driver=(name)
257
+ if threadsafe
258
+ Thread.current['capybara_current_driver'] = name
259
+ else
260
+ @current_driver = name
261
+ end
277
262
  end
278
263
 
279
264
  ##
@@ -281,7 +266,7 @@ module Capybara
281
266
  # Use the default driver as the current driver
282
267
  #
283
268
  def use_default_driver
284
- @current_driver = nil
269
+ self.current_driver = nil
285
270
  end
286
271
 
287
272
  ##
@@ -293,15 +278,7 @@ module Capybara
293
278
  Capybara.current_driver = driver
294
279
  yield
295
280
  ensure
296
- @current_driver = previous_driver
297
- end
298
-
299
- ##
300
- #
301
- # @return [String] The IP address bound by default server
302
- #
303
- def server_host
304
- @server_host || '127.0.0.1'
281
+ self.current_driver = previous_driver
305
282
  end
306
283
 
307
284
  ##
@@ -344,7 +321,19 @@ module Capybara
344
321
  # @return [Symbol] The name of the currently used session.
345
322
  #
346
323
  def session_name
347
- @session_name ||= :default
324
+ if threadsafe
325
+ Thread.current['capybara_session_name'] ||= :default
326
+ else
327
+ @session_name ||= :default
328
+ end
329
+ end
330
+
331
+ def session_name=(name)
332
+ if threadsafe
333
+ Thread.current['capybara_session_name'] = name
334
+ else
335
+ @session_name = name
336
+ end
348
337
  end
349
338
 
350
339
  ##
@@ -352,11 +341,19 @@ module Capybara
352
341
  # Yield a block using a specific session name.
353
342
  #
354
343
  def using_session(name)
355
- previous_session_name = self.session_name
344
+ previous_session_info = {
345
+ session_name: session_name,
346
+ current_driver: current_driver,
347
+ app: app
348
+ }
356
349
  self.session_name = name
357
350
  yield
358
351
  ensure
359
- self.session_name = previous_session_name
352
+ self.session_name = previous_session_info[:session_name]
353
+ if threadsafe
354
+ self.current_driver = previous_session_info[:current_driver]
355
+ self.app = previous_session_info[:app]
356
+ end
360
357
  end
361
358
 
362
359
  ##
@@ -374,32 +371,8 @@ module Capybara
374
371
  end
375
372
  end
376
373
 
377
- # @deprecated Use default_max_wait_time instead
378
- def default_wait_time
379
- deprecate('default_wait_time', 'default_max_wait_time', true)
380
- default_max_wait_time
381
- end
382
-
383
- # @deprecated Use default_max_wait_time= instead
384
- def default_wait_time=(t)
385
- deprecate('default_wait_time=', 'default_max_wait_time=')
386
- self.default_max_wait_time = t
387
- end
388
-
389
- def save_and_open_page_path=(path)
390
- warn "DEPRECATED: #save_and_open_page_path is deprecated, please use #save_path instead. \n"\
391
- "Note: Behavior is slightly different with relative paths - see documentation" unless path.nil?
392
- @save_and_open_page_path = path
393
- end
394
-
395
- def app_host=(url)
396
- raise ArgumentError.new("Capybara.app_host should be set to a url (http://www.example.com)") unless url.nil? || (url =~ URI::Parser.new.make_regexp)
397
- @app_host = url
398
- end
399
-
400
- def default_host=(url)
401
- raise ArgumentError.new("Capybara.default_host should be set to a url (http://www.example.com)") unless url.nil? || (url =~ URI::Parser.new.make_regexp)
402
- @default_host = url
374
+ def session_options
375
+ config.session_options
403
376
  end
404
377
 
405
378
  def included(base)
@@ -407,18 +380,10 @@ module Capybara
407
380
  warn "`include Capybara` is deprecated. Please use `include Capybara::DSL` instead."
408
381
  end
409
382
 
410
- def reuse_server=(bool)
411
- warn "Capybara.reuse_server == false is a BETA feature and may change in a future version" unless bool
412
- @reuse_server = bool
413
- end
414
-
415
- def deprecate(method, alternate_method, once=false)
416
- @deprecation_notified ||= {}
417
- warn "DEPRECATED: ##{method} is deprecated, please use ##{alternate_method} instead" unless once and @deprecation_notified[method]
418
- @deprecation_notified[method]=true
419
- end
420
-
421
383
  private
384
+ def config
385
+ @config ||= Capybara::Config.new
386
+ end
422
387
 
423
388
  def session_pool
424
389
  @session_pool ||= {}