Permalink
Browse files

Move and rename system tests

* Move system tests back into Action Pack
* Rename `ActionSystemTest` to `ActionDispatch::SystemTestCase`
* Remove private base module and only make file for public
`SystemTestCase` class, name private module `SystemTesting`
* Rename `ActionSystemTestCase` to `ApplicationSystemTestCase`
* Update corresponding documentation and guides
* Delete old `ActionSystemTest` files
  • Loading branch information...
eileencodes committed Feb 19, 2017
1 parent 0a68308 commit 1a0ca84a064b07ecab798793a3d7ebe89bb6367c
Showing with 298 additions and 519 deletions.
  1. +1 −1 .travis.yml
  2. +2 −0 Gemfile
  3. +1 −5 Gemfile.lock
  4. +2 −0 actionpack/lib/action_dispatch.rb
  5. +129 −0 actionpack/lib/action_dispatch/system_test_case.rb
  6. +28 −0 actionpack/lib/action_dispatch/system_testing/browser.rb
  7. +18 −0 actionpack/lib/action_dispatch/system_testing/driver.rb
  8. +23 −0 actionpack/lib/action_dispatch/system_testing/server.rb
  9. +53 −0 actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb
  10. +3 −3 {actionsystemtest/test/cases → actionpack/test/dispatch/system_testing}/browser_test.rb
  11. +3 −3 {actionsystemtest/test/cases → actionpack/test/dispatch/system_testing}/driver_test.rb
  12. +3 −3 {actionsystemtest/test/cases → actionpack/test/dispatch/system_testing}/screenshot_helper_test.rb
  13. +10 −0 actionpack/test/dispatch/system_testing/server_test.rb
  14. +5 −6 ...ses/action_system_test_test.rb → actionpack/test/dispatch/system_testing/system_test_case_test.rb
  15. +0 −3 actionsystemtest/CHANGELOG.md
  16. +0 −20 actionsystemtest/MIT-LICENSE
  17. +0 −102 actionsystemtest/README.md
  18. +0 −32 actionsystemtest/Rakefile
  19. +0 −24 actionsystemtest/actionsystemtest.gemspec
  20. +0 −154 actionsystemtest/lib/action_system_test.rb
  21. +0 −26 actionsystemtest/lib/action_system_test/browser.rb
  22. +0 −16 actionsystemtest/lib/action_system_test/driver.rb
  23. +0 −15 actionsystemtest/lib/action_system_test/gem_version.rb
  24. +0 −21 actionsystemtest/lib/action_system_test/server.rb
  25. +0 −51 actionsystemtest/lib/action_system_test/test_helpers/screenshot_helper.rb
  26. +0 −8 actionsystemtest/lib/action_system_test/version.rb
  27. +0 −9 actionsystemtest/test/cases/server_test.rb
  28. +0 −1 ci/travis.rb
  29. +5 −5 guides/source/testing.md
  30. +1 −1 railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb
  31. +1 −1 railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb
  32. +5 −3 railties/lib/rails/generators/test_unit/system/templates/system_test.rb
  33. +1 −1 railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb
  34. +2 −2 railties/lib/rails/test_help.rb
  35. +0 −1 railties/railties.gemspec
  36. +1 −1 railties/test/generators/scaffold_generator_test.rb
  37. +1 −1 railties/test/generators/system_test_generator_test.rb
