actionpack 6.0.0.beta1 → 6.0.1.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionpack might be problematic. Click here for more details.

Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +125 -13
  3. data/README.rdoc +2 -1
  4. data/lib/abstract_controller/caching/fragments.rb +0 -1
  5. data/lib/abstract_controller/translation.rb +1 -0
  6. data/lib/action_controller.rb +4 -1
  7. data/lib/action_controller/metal.rb +3 -3
  8. data/lib/action_controller/metal/basic_implicit_render.rb +1 -1
  9. data/lib/action_controller/metal/etag_with_template_digest.rb +1 -1
  10. data/lib/action_controller/metal/exceptions.rb +2 -2
  11. data/lib/action_controller/metal/force_ssl.rb +1 -2
  12. data/lib/action_controller/metal/helpers.rb +2 -2
  13. data/lib/action_controller/metal/implicit_render.rb +2 -2
  14. data/lib/action_controller/metal/live.rb +2 -2
  15. data/lib/action_controller/metal/mime_responds.rb +1 -1
  16. data/lib/action_controller/metal/params_wrapper.rb +2 -2
  17. data/lib/action_controller/metal/redirecting.rb +6 -27
  18. data/lib/action_controller/metal/renderers.rb +4 -4
  19. data/lib/action_controller/metal/rendering.rb +1 -1
  20. data/lib/action_controller/metal/request_forgery_protection.rb +2 -2
  21. data/lib/action_controller/metal/strong_parameters.rb +6 -12
  22. data/lib/action_controller/renderer.rb +2 -2
  23. data/lib/action_controller/template_assertions.rb +1 -1
  24. data/lib/action_controller/test_case.rb +3 -2
  25. data/lib/action_dispatch.rb +1 -1
  26. data/lib/action_dispatch/http/content_security_policy.rb +20 -9
  27. data/lib/action_dispatch/http/mime_negotiation.rb +5 -0
  28. data/lib/action_dispatch/http/mime_type.rb +13 -1
  29. data/lib/action_dispatch/http/response.rb +27 -7
  30. data/lib/action_dispatch/http/upload.rb +4 -1
  31. data/lib/action_dispatch/journey/formatter.rb +1 -1
  32. data/lib/action_dispatch/journey/path/pattern.rb +6 -1
  33. data/lib/action_dispatch/journey/route.rb +5 -4
  34. data/lib/action_dispatch/journey/routes.rb +0 -1
  35. data/lib/action_dispatch/middleware/actionable_exceptions.rb +39 -0
  36. data/lib/action_dispatch/middleware/cookies.rb +9 -10
  37. data/lib/action_dispatch/middleware/debug_exceptions.rb +8 -2
  38. data/lib/action_dispatch/middleware/debug_view.rb +19 -1
  39. data/lib/action_dispatch/middleware/exception_wrapper.rb +15 -10
  40. data/lib/action_dispatch/middleware/host_authorization.rb +2 -2
  41. data/lib/action_dispatch/middleware/public_exceptions.rb +6 -2
  42. data/lib/action_dispatch/middleware/remote_ip.rb +3 -3
  43. data/lib/action_dispatch/middleware/session/cookie_store.rb +4 -3
  44. data/lib/action_dispatch/middleware/show_exceptions.rb +1 -1
  45. data/lib/action_dispatch/middleware/stack.rb +34 -2
  46. data/lib/action_dispatch/middleware/templates/rescues/_actions.html.erb +13 -0
  47. data/lib/action_dispatch/middleware/templates/rescues/_actions.text.erb +0 -0
  48. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +3 -1
  49. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +1 -1
  50. data/lib/action_dispatch/middleware/templates/rescues/blocked_host.html.erb +2 -2
  51. data/lib/action_dispatch/middleware/templates/rescues/blocked_host.text.erb +2 -2
  52. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +6 -2
  53. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +1 -1
  54. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +4 -1
  55. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +3 -1
  56. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +4 -0
  57. data/lib/action_dispatch/railtie.rb +6 -2
  58. data/lib/action_dispatch/routing.rb +18 -18
  59. data/lib/action_dispatch/routing/mapper.rb +26 -11
  60. data/lib/action_dispatch/routing/route_set.rb +13 -15
  61. data/lib/action_dispatch/system_test_case.rb +43 -5
  62. data/lib/action_dispatch/system_testing/browser.rb +38 -7
  63. data/lib/action_dispatch/system_testing/driver.rb +10 -1
  64. data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +3 -2
  65. data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +7 -6
  66. data/lib/action_dispatch/testing/assertions.rb +1 -1
  67. data/lib/action_dispatch/testing/assertions/routing.rb +8 -1
  68. data/lib/action_dispatch/testing/integration.rb +2 -2
  69. data/lib/action_dispatch/testing/request_encoder.rb +2 -2
  70. data/lib/action_dispatch/testing/test_response.rb +1 -1
  71. data/lib/action_pack/gem_version.rb +2 -2
  72. metadata +20 -15
  73. data/lib/action_dispatch/system_testing/test_helpers/undef_methods.rb +0 -26
