diff options
author | eileencodes <eileencodes@gmail.com> | 2016-08-05 10:17:22 -0400 |
---|---|---|
committer | eileencodes <eileencodes@gmail.com> | 2017-02-20 15:07:31 -0500 |
commit | 0862cf1bbffe0a3c82e311804244a8cb715332a6 (patch) | |
tree | 5466f4a87898649384c9e398ed5ad29c41064402 /actionpack/lib | |
parent | 97d8b7abfe75b6a7617966ad0b3d37ae9fc7adb8 (diff) | |
download | rails-0862cf1bbffe0a3c82e311804244a8cb715332a6.tar.gz rails-0862cf1bbffe0a3c82e311804244a8cb715332a6.tar.bz2 rails-0862cf1bbffe0a3c82e311804244a8cb715332a6.zip |
Add ability to run system tests via Capybara
Capybara defaults to Rack Test for it's driver and works out of the box
but this adds the headers and allows for future configurable adapters
for system testing.
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/system_test_case.rb | 3 | ||||
-rw-r--r-- | actionpack/lib/system_testing/base.rb | 9 | ||||
-rw-r--r-- | actionpack/lib/system_testing/driver_adapter.rb | 18 | ||||
-rw-r--r-- | actionpack/lib/system_testing/driver_adapters.rb | 13 | ||||
-rw-r--r-- | actionpack/lib/system_testing/driver_adapters/capybara_rack_test_driver.rb | 24 | ||||
-rw-r--r-- | actionpack/lib/system_testing/test_helper.rb | 12 |
6 files changed, 79 insertions, 0 deletions
diff --git a/actionpack/lib/system_test_case.rb b/actionpack/lib/system_test_case.rb index fdaae3ff40..4265798073 100644 --- a/actionpack/lib/system_test_case.rb +++ b/actionpack/lib/system_test_case.rb @@ -1,5 +1,8 @@ +require 'system_testing/base' + module Rails class SystemTestCase < ActiveSupport::TestCase include Rails.application.routes.url_helpers + include SystemTesting::Base end end diff --git a/actionpack/lib/system_testing/base.rb b/actionpack/lib/system_testing/base.rb new file mode 100644 index 0000000000..ae4236f97d --- /dev/null +++ b/actionpack/lib/system_testing/base.rb @@ -0,0 +1,9 @@ +require 'system_testing/test_helper' +require 'system_testing/driver_adapter' + +module SystemTesting + module Base + include TestHelper + include DriverAdapter + end +end diff --git a/actionpack/lib/system_testing/driver_adapter.rb b/actionpack/lib/system_testing/driver_adapter.rb new file mode 100644 index 0000000000..70c4396323 --- /dev/null +++ b/actionpack/lib/system_testing/driver_adapter.rb @@ -0,0 +1,18 @@ +require 'system_testing/driver_adapters' + +module SystemTesting + module DriverAdapter + extend ActiveSupport::Concern + + included do + self.driver_adapter = :capybara_rack_test_driver + end + + module ClassMethods + def driver_adapter=(driver_name_or_class) + driver = DriverAdapters.lookup(driver_name_or_class).new + driver.call + end + end + end +end diff --git a/actionpack/lib/system_testing/driver_adapters.rb b/actionpack/lib/system_testing/driver_adapters.rb new file mode 100644 index 0000000000..38e2bdddcc --- /dev/null +++ b/actionpack/lib/system_testing/driver_adapters.rb @@ -0,0 +1,13 @@ +module SystemTesting + module DriverAdapters + extend ActiveSupport::Autoload + + autoload :CapybaraRackTestDriver + + class << self + def lookup(name) + const_get(name.to_s.camelize) + end + end + end +end diff --git a/actionpack/lib/system_testing/driver_adapters/capybara_rack_test_driver.rb b/actionpack/lib/system_testing/driver_adapters/capybara_rack_test_driver.rb new file mode 100644 index 0000000000..2890686e29 --- /dev/null +++ b/actionpack/lib/system_testing/driver_adapters/capybara_rack_test_driver.rb @@ -0,0 +1,24 @@ +module SystemTesting + module DriverAdapters + class CapybaraRackTestDriver + attr_reader :useragent + + def initialize(useragent: 'Capybara') + @useragent = useragent + end + + def call + registration + end + + private + def registration + Capybara.register_driver :rack_test do |app| + Capybara::RackTest::Driver.new(app, headers: { + 'HTTP_USER_AGENT' => @useragent + }) + end + end + end + end +end diff --git a/actionpack/lib/system_testing/test_helper.rb b/actionpack/lib/system_testing/test_helper.rb new file mode 100644 index 0000000000..68b187ed7a --- /dev/null +++ b/actionpack/lib/system_testing/test_helper.rb @@ -0,0 +1,12 @@ +require 'capybara/rails' + +module SystemTesting + module TestHelper + include Capybara::DSL + + def after_teardown + Capybara.reset_sessions! + super + end + end +end |