Stop setting a default Capybara app host

It's intended not to be set if Capybara starts the app server itself. Base Rails-generated URLs off of Capybara.current_session.server_url instead.
This commit is contained in:
George Claghorn 2019-07-24 22:19:21 -04:00 committed by GitHub
parent 49b531ba58
commit d415eb4f6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 38 deletions

View File

@ -9,7 +9,7 @@ gemspec
# We need a newish Rake since Active Job sets its test tasks' descriptions. # We need a newish Rake since Active Job sets its test tasks' descriptions.
gem "rake", ">= 11.1" gem "rake", ">= 11.1"
gem "capybara", ">= 2.15" gem "capybara", ">= 3.26"
gem "selenium-webdriver", ">= 3.141.592" gem "selenium-webdriver", ">= 3.141.592"
gem "rack-cache", "~> 1.2" gem "rack-cache", "~> 1.2"

View File

@ -175,13 +175,13 @@ GEM
bunny (2.13.0) bunny (2.13.0)
amq-protocol (~> 2.3, >= 2.3.0) amq-protocol (~> 2.3, >= 2.3.0)
byebug (10.0.2) byebug (10.0.2)
capybara (3.10.1) capybara (3.26.0)
addressable addressable
mini_mime (>= 0.1.3) mini_mime (>= 0.1.3)
nokogiri (~> 1.8) nokogiri (~> 1.8)
rack (>= 1.6.0) rack (>= 1.6.0)
rack-test (>= 0.6.3) rack-test (>= 0.6.3)
regexp_parser (~> 1.2) regexp_parser (~> 1.5)
xpath (~> 3.2) xpath (~> 3.2)
childprocess (1.0.1) childprocess (1.0.1)
rake (< 13.0) rake (< 13.0)
@ -388,7 +388,7 @@ GEM
redis (4.1.1) redis (4.1.1)
redis-namespace (1.6.0) redis-namespace (1.6.0)
redis (>= 3.0.4) redis (>= 3.0.4)
regexp_parser (1.3.0) regexp_parser (1.6.0)
representable (3.0.4) representable (3.0.4)
declarative (< 0.1.0) declarative (< 0.1.0)
declarative-option (< 0.2.0) declarative-option (< 0.2.0)
@ -545,7 +545,7 @@ DEPENDENCIES
blade-sauce_labs_plugin blade-sauce_labs_plugin
bootsnap (>= 1.4.4) bootsnap (>= 1.4.4)
byebug byebug
capybara (>= 2.15) capybara (>= 3.26)
connection_pool connection_pool
dalli dalli
delayed_job delayed_job

View File

@ -1,3 +1,7 @@
* System tests require Capybara 3.26 or newer.
*George Claghorn*
* Reduced log noise handling ActionController::RoutingErrors. * Reduced log noise handling ActionController::RoutingErrors.
*Alberto Fernández-Capel* *Alberto Fernández-Capel*

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
gem "capybara", ">= 2.15" gem "capybara", ">= 3.26"
require "capybara/dsl" require "capybara/dsl"
require "capybara/minitest" require "capybara/minitest"
@ -119,17 +119,6 @@ module ActionDispatch
def initialize(*) # :nodoc: def initialize(*) # :nodoc:
super super
self.class.driver.use self.class.driver.use
@proxy_route = if ActionDispatch.test_app
Class.new do
include ActionDispatch.test_app.routes.url_helpers
def url_options
default_url_options.merge(host: Capybara.app_host)
end
end.new
else
nil
end
end end
def self.start_application # :nodoc: def self.start_application # :nodoc:
@ -170,16 +159,33 @@ module ActionDispatch
driven_by :selenium driven_by :selenium
def method_missing(method, *args, &block) private
if @proxy_route.respond_to?(method) def url_helpers
@proxy_route.send(method, *args, &block) @url_helpers ||=
if ActionDispatch.test_app
Class.new do
include ActionDispatch.test_app.routes.url_helpers
def url_options
default_url_options.reverse_merge(host: Capybara.app_host || Capybara.current_session.server_url)
end
end.new
end
end
def method_missing(name, *args, &block)
if url_helpers.respond_to?(name)
url_helpers.public_send(name, *args, &block)
else else
super super
end end
end end
ActiveSupport.run_load_hooks(:action_dispatch_system_test_case, self) def respond_to_missing?(name, include_private = false)
url_helpers.respond_to?(name)
end
end
end end
SystemTestCase.start_application ActiveSupport.run_load_hooks :action_dispatch_system_test_case, ActionDispatch::SystemTestCase
end ActionDispatch::SystemTestCase.start_application

View File

@ -4,15 +4,12 @@ module ActionDispatch
module SystemTesting module SystemTesting
module TestHelpers module TestHelpers
module SetupAndTeardown # :nodoc: module SetupAndTeardown # :nodoc:
DEFAULT_HOST = "http://127.0.0.1"
def host!(host) def host!(host)
Capybara.app_host = host ActiveSupport::Deprecation.warn \
end "ActionDispatch::SystemTestCase#host! is deprecated with no replacement. " \
"Set Capybara.app_host directly or rely on Capybara's default host."
def before_setup Capybara.app_host = host
host! DEFAULT_HOST
super
end end
def before_teardown def before_teardown

View File

@ -36,12 +36,10 @@ class SetDriverToSeleniumHeadlessFirefoxTest < DrivenBySeleniumWithHeadlessFiref
end end
class SetHostTest < DrivenByRackTest class SetHostTest < DrivenByRackTest
test "sets default host" do
assert_equal "http://127.0.0.1", Capybara.app_host
end
test "overrides host" do test "overrides host" do
assert_deprecated do
host! "http://example.com" host! "http://example.com"
end
assert_equal "http://example.com", Capybara.app_host assert_equal "http://example.com", Capybara.app_host
end end