@@ -117,6 +117,10 @@
117
117
  background-color: #FFCCCC;
118
118
  }
119
119
 
120
+ .button_to {
121
+ display: inline-block;
122
+ }
123
+
120
124
  .hidden {
121
125
  display: none;
122
126
  }
@@ -23,6 +23,7 @@ module ActionDispatch
23
23
  config.action_dispatch.use_authenticated_cookie_encryption = false
24
24
  config.action_dispatch.use_cookies_with_metadata = false
25
25
  config.action_dispatch.perform_deep_munge = true
26
+ config.action_dispatch.return_only_media_type_on_content_type = true
26
27
 
27
28
  config.action_dispatch.default_headers = {
28
29
  "X-Frame-Options" => "SAMEORIGIN",
@@ -41,8 +42,11 @@ module ActionDispatch
41
42
  ActionDispatch::Http::URL.tld_length = app.config.action_dispatch.tld_length
42
43
  ActionDispatch::Request.ignore_accept_header = app.config.action_dispatch.ignore_accept_header
43
44
  ActionDispatch::Request::Utils.perform_deep_munge = app.config.action_dispatch.perform_deep_munge
44
- ActionDispatch::Response.default_charset = app.config.action_dispatch.default_charset || app.config.encoding
45
- ActionDispatch::Response.default_headers = app.config.action_dispatch.default_headers
45
+ ActiveSupport.on_load(:action_dispatch_response) do
46
+ self.default_charset = app.config.action_dispatch.default_charset || app.config.encoding
47
+ self.default_headers = app.config.action_dispatch.default_headers
48
+ self.return_only_media_type_on_content_type = app.config.action_dispatch.return_only_media_type_on_content_type
49
+ end
46
50
 
47
51
  ActionDispatch::ExceptionWrapper.rescue_responses.merge!(config.action_dispatch.rescue_responses)
48
52
  ActionDispatch::ExceptionWrapper.rescue_templates.merge!(config.action_dispatch.rescue_templates)
@@ -74,8 +74,8 @@ module ActionDispatch
74
74
  # For routes that don't fit the <tt>resources</tt> mold, you can use the HTTP helper
75
75
  # methods <tt>get</tt>, <tt>post</tt>, <tt>patch</tt>, <tt>put</tt> and <tt>delete</tt>.
76
76
  #
77
- # get 'post/:id' => 'posts#show'
78
- # post 'post/:id' => 'posts#create_comment'
77
+ # get 'post/:id', to: 'posts#show'
78
+ # post 'post/:id', to: 'posts#create_comment'
79
79
  #
80
80
  # Now, if you POST to <tt>/posts/:id</tt>, it will route to the <tt>create_comment</tt> action. A GET on the same
81
81
  # URL will route to the <tt>show</tt> action.
@@ -83,7 +83,7 @@ module ActionDispatch
83
83
  # If your route needs to respond to more than one HTTP method (or all methods) then using the
84
84
  # <tt>:via</tt> option on <tt>match</tt> is preferable.
85
85
  #
86
- # match 'post/:id' => 'posts#show', via: [:get, :post]
86
+ # match 'post/:id', to: 'posts#show', via: [:get, :post]
87
87
  #
88
88
  # == Named routes
89
89
  #
@@ -94,7 +94,7 @@ module ActionDispatch
94
94
  # Example:
95
95
  #
96
96
  # # In config/routes.rb
97
- # get '/login' => 'accounts#login', as: 'login'
97
+ # get '/login', to: 'accounts#login', as: 'login'
98
98
  #
99
99
  # # With render, redirect_to, tests, etc.
100
100
  # redirect_to login_url
@@ -120,9 +120,9 @@ module ActionDispatch
120
120
  #
121
121
  # # In config/routes.rb
122
122
  # controller :blog do
123
- # get 'blog/show' => :list
124
- # get 'blog/delete' => :delete
125
- # get 'blog/edit' => :edit
123
+ # get 'blog/show', to: :list
124
+ # get 'blog/delete', to: :delete
125
+ # get 'blog/edit', to: :edit
126
126
  # end
127
127
  #
128
128
  # # provides named routes for show, delete, and edit
@@ -132,7 +132,7 @@ module ActionDispatch
132
132
  #
133
133
  # Routes can generate pretty URLs. For example:
134
134
  #
135
- # get '/articles/:year/:month/:day' => 'articles#find_by_id', constraints: {
135
+ # get '/articles/:year/:month/:day', to: 'articles#find_by_id', constraints: {
136
136
  # year: /\d{4}/,
137
137
  # month: /\d{1,2}/,
138
138
  # day: /\d{1,2}/
@@ -147,7 +147,7 @@ module ActionDispatch
147
147
  # You can specify a regular expression to define a format for a parameter.
148
148
  #
149
149
  # controller 'geocode' do
150
- # get 'geocode/:postalcode' => :show, constraints: {
150
+ # get 'geocode/:postalcode', to: :show, constraints: {
151
151
  # postalcode: /\d{5}(-\d{4})?/
152
152
  # }
153
153
  # end
@@ -156,13 +156,13 @@ module ActionDispatch
156
156
  # expression modifiers:
157
157
  #
158
158
  # controller 'geocode' do
159
- # get 'geocode/:postalcode' => :show, constraints: {
159
+ # get 'geocode/:postalcode', to: :show, constraints: {
160
160
  # postalcode: /hx\d\d\s\d[a-z]{2}/i
161
161
  # }
162
162
  # end
163
163
  #
164
164
  # controller 'geocode' do
165
- # get 'geocode/:postalcode' => :show, constraints: {
165
+ # get 'geocode/:postalcode', to: :show, constraints: {
166
166
  # postalcode: /# Postalcode format
167
167
  # \d{5} #Prefix
168
168
  # (-\d{4})? #Suffix
@@ -178,13 +178,13 @@ module ActionDispatch
178
178
  #
179
179
  # You can redirect any path to another path using the redirect helper in your router:
180
180
  #
181
- # get "/stories" => redirect("/posts")
181
+ # get "/stories", to: redirect("/posts")
182
182
  #
183
183
  # == Unicode character routes
184
184
  #
185
185
  # You can specify unicode character routes in your router:
186
186
  #
187
- # get "こんにちは" => "welcome#index"
187
+ # get "こんにちは", to: "welcome#index"
188
188
  #
189
189
  # == Routing to Rack Applications
190
190
  #
@@ -192,7 +192,7 @@ module ActionDispatch
192
192
  # index action in the PostsController, you can specify any Rack application
193
193
  # as the endpoint for a matcher:
194
194
  #
195
- # get "/application.js" => Sprockets
195
+ # get "/application.js", to: Sprockets
196
196
  #
197
197
  # == Reloading routes
198
198
  #
@@ -210,8 +210,8 @@ module ActionDispatch
210
210
  # === +assert_routing+
211
211
  #
212
212
  # def test_movie_route_properly_splits
213
- # opts = {controller: "plugin", action: "checkout", id: "2"}
214
- # assert_routing "plugin/checkout/2", opts
213
+ # opts = {controller: "plugin", action: "checkout", id: "2"}
214
+ # assert_routing "plugin/checkout/2", opts
215
215
  # end
216
216
  #
217
217
  # +assert_routing+ lets you test whether or not the route properly resolves into options.
@@ -219,8 +219,8 @@ module ActionDispatch
219
219
  # === +assert_recognizes+
220
220
  #
221
221
  # def test_route_has_options
222
- # opts = {controller: "plugin", action: "show", id: "12"}
223
- # assert_recognizes opts, "/plugins/show/12"
222
+ # opts = {controller: "plugin", action: "show", id: "12"}
223
+ # assert_recognizes opts, "/plugins/show/12"
224
224
  # end
225
225
  #
226
226
  # Note the subtle difference between the two: +assert_routing+ tests that
@@ -70,17 +70,17 @@ module ActionDispatch
70
70
  ANCHOR_CHARACTERS_REGEX = %r{\A(\\A|\^)|(\\Z|\\z|\$)\Z}
71
71
  OPTIONAL_FORMAT_REGEX = %r{(?:\(\.:format\)+|\.:format|/)\Z}
72
72
 
73
- attr_reader :requirements, :defaults
74
- attr_reader :to, :default_controller, :default_action
75
- attr_reader :required_defaults, :ast
73
+ attr_reader :requirements, :defaults, :to, :default_controller,
74
+ :default_action, :required_defaults, :ast, :scope_options
76
75
 
77
76
  def self.build(scope, set, ast, controller, default_action, to, via, formatted, options_constraints, anchor, options)
78
77
  options = scope[:options].merge(options) if scope[:options]
79
78
 
80
79
  defaults = (scope[:defaults] || {}).dup
81
80
  scope_constraints = scope[:constraints] || {}
81
+ scope_options = scope[:options] || {}
82
82
 
83
- new set, ast, defaults, controller, default_action, scope[:module], to, formatted, scope_constraints, scope[:blocks] || [], via, options_constraints, anchor, options
83
+ new set, ast, defaults, controller, default_action, scope[:module], to, formatted, scope_constraints, scope_options, scope[:blocks] || [], via, options_constraints, anchor, options
84
84
  end
85
85
 
86
86
  def self.check_via(via)
@@ -111,17 +111,18 @@ module ActionDispatch
111
111
  format != false && path !~ OPTIONAL_FORMAT_REGEX
112
112
  end
113
113
 
114
- def initialize(set, ast, defaults, controller, default_action, modyoule, to, formatted, scope_constraints, blocks, via, options_constraints, anchor, options)
114
+ def initialize(set, ast, defaults, controller, default_action, modyoule, to, formatted, scope_constraints, scope_options, blocks, via, options_constraints, anchor, options)
115
115
  @defaults = defaults
116
116
  @set = set
117
117
 
118
- @to = to
119
- @default_controller = controller
120
- @default_action = default_action
118
+ @to = intern(to)
119
+ @default_controller = intern(controller)
120
+ @default_action = intern(default_action)
121
121
  @ast = ast
122
122
  @anchor = anchor
123
123
  @via = via
124
124
  @internal = options.delete(:internal)
125
+ @scope_options = scope_options
125
126
 
126
127
  path_params = ast.find_all(&:symbol?).map(&:to_sym)
127
128
 
@@ -161,7 +162,7 @@ module ActionDispatch
161
162
 
162
163
  def make_route(name, precedence)
163
164
  Journey::Route.new(name, application, path, conditions, required_defaults,
164
- defaults, request_method, precedence, @internal)
165
+ defaults, request_method, precedence, scope_options, @internal)
165
166
  end
