aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2019-07-24 22:19:21 -0400
committerGitHub <noreply@github.com>2019-07-24 22:19:21 -0400
commitd415eb4f6d6bb24b78b968ae28c22bb7e1721285 (patch)
tree5d6d7bdce42c1cf8389b506c50880dc1f3f4a9ad /actionpack
parent49b531ba588eb8da50ee810b377a461dc9aee618 (diff)
downloadrails-d415eb4f6d6bb24b78b968ae28c22bb7e1721285.tar.gz
rails-d415eb4f6d6bb24b78b968ae28c22bb7e1721285.tar.bz2
rails-d415eb4f6d6bb24b78b968ae28c22bb7e1721285.zip
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.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG.md4
-rw-r--r--actionpack/lib/action_dispatch/system_test_case.rb48
-rw-r--r--actionpack/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb11
-rw-r--r--actionpack/test/dispatch/system_testing/system_test_case_test.rb8
4 files changed, 38 insertions, 33 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index 9a6bd4bb45..99a4ac6845 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,3 +1,7 @@
+* System tests require Capybara 3.26 or newer.
+
+ *George Claghorn*
+
* Reduced log noise handling ActionController::RoutingErrors.
*Alberto Fernández-Capel*
diff --git a/actionpack/lib/action_dispatch/system_test_case.rb b/actionpack/lib/action_dispatch/system_test_case.rb
index 4fda2cf44f..aae96975c7 100644
--- a/actionpack/lib/action_dispatch/system_test_case.rb
+++ b/actionpack/lib/action_dispatch/system_test_case.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-gem "capybara", ">= 2.15"
+gem "capybara", ">= 3.26"
require "capybara/dsl"
require "capybara/minitest"
@@ -119,17 +119,6 @@ module ActionDispatch
def initialize(*) # :nodoc:
super
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
def self.start_application # :nodoc:
@@ -170,16 +159,33 @@ module ActionDispatch
driven_by :selenium
- def method_missing(method, *args, &block)
- if @proxy_route.respond_to?(method)
- @proxy_route.send(method, *args, &block)
- else
- super
+ private
+ def url_helpers
+ @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
- end
- ActiveSupport.run_load_hooks(:action_dispatch_system_test_case, self)
- end
+ def method_missing(name, *args, &block)
+ if url_helpers.respond_to?(name)
+ url_helpers.public_send(name, *args, &block)
+ else
+ super
+ end
+ end
- SystemTestCase.start_application
+ def respond_to_missing?(name, include_private = false)
+ url_helpers.respond_to?(name)
+ end
+ end
end
+
+ActiveSupport.run_load_hooks :action_dispatch_system_test_case, ActionDispatch::SystemTestCase
+ActionDispatch::SystemTestCase.start_application
diff --git a/actionpack/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb b/actionpack/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb
index 20f6a7634f..30dc21ebb9 100644
--- a/actionpack/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb
+++ b/actionpack/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb
@@ -4,15 +4,12 @@ module ActionDispatch
module SystemTesting
module TestHelpers
module SetupAndTeardown # :nodoc:
- DEFAULT_HOST = "http://127.0.0.1"
-
def host!(host)
- Capybara.app_host = host
- end
+ ActiveSupport::Deprecation.warn \
+ "ActionDispatch::SystemTestCase#host! is deprecated with no replacement. " \
+ "Set Capybara.app_host directly or rely on Capybara's default host."
- def before_setup
- host! DEFAULT_HOST
- super
+ Capybara.app_host = host
end
def before_teardown
diff --git a/actionpack/test/dispatch/system_testing/system_test_case_test.rb b/actionpack/test/dispatch/system_testing/system_test_case_test.rb
index 3319db1665..d235f7ad89 100644
--- a/actionpack/test/dispatch/system_testing/system_test_case_test.rb
+++ b/actionpack/test/dispatch/system_testing/system_test_case_test.rb
@@ -36,12 +36,10 @@ class SetDriverToSeleniumHeadlessFirefoxTest < DrivenBySeleniumWithHeadlessFiref
end
class SetHostTest < DrivenByRackTest
- test "sets default host" do
- assert_equal "http://127.0.0.1", Capybara.app_host
- end
-
test "overrides host" do
- host! "http://example.com"
+ assert_deprecated do
+ host! "http://example.com"
+ end
assert_equal "http://example.com", Capybara.app_host
end