aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2019-05-16 09:02:36 -0400
committerGitHub <noreply@github.com>2019-05-16 09:02:36 -0400
commitc8396e030f4b1edd48340975696dcaf6aa8291c9 (patch)
tree6246c1d3f8ac1c8212b613cc3ced8885c9fcc382 /actionpack
parent9c87d2316adf36cf33b1b7afe8d779bf420c52a7 (diff)
downloadrails-c8396e030f4b1edd48340975696dcaf6aa8291c9.tar.gz
rails-c8396e030f4b1edd48340975696dcaf6aa8291c9.tar.bz2
rails-c8396e030f4b1edd48340975696dcaf6aa8291c9.zip
Permit running jobs in system tests
Inherit from ActiveSupport::TestCase instead of ActionDispatch::IntegrationTest. Active Job automatically mixes its test helper into the latter, forcibly setting the test queue adapter before Capybara starts its app server. As a bonus, we no longer need to remove the parts of the ActionDispatch::IntegrationTest API we don’t want to expose.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/railtie.rb6
-rw-r--r--actionpack/lib/action_dispatch/system_test_case.rb8
-rw-r--r--actionpack/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb1
-rw-r--r--actionpack/lib/action_dispatch/system_testing/test_helpers/undef_methods.rb26
-rw-r--r--actionpack/test/dispatch/system_testing/system_test_case_test.rb37
5 files changed, 11 insertions, 67 deletions
diff --git a/actionpack/lib/action_dispatch/railtie.rb b/actionpack/lib/action_dispatch/railtie.rb
index efc3988bc3..5f711c7348 100644
--- a/actionpack/lib/action_dispatch/railtie.rb
+++ b/actionpack/lib/action_dispatch/railtie.rb
@@ -52,5 +52,11 @@ module ActionDispatch
ActionDispatch.test_app = app
end
+
+ initializer "action_dispatch.system_tests" do |app|
+ ActiveSupport.on_load(:action_dispatch_system_test_case) do
+ include app.routes.url_helpers
+ end
+ end
end
end
diff --git a/actionpack/lib/action_dispatch/system_test_case.rb b/actionpack/lib/action_dispatch/system_test_case.rb
index 066daa4a12..a7fb5fa330 100644
--- a/actionpack/lib/action_dispatch/system_test_case.rb
+++ b/actionpack/lib/action_dispatch/system_test_case.rb
@@ -10,7 +10,6 @@ require "action_dispatch/system_testing/browser"
require "action_dispatch/system_testing/server"
require "action_dispatch/system_testing/test_helpers/screenshot_helper"
require "action_dispatch/system_testing/test_helpers/setup_and_teardown"
-require "action_dispatch/system_testing/test_helpers/undef_methods"
module ActionDispatch
# = System Testing
@@ -110,12 +109,11 @@ module ActionDispatch
# Because <tt>ActionDispatch::SystemTestCase</tt> is a shim between Capybara
# and Rails, any driver that is supported by Capybara is supported by system
# tests as long as you include the required gems and files.
- class SystemTestCase < IntegrationTest
+ class SystemTestCase < ActiveSupport::TestCase
include Capybara::DSL
include Capybara::Minitest::Assertions
include SystemTesting::TestHelpers::SetupAndTeardown
include SystemTesting::TestHelpers::ScreenshotHelper
- include SystemTesting::TestHelpers::UndefMethods
def initialize(*) # :nodoc:
super
@@ -160,6 +158,10 @@ module ActionDispatch
driven_by :selenium
+ def url_options # :nodoc:
+ default_url_options.merge(host: Capybara.app_host)
+ end
+
ActiveSupport.run_load_hooks(:action_dispatch_system_test_case, self)
end
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 7080dbe022..20f6a7634f 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
@@ -7,7 +7,6 @@ module ActionDispatch
DEFAULT_HOST = "http://127.0.0.1"
def host!(host)
- super
Capybara.app_host = host
end
diff --git a/actionpack/lib/action_dispatch/system_testing/test_helpers/undef_methods.rb b/actionpack/lib/action_dispatch/system_testing/test_helpers/undef_methods.rb
deleted file mode 100644
index d64be3b3d9..0000000000
--- a/actionpack/lib/action_dispatch/system_testing/test_helpers/undef_methods.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-# frozen_string_literal: true
-
-module ActionDispatch
- module SystemTesting
- module TestHelpers
- module UndefMethods # :nodoc:
- extend ActiveSupport::Concern
- included do
- METHODS = %i(get post put patch delete).freeze
-
- METHODS.each do |verb|
- undef_method verb
- end
-
- def method_missing(method, *args, &block)
- if METHODS.include?(method)
- raise NoMethodError, "System tests cannot make direct requests via ##{method}; use #visit and #click_on instead. See http://www.rubydoc.info/github/teamcapybara/capybara/master#The_DSL for more information."
- else
- super
- end
- end
- end
- end
- end
- end
-end
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 847b09dcfe..3319db1665 100644
--- a/actionpack/test/dispatch/system_testing/system_test_case_test.rb
+++ b/actionpack/test/dispatch/system_testing/system_test_case_test.rb
@@ -46,40 +46,3 @@ class SetHostTest < DrivenByRackTest
assert_equal "http://example.com", Capybara.app_host
end
end
-
-class UndefMethodsTest < DrivenBySeleniumWithChrome
- test "get" do
- exception = assert_raise NoMethodError do
- get "http://example.com"
- end
- assert_equal "System tests cannot make direct requests via #get; use #visit and #click_on instead. See http://www.rubydoc.info/github/teamcapybara/capybara/master#The_DSL for more information.", exception.message
- end
-
- test "post" do
- exception = assert_raise NoMethodError do
- post "http://example.com"
- end
- assert_equal "System tests cannot make direct requests via #post; use #visit and #click_on instead. See http://www.rubydoc.info/github/teamcapybara/capybara/master#The_DSL for more information.", exception.message
- end
-
- test "put" do
- exception = assert_raise NoMethodError do
- put "http://example.com"
- end
- assert_equal "System tests cannot make direct requests via #put; use #visit and #click_on instead. See http://www.rubydoc.info/github/teamcapybara/capybara/master#The_DSL for more information.", exception.message
- end
-
- test "patch" do
- exception = assert_raise NoMethodError do
- patch "http://example.com"
- end
- assert_equal "System tests cannot make direct requests via #patch; use #visit and #click_on instead. See http://www.rubydoc.info/github/teamcapybara/capybara/master#The_DSL for more information.", exception.message
- end
-
- test "delete" do
- exception = assert_raise NoMethodError do
- delete "http://example.com"
- end
- assert_equal "System tests cannot make direct requests via #delete; use #visit and #click_on instead. See http://www.rubydoc.info/github/teamcapybara/capybara/master#The_DSL for more information.", exception.message
- end
-end