166
167
 
167
168
  def application
@@ -222,6 +223,10 @@ module ActionDispatch
222
223
  private :build_path
223
224
 
224
225
  private
226
+ def intern(object)
227
+ object.is_a?(String) ? -object : object
228
+ end
229
+
225
230
  def add_wildcard_options(options, formatted, path_ast)
226
231
  # Add a constraint for wildcard route to make it non-greedy and match the
227
232
  # optional format part of the route by default.
@@ -1141,6 +1146,10 @@ module ActionDispatch
1141
1146
  attr_reader :controller, :path, :param
1142
1147
 
1143
1148
  def initialize(entities, api_only, shallow, options = {})
1149
+ if options[:param].to_s.include?(":")
1150
+ raise ArgumentError, ":param option can't contain colons"
1151
+ end
1152
+
1144
1153
  @name = entities.to_s
1145
1154
  @path = (options[:path] || @name).to_s
1146
1155
  @controller = (options[:controller] || @name).to_s
@@ -1398,6 +1407,8 @@ module ActionDispatch
1398
1407
  # as a comment on a blog post like <tt>/posts/a-long-permalink/comments/1234</tt>
1399
1408
  # to be shortened to just <tt>/comments/1234</tt>.
1400
1409
  #
1410
+ # Set <tt>shallow: false</tt> on a child resource to ignore a parent's shallow parameter.
1411
+ #
1401
1412
  # [:shallow_path]
