Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
### Added

### Changed
- `driver.browser` is a plain `Ferrum::Browser`, whose `page` is the first window. `driver.current_page` is the window
Capybara switched to. Cuprite sets every page up through Ferrum's `on_page` [#399]
- `browser.go_to` no longer raises `PendingConnectionsError`, `visit` does, and `browser.resize` and
- Breaking: `driver.browser` is a plain `Ferrum::Browser`, whose `page` is the first window. `driver.current_page` is
the window Capybara switched to. Cuprite sets every page up through Ferrum's `on_page` [#399]
- Breaking: `browser.go_to` no longer raises `PendingConnectionsError`, `visit` does, and `browser.resize` and
`browser.set_viewport` don't keep `:mobile` and `:scale_factor` [#399]
- `url_blocklist=`, `url_allowlist=`, their aliases and `raise_on_unhandled_modal=` moved from `driver.browser` to
`driver` [#399]
- A browser that died is restarted by `reset!` before the next test, not by the command that found it dead, so the test
it died in fails with `Ferrum::DeadBrowserError` [#399]
- `UnhandledModalError` is raised from Capybara's calls (`visit`, finders, node actions, `evaluate_script`,
`execute_script`), Ferrum calls don't raise it [#399]
- Cuprite reaches Ferrum through its public API only, Ferrum's `new_window:`, `close_target` and `on_page` replace the
internals it patched or called [#397, #398, #399]

### Deprecated
- `url_blocklist=`, `url_allowlist=`, their aliases, their readers and `raise_on_unhandled_modal=` on `driver.browser`,
will be removed in 1.0. They moved to `driver` and warn on the browser [#399]

### Fixed

### Removed
Expand Down
20 changes: 20 additions & 0 deletions lib/capybara/cuprite/deprecation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Capybara
module Cuprite
# The release that removes what's deprecated now.
REMOVE_DEPRECATED_IN = "1.0"

# Warns that a method is deprecated, pointing at the code that called it.
#
# @api private
# @param method [String] the deprecated call, e.g. `"page.driver.browser.url_blocklist="`
# @param advice [String, nil] what to use instead
# @return [void]
def self.deprecation_warning(method, advice = nil)
message = "#{method} is deprecated and will be removed in #{REMOVE_DEPRECATED_IN}"
message += ", #{advice} instead" if advice
warn message, uplevel: 2
end
end
end
2 changes: 2 additions & 0 deletions lib/capybara/cuprite/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "forwardable"
require "rack"
require "capybara/cuprite/finder"
require "capybara/cuprite/driver/deprecations"
require "capybara/cuprite/driver/extensions"
require "capybara/cuprite/driver/settings"
require "capybara/cuprite/driver/window"
Expand Down Expand Up @@ -447,6 +448,7 @@ def start_browser
browser = Ferrum::Browser.new(options.except(*CUPRITE_OPTIONS))
@settings = Settings.new(options, browser.options.window_size)
browser.on_page { |page| prepare_page(page) }
Deprecations.extend_browser(browser, self)
browser
rescue StandardError
browser&.quit
Expand Down
36 changes: 36 additions & 0 deletions lib/capybara/cuprite/driver/deprecations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

require "capybara/cuprite/deprecation"

module Capybara
module Cuprite
class Driver < Capybara::Driver::Base
# The settings that moved from `page.driver.browser` to `page.driver`. They stay on the browser until 1.0 and
# forward to the driver with a warning.
# @api private
module Deprecations
# The settings the browser keeps until 1.0.
BROWSER_METHODS = %i[raise_on_unhandled_modal raise_on_unhandled_modal=
url_whitelist url_whitelist= url_allowlist url_allowlist=
url_blacklist url_blacklist= url_blocklist url_blocklist=].freeze

module_function

# Adds the moved settings to the browser, forwarding them to the driver with a warning. Only this browser
# object gets them, `Ferrum::Browser` stays as it is.
#
# @param browser [Ferrum::Browser]
# @param driver [Driver]
# @return [void]
def extend_browser(browser, driver)
BROWSER_METHODS.each do |name|
browser.define_singleton_method(name) do |*args|
Cuprite.deprecation_warning("page.driver.browser.#{name}", "use page.driver.#{name}")
driver.public_send(name, *args)
end
end
end
end
end
end
end
7 changes: 7 additions & 0 deletions sig/capybara/cuprite/deprecation.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Capybara
module Cuprite
REMOVE_DEPRECATED_IN: String

def self.deprecation_warning: (String method, ?String? advice) -> void
end
end
11 changes: 11 additions & 0 deletions sig/capybara/cuprite/driver/deprecations.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Capybara
module Cuprite
class Driver < Capybara::Driver::Base
module Deprecations
BROWSER_METHODS: Array[Symbol]

def self?.extend_browser: (Ferrum::Browser browser, Driver driver) -> void
end
end
end
end
33 changes: 33 additions & 0 deletions spec/driver/deprecations_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

describe Capybara::Cuprite::Driver::Deprecations do
around do |example|
@driver = Capybara::Cuprite::Driver.new(nil)
example.run
ensure
@driver.quit
end

describe ".extend_browser" do
def expect_deprecated(name, &)
message = "page.driver.browser.#{name} is deprecated and will be removed in 1.0, use page.driver.#{name} instead"
expect(&).to output(/#{Regexp.escape(message)}/).to_stderr
end

it "forwards url_blocklist= on the browser to the driver with a warning" do
expect_deprecated("url_blocklist=") { @driver.browser.url_blocklist = /unwanted/ }
expect(@driver.url_blocklist).to eq([/unwanted/])
end

it "forwards url_allowlist on the browser to the driver with a warning" do
@driver.url_allowlist = /wanted/

expect_deprecated("url_allowlist") { expect(@driver.browser.url_allowlist).to eq([/wanted/]) }
end

it "forwards raise_on_unhandled_modal= on the browser to the driver with a warning" do
expect_deprecated("raise_on_unhandled_modal=") { @driver.browser.raise_on_unhandled_modal = true }
expect(@driver.raise_on_unhandled_modal).to be(true)
end
end
end
Loading