View
@@ -36,7 +36,7 @@ env:
matrix:
- "GEM=railties"
- "GEM=ap,ac"
- "GEM=am,amo,as,av,aj,ast"
- "GEM=am,amo,as,av,aj"
- "GEM=as PRESERVE_TIMEZONES=1"
- "GEM=ar:mysql2"
- "GEM=ar:sqlite3"
View
@@ -16,6 +16,8 @@ gem "rake", ">= 11.1"
# be loaded after loading the test library.
gem "mocha", "~> 0.14", require: false
gem "capybara", "~> 2.7.0"
gem "rack-cache", "~> 1.2"
gem "jquery-rails"
gem "coffee-rails"
View
@@ -49,10 +49,6 @@ PATH
rack-test (~> 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionsystemtest (5.1.0.alpha)
actionpack (= 5.1.0.alpha)
activesupport (= 5.1.0.alpha)
capybara (~> 2.7.0)
actionview (5.1.0.alpha)
activesupport (= 5.1.0.alpha)
builder (~> 3.1)
@@ -87,7 +83,6 @@ PATH
sprockets-rails (>= 2.0.0)
railties (5.1.0.alpha)
actionpack (= 5.1.0.alpha)
actionsystemtest (= 5.1.0.alpha)
activesupport (= 5.1.0.alpha)
method_source
rake (>= 0.8.7)
@@ -387,6 +382,7 @@ DEPENDENCIES
blade
blade-sauce_labs_plugin
byebug
capybara (~> 2.7.0)
coffee-rails
dalli (>= 2.2.1)
delayed_job
@@ -97,6 +97,8 @@ module Session
autoload :TestResponse
autoload :AssertionResponse
end
autoload :SystemTestCase, "action_dispatch/system_test_case"
end
autoload :Mime, "action_dispatch/http/mime_type"
@@ -0,0 +1,129 @@
require "capybara/dsl"
require "action_controller"
require "action_dispatch/system_testing/driver"
require "action_dispatch/system_testing/server"
require "action_dispatch/system_testing/browser"
require "action_dispatch/system_testing/test_helpers/screenshot_helper"
module ActionDispatch
class SystemTestCase < IntegrationTest
# = System Testing

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca Feb 23, 2017

Member

Is this supposed to be documentation of SystemTestCase or just internal documentation for framework contributors?

@rafaelfranca

rafaelfranca Feb 23, 2017

Member

Is this supposed to be documentation of SystemTestCase or just internal documentation for framework contributors?

This comment has been minimized.

Show comment
Hide comment
@eileencodes

eileencodes Feb 23, 2017

Member

It's supposed to be documentation of SystemTestCase but I realized it's in the wrong place. I'm going to move it now.

@eileencodes

eileencodes Feb 23, 2017

Member

It's supposed to be documentation of SystemTestCase but I realized it's in the wrong place. I'm going to move it now.

#
# System tests let you test real application in the browser. Because system
# tests use a real browser experience you can test all of your JavaScript
# easily from your test suite.
#
# To create a system test in your application, extend your test class
# from <tt>ApplicationSystemTestCase</tt>. System tests use Capybara as a
# base and allow you to configure the settings through your
# <tt>system_test_helper.rb</tt> file that is generated with a new
# application or scaffold.
#
# Here is an example system test:
#
# require 'system_test_helper'
#
# class Users::CreateTest < ApplicationSystemTestCase
# test "adding a new user" do
# visit users_path
# click_on 'New User'
#
# fill_in 'Name', with: 'Arya'
# click_on 'Create User'
#
# assert_text 'Arya'
# end
# end
#
# When generating an application or scaffold a +system_test_helper.rb+ will also
# be generated containing the base class for system testing. This is where you
# can change the driver, add Capybara settings, and other configuration for
# your system tests.
#
# require "test_helper"
#
# class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
# teardown do
# take_failed_screenshot
# Capybara.reset_sessions!
# end
# end
#
# By default, <tt>ActionDispatch::SystemTestCase</tt> is driven by the
# Selenium driver, with the Chrome browser, and a browser size of 1400x1400.
#
# Changing the driver configuration options are easy. Let's say you want to use
# and the Firefox browser instead. In your +system_test_helper.rb+
# file add the following:
#
# require "test_helper"
#
# class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
# driven_by :selenium, using: :firefox
#
# teardown do
# take_failed_screenshot
# Capybara.reset_sessions!
# end
# end
#
# +driven_by+ has a required argument for the driver name. The keyword
# arguments are +:using+ for the browser (not applicable for headless drivers),
# and +:screen_size+ to change the size of the screen taking screenshots.
#
# To use a headless driver, like Poltergeist, update your Gemfile to use
# Poltergeist instead of Selenium and then declare the driver name in the
# +system_test_helper.rb+ file. In this case you would leave out the +:using+
# option because the driver is headless.
#
# require "test_helper"
# require "capybara/poltergeist"
#
# class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
# driven_by :poltergeist
#
# teardown do
# take_failed_screenshot
# Capybara.reset_sessions!
# end
# end
#
# 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.
include Capybara::DSL
include SystemTesting::TestHelpers::ScreenshotHelper
def self.start_application # :nodoc:
Capybara.app = Rack::Builder.new do
map "/" do
run Rails.application
end
end
end
# System Test configuration options
#
# The defaults settings are Selenium, using Chrome, with a screen size
# of 1400x1400.
#
# Examples:
#
# driven_by :poltergeist
#
# driven_by :selenium, using: :firefox
#
# driven_by :selenium, screen_size: [800, 800]
def self.driven_by(driver, using: :chrome, screen_size: [1400, 1400])
SystemTesting::Driver.new(driver).run
SystemTesting::Server.new.run
SystemTesting::Browser.new(using, screen_size).run if selenium?(driver)
end
def self.selenium?(driver) # :nodoc:
driver == :selenium
end
end
SystemTestCase.start_application
end
@@ -0,0 +1,28 @@
module ActionDispatch
module SystemTesting
class Browser # :nodoc:
def initialize(name, screen_size)
@name = name
@screen_size = screen_size
end
def run
register
setup
end
private
def register
Capybara.register_driver @name do |app|
Capybara::Selenium::Driver.new(app, browser: @name).tap do |driver|
driver.browser.manage.window.size = Selenium::WebDriver::Dimension.new(*@screen_size)
end
end
end
def setup
Capybara.default_driver = @name.to_sym
end
end
end
end
@@ -0,0 +1,18 @@
module ActionDispatch
module SystemTesting
class Driver # :nodoc:
def initialize(name)
@name = name
end
def run
register
end
private
def register
Capybara.default_driver = @name
end
end
end
end
@@ -0,0 +1,23 @@
require "rack/handler/puma"
module ActionDispatch
module SystemTesting
class Server # :nodoc:
def run
register
setup
end
private
def register
Capybara.register_server :rails_puma do |app, port, host|
Rack::Handler::Puma.run(app, Port: port, Threads: "0:1")
end
end
def setup
Capybara.server = :rails_puma
end
end
end
end
@@ -0,0 +1,53 @@
module ActionDispatch
module SystemTesting
module TestHelpers
# Screenshot helper for system testing
module ScreenshotHelper
# Takes a screenshot of the current page in the browser.
#
# +take_screenshot+ can be used at any point in your system tests to take
# a screenshot of the current state. This can be useful for debugging or
# automating visual testing.
def take_screenshot
save_image
puts "[Screenshot]: #{image_path}"
puts display_image
end
# Takes a screenshot of the current page in the browser if the test
# failed.
#
# +take_screenshot+ is included in <tt>system_test_helper.rb</tt> that is
# generated with the application. To take screenshots when a test fails
# add +take_failed_screenshot+ to the teardown block before clearing
# sessions.
def take_failed_screenshot
take_screenshot unless passed?
end
private
def image_path
"tmp/screenshots/failures_#{method_name}.png"
end
def save_image
page.save_screenshot(Rails.root.join(image_path))
end
def display_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
end
@@ -1,9 +1,9 @@
require "active_support/testing/autorun"
require "action_system_test"
require "abstract_unit"
require "action_dispatch/system_testing/browser"
class BrowserTest < ActiveSupport::TestCase
test "initializing the browser" do
browser = ActionSystemTest::Browser.new(:chrome, [ 1400, 1400 ])
browser = ActionDispatch::SystemTesting::Browser.new(:chrome, [ 1400, 1400 ])
assert_equal :chrome, browser.instance_variable_get(:@name)
assert_equal [ 1400, 1400 ], browser.instance_variable_get(:@screen_size)
end
@@ -1,9 +1,9 @@
require "active_support/testing/autorun"
require "action_system_test"
require "abstract_unit"
require "action_dispatch/system_testing/driver"
class DriverTest < ActiveSupport::TestCase
test "initializing the driver" do
driver = ActionSystemTest::Driver.new(:selenium)
driver = ActionDispatch::SystemTesting::Driver.new(:selenium)
assert_equal :selenium, driver.instance_variable_get(:@name)
end
end
@@ -1,9 +1,9 @@
require "active_support/testing/autorun"
require "action_system_test"
require "abstract_unit"
require "action_dispatch/system_testing/test_helpers/screenshot_helper"
class ScreenshotHelperTest < ActiveSupport::TestCase
test "image path is saved in tmp directory" do
new_test = ActionSystemTest::Base.new("x")
new_test = ActionDispatch::SystemTestCase.new("x")
assert_equal "tmp/screenshots/failures_x.png", new_test.send(:image_path)
end
@@ -0,0 +1,10 @@
require "abstract_unit"
require "capybara/dsl"
require "action_dispatch/system_testing/server"
class ServerTest < ActiveSupport::TestCase
test "initializing the server port" do
server = ActionDispatch::SystemTesting::Server.new.run
assert_includes Capybara.servers, :rails_puma
end
end
@@ -1,22 +1,21 @@
require "active_support/testing/autorun"
require "action_system_test"
require "abstract_unit"
class ActionSystemTestTest < ActiveSupport::TestCase
class SystemTestCaseTest < ActiveSupport::TestCase
test "driven_by sets Capybara's default driver to poltergeist" do
ActionSystemTest::Base.driven_by :poltergeist
ActionDispatch::SystemTestCase.driven_by :poltergeist
assert_equal :poltergeist, Capybara.default_driver
end
test "driven_by sets Capybara's drivers respectively" do
ActionSystemTest::Base.driven_by :selenium, using: :chrome
ActionDispatch::SystemTestCase.driven_by :selenium, using: :chrome
assert_includes Capybara.drivers, :selenium
assert_includes Capybara.drivers, :chrome
assert_equal :chrome, Capybara.default_driver
end
test "selenium? returns false if driver is poltergeist" do
assert_not ActionSystemTest::Base.selenium?(:poltergeist)
assert_not ActionDispatch::SystemTestCase.selenium?(:poltergeist)
end
end
@@ -1,3 +0,0 @@
* Added to Rails!
*Eileen M. Uchitelle*
Oops, something went wrong.

0 comments on commit 1a0ca84

Please sign in to comment.