1402
1413
  # Prefixes nested shallow routes with the specified path.
1403
1414
  #
@@ -1440,6 +1451,9 @@ module ActionDispatch
1440
1451
  # Allows you to specify the default value for optional +format+
1441
1452
  # segment or disable it by supplying +false+.
1442
1453
  #
1454
+ # [:param]
1455
+ # Allows you to override the default param name of +:id+ in the URL.
1456
+ #
1443
1457
  # === Examples
1444
1458
  #
1445
1459
  # # routes call <tt>Admin::PostsController</tt>
@@ -1665,7 +1679,8 @@ module ActionDispatch
1665
1679
  return true
1666
1680
  end
1667
1681
 
1668
- if options.delete(:shallow)
1682
+ if options[:shallow]
1683
+ options.delete(:shallow)
1669
1684
  shallow do
1670
1685
  send(method, resources.pop, options, &block)
1671
1686
  end
@@ -2059,7 +2074,7 @@ module ActionDispatch
2059
2074
  # of routing helpers, e.g:
2060
2075
  #
2061
2076
  # direct :homepage do
2062
- # "http://www.rubyonrails.org"
2077
+ # "https://rubyonrails.org"
2063
2078
  # end
2064
2079
  #
2065
2080
  # direct :commentable do |model|
@@ -317,23 +317,21 @@ module ActionDispatch
317
317
  #
