aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2016-11-06 18:55:15 -0500
committereileencodes <eileencodes@gmail.com>2017-02-20 15:07:33 -0500
commit5bf0aa6745db27c45c0778f9f6e9046f9ee9fb94 (patch)
tree7ba85a8ea15146725c68ce6b9e5a94ebac6d0c9c /actionpack/lib
parenta21e18d5080a2c4808330271885f5664a725d3f3 (diff)
downloadrails-5bf0aa6745db27c45c0778f9f6e9046f9ee9fb94.tar.gz
rails-5bf0aa6745db27c45c0778f9f6e9046f9ee9fb94.tar.bz2
rails-5bf0aa6745db27c45c0778f9f6e9046f9ee9fb94.zip
Turn system testing into it's own gem and rename
Renames `Rails::SystemTestCase` to `ActionSystemTest` and moves it to a gem under the Rails name. We need to name the class `ActionSystemTestCase` because the gem expects a module but tests themselves expect a class. Adds MIT-LICENSE, CHANGELOG, and README for the future.
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/system_test_case.rb57
-rw-r--r--actionpack/lib/system_testing/driver_adapter.rb31
-rw-r--r--actionpack/lib/system_testing/driver_adapters.rb46
-rw-r--r--actionpack/lib/system_testing/driver_adapters/capybara_driver.rb83
-rw-r--r--actionpack/lib/system_testing/driver_adapters/rails_selenium_driver.rb98
-rw-r--r--actionpack/lib/system_testing/driver_adapters/web_server.rb45
-rw-r--r--actionpack/lib/system_testing/railtie.rb17
-rw-r--r--actionpack/lib/system_testing/test_helper.rb23
-rw-r--r--actionpack/lib/system_testing/test_helpers.rb9
-rw-r--r--actionpack/lib/system_testing/test_helpers/assertions.rb40
-rw-r--r--actionpack/lib/system_testing/test_helpers/form_helper.rb58
-rw-r--r--actionpack/lib/system_testing/test_helpers/screenshot_helper.rb47
12 files changed, 0 insertions, 554 deletions
diff --git a/actionpack/lib/system_test_case.rb b/actionpack/lib/system_test_case.rb
deleted file mode 100644
index 373cb4f0d0..0000000000
--- a/actionpack/lib/system_test_case.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-require "system_testing/test_helper"
-require "system_testing/driver_adapter"
-
-module Rails
- # System tests are similar to Integration tests in that they incorporate multiple
- # controllers and actions, but can be used to simulate a real user experience.
- # System tests are also known as Acceptance tests.
- #
- # To create a System Test in your application extend your test class from
- # <tt>Rails::SystemTestCase</tt>. System tests use Capybara as a base and
- # allows you to configure the driver. The default driver is
- # <tt>RailsSeleniumDriver</tt> which provides Capybara with no-setup
- # configuration of the Selenium Driver. If you prefer you can use the bare
- # Selenium driver and set your own configuration.
- #
- # A system test looks like the following:
- #
- # require 'test_helper'
- #
- # class Users::CreateTest < Rails::SystemTestCase
- # def adding_a_new_user
- # visit users_path
- # click_on 'New User'
- #
- # fill_in 'Name', with: 'Arya'
- # click_on 'Create User'
- #
- # assert_text 'Arya'
- # end
- # end
- #
- # System test driver can be configured in your Rails configuration file for the
- # test environment.
- #
- # config.system_testing.driver = :rails_selenium_driver
- #
- # You can also specify a driver by initializing a new driver object. This allows
- # you to change the default settings for the driver you're setting.
- #
- # config.system_testing.driver = SystemTesting::DriverAdapters::RailsSeleniumDriver.new(
- # browser: :firefox
- # )
- #
- # A list of supported adapters can be found in DriverAdapters.
- #
- # If you want to use one of the default drivers provided by Capybara you can
- # set the driver in your config to one of those defaults: +:rack_test+,
- # +:selenium+, +:webkit+, or +:poltergeist+. These 4 drivers use Capyara's
- # driver defaults whereas the <tt>RailsSeleniumDriver</tt> has pre-set
- # configuration for browser, server, port, etc.
- class SystemTestCase < ActionDispatch::IntegrationTest
- include SystemTesting::TestHelper
- include SystemTesting::DriverAdapter
-
- ActiveSupport.run_load_hooks(:system_testing, self)
- end
-end
diff --git a/actionpack/lib/system_testing/driver_adapter.rb b/actionpack/lib/system_testing/driver_adapter.rb
deleted file mode 100644
index ccd702e967..0000000000
--- a/actionpack/lib/system_testing/driver_adapter.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-require "system_testing/driver_adapters"
-
-module SystemTesting
- # The <tt>SystemTesting::DriverAdapter</tt> module is used to load the driver
- # set in your Rails' test configuration file.
- #
- # The default driver adapter is the +:rails_selenium_driver+.
- module DriverAdapter
- extend ActiveSupport::Concern
-
- module ClassMethods
- def default_driver # :nodoc
- :rails_selenium_driver
- end
-
- # Returns the current driver that is set. If no driver is set in the
- # Rails' configuration file then +:rails_selenium_driver+ will be
- # initialized.
- def driver
- @driver ||= DriverAdapters.lookup(default_driver)
- end
-
- # Specify the adapter and settings for the system test driver set in the
- # Rails' configuration file.
- def driver=(driver)
- @driver = DriverAdapters.lookup(driver)
- @driver.call
- end
- end
- end
-end
diff --git a/actionpack/lib/system_testing/driver_adapters.rb b/actionpack/lib/system_testing/driver_adapters.rb
deleted file mode 100644
index d246106717..0000000000
--- a/actionpack/lib/system_testing/driver_adapters.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-module SystemTesting
- # == System Testing Driver Adapters
- #
- # By default Rails supports Capybara with the Selenium Driver. Rails provides
- # configuration setup for using the selenium driver with Capybara.
- # Additionally Rails can be used as a layer between Capybara and its other
- # supported drivers: +:rack_test+, +:selenium+, +:webkit+, or +:poltergeist+.
- #
- # *{RackTest}[https://github.com/jnicklas/capybara#racktest]
- # *{Selenium}[http://seleniumhq.org/docs/01_introducing_selenium.html#selenium-2-aka-selenium-webdriver]
- # *{Webkit}[https://github.com/thoughtbot/capybara-webkit]
- # *{Poltergeist}[https://github.com/teampoltergeist/poltergeist]
- #
- # === Driver Features
- #
- # | | Default Browser | Supports Screenshots? |
- # |-----------------|-----------------------|-----------------------|
- # | Rails' Selenium | Chrome | Yes |
- # | Rack Test | No JS Support | No |
- # | Selenium | Firefox | Yes |
- # | WebKit | Headless w/ Qt | Yes |
- # | Poltergeist | Headless w/ PhantomJS | Yes |
- module DriverAdapters
- extend ActiveSupport::Autoload
-
- autoload :CapybaraDriver
- autoload :RailsSeleniumDriver
-
- class << self
- # Returns driver for specified name.
- #
- # SystemTesting::DriverAdapters.lookup(:rails_selenium_driver)
- # # => SystemTesting::DriverAdapters::RailsSeleniumDriver
- def lookup(driver)
- if CapybaraDriver::CAPYBARA_DEFAULTS.include?(driver)
- CapybaraDriver.new(name: driver)
- elsif driver.is_a?(Symbol)
- klass = const_get(driver.to_s.camelize)
- klass.new
- else
- driver
- end
- end
- end
- end
-end
diff --git a/actionpack/lib/system_testing/driver_adapters/capybara_driver.rb b/actionpack/lib/system_testing/driver_adapters/capybara_driver.rb
deleted file mode 100644
index 7755b9616a..0000000000
--- a/actionpack/lib/system_testing/driver_adapters/capybara_driver.rb
+++ /dev/null
@@ -1,83 +0,0 @@
-require "system_testing/driver_adapters/web_server"
-
-module SystemTesting
- module DriverAdapters
- # == CapybaraDriver for System Testing
- #
- # The <tt>CapybaraDriver</tt> is a shim that sits between Rails and
- # Capybara.
- #
- # The drivers Capybara supports are: +:rack_test+, +:selenium+, +:webkit+,
- # and +:poltergeist+.
- #
- # Rails provides its own defaults for Capybara with the Selenium driver
- # through <tt>RailsSeleniumDriver</tt>, but allows users to use Selenium
- # directly.
- #
- # To set your system tests to use one of Capybara's default drivers, add
- # the following to yur Rails' configuration test environment:
- #
- # config.system_testing.driver = :rack_test
- #
- # The +:rack_test+ driver is a basic test driver that doesn't support
- # JavaScript testing and doesn't require a server.
- #
- # The +:poltergeist+ and +:webkit+ drivers are headless, but require some
- # extra environment setup. Because the default server for Rails is Puma, each
- # of the Capybara drivers will default to using Puma. Changing the configuration
- # to use Webrick is possible by initalizing a new driver object.
- #
- # The default settings for the <tt>CapybaraDriver</tt> are:
- #
- # #<SystemTesting::DriverAdapters::CapybaraDriver:0x007ff0e992c1d8
- # @name=:rack_test,
- # @server=:puma,
- # @port=28100
- # >
- #
- # The settings for the <tt>CapybaraDriver</tt> can be changed from
- # Rails' configuration file.
- #
- # config.system_testing.driver = SystemTesting::DriverAdapters::CapybaraDriver.new(
- # name: :webkit,
- # server: :webrick
- # )
- class CapybaraDriver
- include WebServer
-
- CAPYBARA_DEFAULTS = [ :rack_test, :selenium, :webkit, :poltergeist ]
-
- attr_reader :name, :server, :port
-
- def initialize(name: :rack_test, server: :puma, port: 28100)
- @name = name
- @server = server
- @port = port
- end
-
- def call
- registration
- setup
- end
-
- def supports_screenshots?
- @name != :rack_test
- end
-
- private
- def registration
- register_server
- end
-
- def setup
- set_server
- set_port
- set_driver
- end
-
- def set_driver
- Capybara.default_driver = @name
- end
- end
- end
-end
diff --git a/actionpack/lib/system_testing/driver_adapters/rails_selenium_driver.rb b/actionpack/lib/system_testing/driver_adapters/rails_selenium_driver.rb
deleted file mode 100644
index aa67ba8029..0000000000
--- a/actionpack/lib/system_testing/driver_adapters/rails_selenium_driver.rb
+++ /dev/null
@@ -1,98 +0,0 @@
-require "system_testing/driver_adapters/web_server"
-
-module SystemTesting
- module DriverAdapters
- # == RailsSeleniumDriver for System Testing
- #
- # The <tt>RailsSeleniumDriver</tt> uses the Selenium 2.0 webdriver. The
- # selenium-webdriver gem is required by this driver.
- #
- # The <tt>RailsSeleniumDriver</tt> is useful for real browser testing and
- # supports Chrome and Firefox.
- #
- # By default Rails system testing will use Rails' configuration with Capybara
- # and the Selenium driver. To explictly set the <tt>RailsSeleniumDriver</tt>
- # add the following to your Rails' configuration test environment:
- #
- # config.system_testing.driver = :rails_selenium_driver
- #
- # Because this driver supports real browser testing it is required that a
- # server is configured.
- #
- # If no server is specified when the driver is initialized, Puma will be used
- # by default. The default settings for the <tt>RailsSeleniumDriver</tt>
- # are as follows:
- #
- # #<SystemTesting::DriverAdapters::RailsSeleniumDriver:0x007ff0e992c1d8
- # @browser=:chrome,
- # @server=:puma,
- # @port=28100,
- # @screen_size=[ 1400, 1400 ]
- # >
- #
- # The settings for the <tt>RailsSeleniumDriver</tt> can be changed in the
- # Rails configuration file.
- #
- # config.system_testing.driver = SystemTesting::DriverAdapters::RailsSeleniumDriver.new(
- # server: :webrick,
- # port: 28100,
- # screen_size: [ 800, 800 ]
- # )
- #
- # The default browser is set to Chrome because the current version of
- # Firefox does not work with selenium-webdriver. If you want to use Firefox,
- # you will need to use Firefox 45.0esr or 47.0 and ensure
- # that selenium-webdriver is version 2.53.4. To change the browser from
- # +:chrome+ to +:firefox+, initialize the Selenium driver in your Rails'
- # test environment:
- #
- # config.system_testing.driver = SystemTesting::DriverAdapters::RailsSeleniumDriver.new(
- # browser: :firefox
- # )
- class RailsSeleniumDriver
- include WebServer
-
- attr_reader :browser, :server, :port, :screen_size
-
- def initialize(browser: :chrome, server: :puma, port: 28100, screen_size: [ 1400,1400 ]) # :nodoc:
- @browser = browser
- @server = server
- @port = port
- @screen_size = screen_size
- end
-
- def call # :nodoc:
- registration
- setup
- end
-
- def supports_screenshots?
- true
- end
-
- private
- def registration
- register_browser_driver
- register_server
- end
-
- def setup
- set_server
- set_port
- set_driver
- end
-
- def register_browser_driver
- Capybara.register_driver @browser do |app|
- Capybara::Selenium::Driver.new(app, browser: @browser).tap do |driver|
- driver.browser.manage.window.size = Selenium::WebDriver::Dimension.new(*@screen_size)
- end
- end
- end
-
- def set_driver
- Capybara.default_driver = @browser.to_sym
- end
- end
- end
-end
diff --git a/actionpack/lib/system_testing/driver_adapters/web_server.rb b/actionpack/lib/system_testing/driver_adapters/web_server.rb
deleted file mode 100644
index 65d719d1ab..0000000000
--- a/actionpack/lib/system_testing/driver_adapters/web_server.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-begin
- require "rack/handler/puma"
-rescue LoadError
- false
-end
-
-module SystemTesting
- module DriverAdapters
- module WebServer # :nodoc:
- def register_server
- Capybara.register_server @server do |app, port, host|
- case @server
- when :puma
- register_puma(app, port)
- when :webrick
- register_webrick(app, port, host)
- else
- register_default(app, port)
- end
- end
- end
-
- private
- def register_default(app, port)
- Capybara.run_default_server(app, port)
- end
-
- def register_puma(app, port)
- Rack::Handler::Puma.run(app, Port: port, Threads: "0:4")
- end
-
- def register_webrick(app, port)
- Rack::Handler::WEBrick.run(app, Port: port)
- end
-
- def set_server
- Capybara.server = @server
- end
-
- def set_port
- Capybara.server_port = @port
- end
- end
- end
-end
diff --git a/actionpack/lib/system_testing/railtie.rb b/actionpack/lib/system_testing/railtie.rb
deleted file mode 100644
index d8af69e5d3..0000000000
--- a/actionpack/lib/system_testing/railtie.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-require "system_test_case"
-
-module SystemTesting
- # = System Testing Railtie
- class Railtie < Rails::Railtie # :nodoc:
- config.system_testing = ActiveSupport::OrderedOptions.new
-
- initializer "system_testing.set_configs" do |app|
- options = app.config.system_testing
- options.driver ||= Rails::SystemTestCase.default_driver
-
- ActiveSupport.on_load(:system_testing) do
- options.each { |k,v| send("#{k}=", v) }
- end
- end
- end
-end
diff --git a/actionpack/lib/system_testing/test_helper.rb b/actionpack/lib/system_testing/test_helper.rb
deleted file mode 100644
index 8bd49b2f4c..0000000000
--- a/actionpack/lib/system_testing/test_helper.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-require "capybara/dsl"
-require "system_testing/test_helpers"
-
-module SystemTesting
- module TestHelper # :nodoc:
- include TestHelpers::Assertions
- include TestHelpers::FormHelper
- include TestHelpers::ScreenshotHelper
- include Capybara::DSL
-
- Capybara.app = Rack::Builder.new do
- map "/" do
- run Rails.application
- end
- end
-
- def after_teardown
- take_screenshot if supported?
- Capybara.reset_sessions!
- super
- end
- end
-end
diff --git a/actionpack/lib/system_testing/test_helpers.rb b/actionpack/lib/system_testing/test_helpers.rb
deleted file mode 100644
index 3c528a6953..0000000000
--- a/actionpack/lib/system_testing/test_helpers.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-module SystemTesting
- module TestHelpers
- extend ActiveSupport::Autoload
-
- autoload :Assertions
- autoload :FormHelper
- autoload :ScreenshotHelper
- end
-end
diff --git a/actionpack/lib/system_testing/test_helpers/assertions.rb b/actionpack/lib/system_testing/test_helpers/assertions.rb
deleted file mode 100644
index 6e5b62e3c5..0000000000
--- a/actionpack/lib/system_testing/test_helpers/assertions.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-module SystemTesting
- module TestHelpers
- # Assertions for system testing that aren't included by default in Capybara.
- # These are assertions that are useful specifically for Rails applications.
- module Assertions
- # Asserts that all of the provided selectors are present on the given page.
- #
- # assert_all_of_selectors('p', 'td')
- def assert_all_of_selectors(*items)
- options = items.extract_options!
- type = type_for_selector(items)
-
- items.each do |item|
- assert_selector type, item, options
- end
- end
-
- # Asserts that none of the provided selectors are present on the page.
- #
- # assert_none_of_selectors('ul', 'ol')
- def assert_none_of_selectors(*items)
- options = items.extract_options!
- type = type_for_selector(items)
-
- items.each do |item|
- assert_no_selector type, item, options
- end
- end
-
- private
- def type_for_selector(*items)
- if items.first.is_a?(Symbol)
- items.shift
- else
- Capybara.default_selector
- end
- end
- end
- end
-end
diff --git a/actionpack/lib/system_testing/test_helpers/form_helper.rb b/actionpack/lib/system_testing/test_helpers/form_helper.rb
deleted file mode 100644
index 74a1516116..0000000000
--- a/actionpack/lib/system_testing/test_helpers/form_helper.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-module SystemTesting
- module TestHelpers
- # Form helpers for system testing that aren't included by default in
- # Capybara.
- module FormHelper
- # Finds all provided fields or text areas and fills in with supplied values.
- #
- # fill_in_all_fields('Name' => 'Eileen', 'Job Title' => 'Programmer')
- def fill_in_all_fields(fields)
- fields.each do |name, value|
- fill_in name, with: value
- end
- end
-
- # Locates a checkbox that is present inside a label and checks it. When
- # using styled boxes Selenium may not be able to see the checkbox. This
- # form helper looks inside the checkbox and clicks the label instead of
- # setting the value of the checkbox.
- #
- # click_checkbox_label 'Admin'
- #
- # By default +click_checkbox_label+ looks for checkboxes that are not
- # checked by default. To locate an already checked box and uncheck it
- # set checked to true:
- #
- # click_checkbox_label 'Admin', checked: true
- def click_checkbox_label(name, checked: false)
- field = find_checkbox(name, checked)
- label = find_label_wrapper(field)
- label.click
- end
-
- # In lieu of locating a button and calling +click_on+, +press_enter+ will
- # submit the form via enter. This method will only work for drivers that
- # load a browser like Selenium.
- #
- # test 'Adding a User' do
- # fill_in 'Name', with: 'Arya'
- #
- # press_enter
- #
- # assert_text 'Arya'
- # end
- def press_enter
- page.driver.browser.action.send_keys(:enter).perform
- end
-
- private
- def find_checkbox(name, checked)
- find(:field, name, visible: :all, checked: checked)
- end
-
- def find_label_wrapper(field, location: "./ancestor::label")
- field.find :xpath, location
- end
- end
- end
-end
diff --git a/actionpack/lib/system_testing/test_helpers/screenshot_helper.rb b/actionpack/lib/system_testing/test_helpers/screenshot_helper.rb
deleted file mode 100644
index eeade229df..0000000000
--- a/actionpack/lib/system_testing/test_helpers/screenshot_helper.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-module SystemTesting
- module TestHelpers
- # Screenshot helper for system testing
- module ScreenshotHelper
- # Takes a screenshot of the current page in the browser if the system
- # test driver supports screenshots and the test failed.
- #
- # Additionally +take_screenshot+ can be used within your tests at points
- # you want to take a screenshot if the driver supports screenshots. The
- # Rack Test driver does not support screenshots.
- #
- # You can check of the driver supports screenshots by running
- #
- # Rails::SystemTestCase.driver.supports_screenshots?
- # => true
- def take_screenshot
- puts "[Screenshot]: #{image_path}"
- puts find_image
- end
-
- private
- def supported?
- Rails::SystemTestCase.driver.supports_screenshots? && !passed?
- end
-
- def image_path
- path = "tmp/screenshots/failures_#{method_name}.png"
- page.save_screenshot(Rails.root.join(path))
- path
- end
-
- def find_image
- if ENV["CAPYBARA_INLINE_SCREENSHOT"] == "artifact"
- "\e]1338;url=artifact://#{image_path}\a"
- else
- name = inline_base64(File.basename(image_path))
- image = inline_base64(File.read(image_path))
- "\e]1337;File=name=#{name};height=400px;inline=1:#{image}\a"
- end
- end
-
- def inline_base64(path)
- Base64.encode64(path).gsub("\n", "")
- end
- end
- end
-end