318
318
  def define_url_helper(mod, route, name, opts, route_key, url_strategy)
319
319
  helper = UrlHelper.create(route, opts, route_key, url_strategy)
320
- mod.module_eval do
321
- define_method(name) do |*args|
322
- last = args.last
323
- options = \
324
- case last
325
- when Hash
326
- args.pop
327
- when ActionController::Parameters
328
- args.pop.to_h
329
- end
330
- helper.call self, args, options
331
- end
320
+ mod.define_method(name) do |*args|
321
+ last = args.last
322
+ options = \
323
+ case last
324
+ when Hash
325
+ args.pop
326
+ when ActionController::Parameters
327
+ args.pop.to_h
328
+ end
329
+ helper.call self, args, options
332
330
  end
333
331
  end
334
332
  end
335
333
 
336
- # strategy for building urls to send to the client
334
+ # strategy for building URLs to send to the client
337
335
  PATH = ->(options) { ActionDispatch::Http::URL.path_for(options) }
338
336
  UNKNOWN = ->(options) { ActionDispatch::Http::URL.url_for(options) }
339
337
 
@@ -593,14 +591,14 @@ module ActionDispatch
593
591
  if route.segment_keys.include?(:controller)
594
592
  ActiveSupport::Deprecation.warn(<<-MSG.squish)
595
593
  Using a dynamic :controller segment in a route is deprecated and
596
- will be removed in Rails 6.0.
594
+ will be removed in Rails 6.1.
597
595
  MSG
598
596
  end
599
597
 
600
598
  if route.segment_keys.include?(:action)
601
599
  ActiveSupport::Deprecation.warn(<<-MSG.squish)
602
600
  Using a dynamic :action segment in a route is deprecated and
603
- will be removed in Rails 6.0.
601
+ will be removed in Rails 6.1.
604
602
  MSG
605
603
  end
606
604
 
@@ -4,13 +4,13 @@ gem "capybara", ">= 2.15"
4
4
 
5
5
  require "capybara/dsl"
6
6
  require "capybara/minitest"
7
+ require "selenium/webdriver"
7
8
  require "action_controller"
8
9
  require "action_dispatch/system_testing/driver"
9
10
  require "action_dispatch/system_testing/browser"
10
11
  require "action_dispatch/system_testing/server"
11
12
  require "action_dispatch/system_testing/test_helpers/screenshot_helper"
12
13
  require "action_dispatch/system_testing/test_helpers/setup_and_teardown"
13
- require "action_dispatch/system_testing/test_helpers/undef_methods"
14
14
 
15
15
  module ActionDispatch
16
16
  # = System Testing
@@ -89,19 +89,47 @@ module ActionDispatch
89
89
  # { js_errors: true }
90
90
  # end
91
91
  #
92
+ # Some drivers require browser capabilities to be passed as a block instead
93
+ # of through the +options+ hash.
94
+ #
95
+ # As an example, if you want to add mobile emulation on chrome, you'll have to
96
+ # create an instance of selenium's +Chrome::Options+ object and add
97
+ # capabilities with a block.
98
+ #
99
+ # The block will be passed an instance of <tt><Driver>::Options</tt> where you can
100
+ # define the capabilities you want. Please refer to your driver documentation
101
+ # to learn about supported options.
102
+ #
103
+ # class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
104
+ # driven_by :selenium, using: :chrome, screen_size: [1024, 768] do |driver_option|
105
+ # driver_option.add_emulation(device_name: 'iPhone 6')
106
+ # driver_option.add_extension('path/to/chrome_extension.crx')
107
+ # end
108
+ # end
109
+ #
92
110
  # Because <tt>ActionDispatch::SystemTestCase</tt> is a shim between Capybara
93
111
  # and Rails, any driver that is supported by Capybara is supported by system
94
112
  # tests as long as you include the required gems and files.
95
- class SystemTestCase < IntegrationTest
113
+ class SystemTestCase < ActiveSupport::TestCase
96
114
  include Capybara::DSL
97
115
  include Capybara::Minitest::Assertions
98
116
  include SystemTesting::TestHelpers::SetupAndTeardown
99
117
  include SystemTesting::TestHelpers::ScreenshotHelper
100
- include SystemTesting::TestHelpers::UndefMethods
101
118
 
102
119
  def initialize(*) # :nodoc:
103
120
  super
104
121
  self.class.driver.use
122
+ @proxy_route = if ActionDispatch.test_app
123
+ Class.new do
124
+ include ActionDispatch.test_app.routes.url_helpers
125
+
126
+ def url_options
127
+ default_url_options.merge(host: Capybara.app_host)
128
+ end
129
+ end.new
130
+ else
131
+ nil
132
+ end
105
133
  end
106
134
 
107
135
  def self.start_application # :nodoc:
@@ -134,12 +162,22 @@ module ActionDispatch
134
162
  # driven_by :selenium, using: :firefox
135
163
  #
136
164
  # driven_by :selenium, using: :headless_firefox
137
- def self.driven_by(driver, using: :chrome, screen_size: [1400, 1400], options: {})
138
- self.driver = SystemTesting::Driver.new(driver, using: using, screen_size: screen_size, options: options)
165
+ def self.driven_by(driver, using: :chrome, screen_size: [1400, 1400], options: {}, &capabilities)
166
+ driver_options = { using: using, screen_size: screen_size, options: options }
167
+
168
+ self.driver = SystemTesting::Driver.new(driver, driver_options, &capabilities)
139
169
  end
140
170
 
141
171
  driven_by :selenium
142
172
 
173
+ def method_missing(method, *args, &block)
174
+ if @proxy_route.respond_to?(method)
175
+ @proxy_route.send(method, *args, &block)
176
+ else
177
+ super
178
+ end
179
+ end
180
+
143
181
  ActiveSupport.run_load_hooks(:action_dispatch_system_test_case, self)
144
182
  end
145
183
 
@@ -29,20 +29,51 @@ module ActionDispatch
29
29
  end
30
30
  end
31
31
 
32
+ def capabilities
33
+ @option ||=
34
+ case type
35
+ when :chrome
36
+ ::Selenium::WebDriver::Chrome::Options.new
37
+ when :firefox
38
+ ::Selenium::WebDriver::Firefox::Options.new
39
+ end
40
+ end
41
+
42
+ # driver_path can be configured as a proc. The webdrivers gem uses this
43
+ # proc to update web drivers. Running this proc early allows us to only
44
+ # update the webdriver once and avoid race conditions when using
45
+ # parallel tests.
46
+ def preload
47
+ case type
48
+ when :chrome
49
+ if ::Selenium::WebDriver::Service.respond_to? :driver_path=
50
+ ::Selenium::WebDriver::Chrome::Service.driver_path.try(:call)
51
+ else
52
+ # Selenium <= v3.141.0
53
+ ::Selenium::WebDriver::Chrome.driver_path
54
+ end
55
+ when :firefox
56
+ if ::Selenium::WebDriver::Service.respond_to? :driver_path=
57
+ ::Selenium::WebDriver::Firefox::Service.driver_path.try(:call)
58
+ else
59
+ # Selenium <= v3.141.0
60
+ ::Selenium::WebDriver::Firefox.driver_path
61
+ end
62
+ end
63
+ end
64
+
32
65
  private
33
66
  def headless_chrome_browser_options
34
- options = Selenium::WebDriver::Chrome::Options.new
35
- options.args << "--headless"
36
- options.args << "--disable-gpu" if Gem.win_platform?
67
+ capabilities.args << "--headless"
68
+ capabilities.args << "--disable-gpu" if Gem.win_platform?
37
69
 
38
- options
70
+ capabilities
39
71
  end
40
72
 
41
73
  def headless_firefox_browser_options
42
- options = Selenium::WebDriver::Firefox::Options.new
43
- options.args << "-headless"
74
+ capabilities.args << "-headless"
44
75
 
45
- options
76
+ capabilities
46
77
  end
47
78
  end
48
79
  end