aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.travis.yml2
-rw-r--r--Gemfile2
-rw-r--r--Gemfile.lock6
-rw-r--r--actionpack/lib/action_dispatch.rb2
-rw-r--r--actionpack/lib/action_dispatch/system_test_case.rb129
-rw-r--r--actionpack/lib/action_dispatch/system_testing/browser.rb28
-rw-r--r--actionpack/lib/action_dispatch/system_testing/driver.rb18
-rw-r--r--actionpack/lib/action_dispatch/system_testing/server.rb23
-rw-r--r--actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb53
-rw-r--r--actionpack/test/dispatch/system_testing/browser_test.rb (renamed from actionsystemtest/test/cases/browser_test.rb)6
-rw-r--r--actionpack/test/dispatch/system_testing/driver_test.rb (renamed from actionsystemtest/test/cases/driver_test.rb)6
-rw-r--r--actionpack/test/dispatch/system_testing/screenshot_helper_test.rb (renamed from actionsystemtest/test/cases/screenshot_helper_test.rb)6
-rw-r--r--actionpack/test/dispatch/system_testing/server_test.rb10
-rw-r--r--actionpack/test/dispatch/system_testing/system_test_case_test.rb (renamed from actionsystemtest/test/cases/action_system_test_test.rb)11
-rw-r--r--actionsystemtest/CHANGELOG.md3
-rw-r--r--actionsystemtest/MIT-LICENSE20
-rw-r--r--actionsystemtest/README.md102
-rw-r--r--actionsystemtest/Rakefile32
-rw-r--r--actionsystemtest/actionsystemtest.gemspec24
-rw-r--r--actionsystemtest/lib/action_system_test.rb154
-rw-r--r--actionsystemtest/lib/action_system_test/browser.rb26
-rw-r--r--actionsystemtest/lib/action_system_test/driver.rb16
-rw-r--r--actionsystemtest/lib/action_system_test/gem_version.rb15
-rw-r--r--actionsystemtest/lib/action_system_test/server.rb21
-rw-r--r--actionsystemtest/lib/action_system_test/test_helpers/screenshot_helper.rb51
-rw-r--r--actionsystemtest/lib/action_system_test/version.rb8
-rw-r--r--actionsystemtest/test/cases/server_test.rb9
-rwxr-xr-xci/travis.rb1
-rw-r--r--guides/source/testing.md10
-rw-r--r--railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb2
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb2
-rw-r--r--railties/lib/rails/generators/test_unit/system/templates/system_test.rb8
-rw-r--r--railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb2
-rw-r--r--railties/lib/rails/test_help.rb4
-rw-r--r--railties/railties.gemspec1
-rw-r--r--railties/test/generators/scaffold_generator_test.rb2
-rw-r--r--railties/test/generators/system_test_generator_test.rb2
37 files changed, 298 insertions, 519 deletions
diff --git a/.travis.yml b/.travis.yml
index 8fdef9e2a3..eafa06e44f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -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"
diff --git a/Gemfile b/Gemfile
index 9f40bae83f..2aaaca3e0b 100644
--- a/Gemfile
+++ b/Gemfile
@@ -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"
diff --git a/Gemfile.lock b/Gemfile.lock
index 870e23cb73..402eae60f6 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -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
diff --git a/actionpack/lib/action_dispatch.rb b/actionpack/lib/action_dispatch.rb
index 028177ace2..303790e96d 100644
--- a/actionpack/lib/action_dispatch.rb
+++ b/actionpack/lib/action_dispatch.rb
@@ -97,6 +97,8 @@ module ActionDispatch
autoload :TestResponse
autoload :AssertionResponse
end
+
+ autoload :SystemTestCase, "action_dispatch/system_test_case"
end
autoload :Mime, "action_dispatch/http/mime_type"
diff --git a/actionpack/lib/action_dispatch/system_test_case.rb b/actionpack/lib/action_dispatch/system_test_case.rb
new file mode 100644
index 0000000000..850f101ca8
--- /dev/null
+++ b/actionpack/lib/action_dispatch/system_test_case.rb
@@ -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
+ #
+ # 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
diff --git a/actionpack/lib/action_dispatch/system_testing/browser.rb b/actionpack/lib/action_dispatch/system_testing/browser.rb
new file mode 100644
index 0000000000..c9a6628516
--- /dev/null
+++ b/actionpack/lib/action_dispatch/system_testing/browser.rb
@@ -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
diff --git a/actionpack/lib/action_dispatch/system_testing/driver.rb b/actionpack/lib/action_dispatch/system_testing/driver.rb
new file mode 100644
index 0000000000..7c2ad84e19
--- /dev/null
+++ b/actionpack/lib/action_dispatch/system_testing/driver.rb
@@ -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
diff --git a/actionpack/lib/action_dispatch/system_testing/server.rb b/actionpack/lib/action_dispatch/system_testing/server.rb
new file mode 100644
index 0000000000..62ba07736b
--- /dev/null
+++ b/actionpack/lib/action_dispatch/system_testing/server.rb
@@ -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
diff --git a/actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb b/actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb
new file mode 100644
index 0000000000..1ad64b7f78
--- /dev/null
+++ b/actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb
@@ -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
diff --git a/actionsystemtest/test/cases/browser_test.rb b/actionpack/test/dispatch/system_testing/browser_test.rb
index 05e260abfa..b0ad309492 100644
--- a/actionsystemtest/test/cases/browser_test.rb
+++ b/actionpack/test/dispatch/system_testing/browser_test.rb
@@ -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
diff --git a/actionsystemtest/test/cases/driver_test.rb b/actionpack/test/dispatch/system_testing/driver_test.rb
index 895aab4e45..f0ebdb38db 100644
--- a/actionsystemtest/test/cases/driver_test.rb
+++ b/actionpack/test/dispatch/system_testing/driver_test.rb
@@ -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
diff --git a/actionsystemtest/test/cases/screenshot_helper_test.rb b/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb
index d86bc4e62d..3da89f4a10 100644
--- a/actionsystemtest/test/cases/screenshot_helper_test.rb
+++ b/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb
@@ -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
diff --git a/actionpack/test/dispatch/system_testing/server_test.rb b/actionpack/test/dispatch/system_testing/server_test.rb
new file mode 100644
index 0000000000..66842f4ea9
--- /dev/null
+++ b/actionpack/test/dispatch/system_testing/server_test.rb
@@ -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
diff --git a/actionsystemtest/test/cases/action_system_test_test.rb b/actionpack/test/dispatch/system_testing/system_test_case_test.rb
index b77da5a5a9..a384902a14 100644
--- a/actionsystemtest/test/cases/action_system_test_test.rb
+++ b/actionpack/test/dispatch/system_testing/system_test_case_test.rb
@@ -1,15 +1,14 @@
-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
@@ -17,6 +16,6 @@ class ActionSystemTestTest < ActiveSupport::TestCase
end
test "selenium? returns false if driver is poltergeist" do
- assert_not ActionSystemTest::Base.selenium?(:poltergeist)
+ assert_not ActionDispatch::SystemTestCase.selenium?(:poltergeist)
end
end
diff --git a/actionsystemtest/CHANGELOG.md b/actionsystemtest/CHANGELOG.md
deleted file mode 100644
index 3c7ea2c273..0000000000
--- a/actionsystemtest/CHANGELOG.md
+++ /dev/null
@@ -1,3 +0,0 @@
-* Added to Rails!
-
- *Eileen M. Uchitelle*
diff --git a/actionsystemtest/MIT-LICENSE b/actionsystemtest/MIT-LICENSE
deleted file mode 100644
index 7fddc6b222..0000000000
--- a/actionsystemtest/MIT-LICENSE
+++ /dev/null
@@ -1,20 +0,0 @@
-Copyright (c) 2017 David Heinemeier Hansson
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/actionsystemtest/README.md b/actionsystemtest/README.md
deleted file mode 100644
index 4238b9a749..0000000000
--- a/actionsystemtest/README.md
+++ /dev/null
@@ -1,102 +0,0 @@
-# Action System Test
-
-Action System Test adds Capybara integration to your Rails application and makes
-it possible to test your application and it's JavaScript interactions.
-
-This allows you to test the entire user experience of your application rather
-than your controllers, models, and views separately.
-
-Action System Test provides all of the setup out of the box for you to use
-Capybara with the Selenium Driver in your Rails application. Changing the
-default configuration is simple, yet flexible.
-
-## Examples
-
-### Usage
-
-By default Rails provides applications with system testing through Capybara
-and defaults to using the Selenium driver. The configuration set by Rails
-means that when you generate an application system tests will work out of
-the box, without you having to change any of the configuration requirements.
-
-Action System Test uses all the helpers from Capybara, but abstracts away the
-setup required to get running. Below is an example Action System Test.
-
-```ruby
-class UsersTest < ActionSystemTestCase
- setup do
- visit users_path
- end
-
- test "creating a new user" do
- click_on "New User"
-
- fill_in "Name", with: "Arya"
-
- click_on "Create User"
-
- assert_text "Arya"
- end
-end
-```
-
-First we visit the +users_path+. From there we are going to use Action System
-Test to create a new user. The test will click on the "New User" button. Then
-it will fill in the "Name" field with "Arya" and click on the "Create User"
-button. Lastly, we assert that the text on the Users show page is what we
-expected, which in this case is "Arya".
-
-### Configuration
-
-When generating a new application Rails will include the Capybara gem, the
-Selenium gem, and a <tt>system_test_helper.rb</tt> file. The
-<tt>system_test_helper.rb</tt> file is where you can change the desired
-configuration if Rails doesn't work out of the box for you.
-
-The <tt>system_test_helper.rb</tt> file provides a home for all of your Capybara
-and Action System Test configuration.
-
-The default configuration uses the Selenium driver, with the Chrome browser,
-and a screen size of 1400x1400.
-
-Changing the configuration is as simple as changing the driver in your
-<tt>system_test_helper.rb</tt>
-
-If you want to change the default settings of the Rails provided Selenium
-you can change `driven_by` in the helper file.
-
-The driver name is a required argument for `driven_by`. The optional arguments
-that can be passed to `driven_by` are `:using` for the browser (this will only
-be used for non-headless drivers like Selenium), and `:screen_size` to change
-the size of the screen for screenshots.
-
-Below are some examples for changing the default configuration settings for
-system tests:
-
-Changing the browser and screen size:
-
-```ruby
-class ActionSystemTestCase < ActionSystemTest::Base
- driven_by :selenium, using: :firefox, screen_size: [ 800, 800 ]
-end
-```
-
-The browser setting is not used by headless drivers like Poltergeist. When
-using a headless driver simply leave out the `:using` argument.
-
-```ruby
-class ActionSystemTestCase < ActionSystemTest::Base
- driven_by :poltergeist
-end
-```
-
-### Running the tests
-
-Because system tests are time consuming and can use a lot of resources
-they are not automatically run with `rails test`.
-
-To run all the tests in the system suite run the system test command:
-
-```
-$ rails test:system
-```
diff --git a/actionsystemtest/Rakefile b/actionsystemtest/Rakefile
deleted file mode 100644
index 8b07e8f4af..0000000000
--- a/actionsystemtest/Rakefile
+++ /dev/null
@@ -1,32 +0,0 @@
-require "rake/testtask"
-
-test_files = Dir.glob("test/**/*_test.rb")
-
-desc "Default Task"
-task default: :test
-
-task :package
-
-# Run the unit tests
-Rake::TestTask.new do |t|
- t.libs << "test"
- t.test_files = test_files
-
- t.warning = true
- t.verbose = true
- t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION)
-end
-
-namespace :test do
- task :isolated do
- test_files.all? do |file|
- sh(Gem.ruby, "-w", "-Ilib:test", file)
- end || raise("Failures")
- end
-end
-
-task :lines do
- load File.expand_path("..", File.dirname(__FILE__)) + "/tools/line_statistics"
- files = FileList["lib/**/*.rb"]
- CodeTools::LineStatistics.new(files).print_loc
-end
diff --git a/actionsystemtest/actionsystemtest.gemspec b/actionsystemtest/actionsystemtest.gemspec
deleted file mode 100644
index 81293980c4..0000000000
--- a/actionsystemtest/actionsystemtest.gemspec
+++ /dev/null
@@ -1,24 +0,0 @@
-version = File.read(File.expand_path("../../RAILS_VERSION", __FILE__)).strip
-
-Gem::Specification.new do |s|
- s.platform = Gem::Platform::RUBY
- s.name = "actionsystemtest"
- s.version = version
- s.summary = "Acceptance test framework for Rails."
- s.description = "Test framework for testing web applications by simulating how users interact with your application."
-
- s.required_ruby_version = ">= 2.2.2"
-
- s.license = "MIT"
-
- s.author = ["Eileen Uchitelle", "David Heinemeier Hansson"]
- s.email = ["eileencodes@gmail.com", "david@loudthinking.com"]
- s.homepage = "http://rubyonrails.org"
-
- s.files = Dir["CHANGELOG.md", "MIT-LICENSE", "README.md", "lib/**/*"]
- s.require_path = "lib"
-
- s.add_dependency "capybara", "~> 2.7.0"
- s.add_dependency "actionpack", version
- s.add_dependency "activesupport", version
-end
diff --git a/actionsystemtest/lib/action_system_test.rb b/actionsystemtest/lib/action_system_test.rb
deleted file mode 100644
index 3c96361725..0000000000
--- a/actionsystemtest/lib/action_system_test.rb
+++ /dev/null
@@ -1,154 +0,0 @@
-#--
-## Copyright (c) 2014-2017 David Heinemeier Hansson
-##
-## Permission is hereby granted, free of charge, to any person obtaining
-## a copy of this software and associated documentation files (the
-## "Software"), to deal in the Software without restriction, including
-## without limitation the rights to use, copy, modify, merge, publish,
-## distribute, sublicense, and/or sell copies of the Software, and to
-## permit persons to whom the Software is furnished to do so, subject to
-## the following conditions:
-##
-## The above copyright notice and this permission notice shall be
-## included in all copies or substantial portions of the Software.
-##
-## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-## LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-## OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-## WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-##++
-
-require "capybara/dsl"
-require "action_controller"
-require "action_system_test/driver"
-require "action_system_test/browser"
-require "action_system_test/server"
-require "action_system_test/test_helpers/screenshot_helper"
-
-module ActionSystemTest # :nodoc:
- # = Action System Test
- #
- # 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 an ActionSystemTest in your application, extend your test class
- # from <tt>ActionSystemTestCase</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 < ActionSystemTestCase
- # 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 ActionSystemTestCase < ActionSystemTest::Base
- # teardown do
- # take_failed_screenshot
- # Capybara.reset_sessions!
- # end
- # end
- #
- # By default, <tt>ActionSystemTest</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 ActionSystemTestCase < ActionSystemTest::Base
- # 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 ActionSystemTestCase < ActionSystemTest::Base
- # driven_by :poltergeist
- #
- # teardown do
- # take_failed_screenshot
- # Capybara.reset_sessions!
- # end
- # end
- #
- # Because <tt>ActionSystemTest</tt> is a shim between Capybara and Rails, any
- # driver that is supported by Capybara is supported by Action System Test as
- # long as you include the required gems and files.
- include Capybara::DSL
- include ActionSystemTest::TestHelpers::ScreenshotHelper
-
- class Base < ActionDispatch::IntegrationTest
- include ActionSystemTest
-
- def self.start_application # :nodoc:
- Capybara.app = Rack::Builder.new do
- map "/" do
- run Rails.application
- end
- end
- end
-
- # Action 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])
- Driver.new(driver).run
- Server.new.run
- Browser.new(using, screen_size).run if selenium?(driver)
- end
-
- def self.selenium?(driver) # :nodoc:
- driver == :selenium
- end
- end
-
- Base.start_application
- Base.driven_by :selenium
-end
diff --git a/actionsystemtest/lib/action_system_test/browser.rb b/actionsystemtest/lib/action_system_test/browser.rb
deleted file mode 100644
index 220d8b6807..0000000000
--- a/actionsystemtest/lib/action_system_test/browser.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-module ActionSystemTest
- 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
diff --git a/actionsystemtest/lib/action_system_test/driver.rb b/actionsystemtest/lib/action_system_test/driver.rb
deleted file mode 100644
index 7d499ba772..0000000000
--- a/actionsystemtest/lib/action_system_test/driver.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-module ActionSystemTest
- class Driver # :nodoc:
- def initialize(name)
- @name = name
- end
-
- def run
- register
- end
-
- private
- def register
- Capybara.default_driver = @name
- end
- end
-end
diff --git a/actionsystemtest/lib/action_system_test/gem_version.rb b/actionsystemtest/lib/action_system_test/gem_version.rb
deleted file mode 100644
index c10fce2da0..0000000000
--- a/actionsystemtest/lib/action_system_test/gem_version.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-module ActionSystemTest
- # Returns the version of the currently loaded Action System Test as a <tt>Gem::Version</tt>.
- def self.gem_version
- Gem::Version.new VERSION::STRING
- end
-
- module VERSION
- MAJOR = 5
- MINOR = 1
- TINY = 0
- PRE = "alpha"
-
- STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
- end
-end
diff --git a/actionsystemtest/lib/action_system_test/server.rb b/actionsystemtest/lib/action_system_test/server.rb
deleted file mode 100644
index 76ae30f753..0000000000
--- a/actionsystemtest/lib/action_system_test/server.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require "rack/handler/puma"
-
-module ActionSystemTest
- 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
diff --git a/actionsystemtest/lib/action_system_test/test_helpers/screenshot_helper.rb b/actionsystemtest/lib/action_system_test/test_helpers/screenshot_helper.rb
deleted file mode 100644
index af83ca3ec8..0000000000
--- a/actionsystemtest/lib/action_system_test/test_helpers/screenshot_helper.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-module ActionSystemTest
- 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
diff --git a/actionsystemtest/lib/action_system_test/version.rb b/actionsystemtest/lib/action_system_test/version.rb
deleted file mode 100644
index a0fda7d9da..0000000000
--- a/actionsystemtest/lib/action_system_test/version.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require_relative "gem_version"
-
-module ActionSystemTest
- # Returns the version of the currently loaded Action System Test as a <tt>Gem::Version</tt>
- def self.version
- gem_version
- end
-end
diff --git a/actionsystemtest/test/cases/server_test.rb b/actionsystemtest/test/cases/server_test.rb
deleted file mode 100644
index 627b146d03..0000000000
--- a/actionsystemtest/test/cases/server_test.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require "active_support/testing/autorun"
-require "action_system_test"
-
-class ServerTest < ActiveSupport::TestCase
- test "initializing the server port" do
- server = ActionSystemTest::Server
- assert_includes Capybara.servers, :rails_puma
- end
-end
diff --git a/ci/travis.rb b/ci/travis.rb
index 2958b5b0f5..f59ce5406a 100755
--- a/ci/travis.rb
+++ b/ci/travis.rb
@@ -24,7 +24,6 @@ class Build
"av" => "actionview",
"aj" => "activejob",
"ac" => "actioncable",
- "ast" => "actionsystemtest",
"guides" => "guides"
}
diff --git a/guides/source/testing.md b/guides/source/testing.md
index 5b8e14f296..366ab0b2a1 100644
--- a/guides/source/testing.md
+++ b/guides/source/testing.md
@@ -367,7 +367,7 @@ All the basic assertions such as `assert_equal` defined in `Minitest::Assertions
* [`ActionView::TestCase`](http://api.rubyonrails.org/classes/ActionView/TestCase.html)
* [`ActionDispatch::IntegrationTest`](http://api.rubyonrails.org/classes/ActionDispatch/IntegrationTest.html)
* [`ActiveJob::TestCase`](http://api.rubyonrails.org/classes/ActiveJob/TestCase.html)
-* [`ActionSystemTestCase`](http://api.rubyonrails.org/classes/ActionSystemTest.html)
+* [`ActionDispatch::SystemTestCase`](http://api.rubyonrails.org/classes/ActionDispatch/SystemTestCase.html)
Each of these classes include `Minitest::Assertions`, allowing us to use all of the basic assertions in our tests.
@@ -620,7 +620,7 @@ Here's what a freshly-generated system test looks like:
```ruby
require "system_test_helper"
-class UsersCreateTest < ActionSystemTestCase
+class UsersCreateTest < ApplicationSystemTestCase
# test "the truth" do
# assert true
# end
@@ -649,7 +649,7 @@ Poltergeist. First add the Poltergeist gem to your Gemfile. Then in your
require "test_helper"
require "capybara/poltergeist"
-class ActionSystemTestCase < ActionSystemTest::Base
+class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :poltergeist
end
```
@@ -661,7 +661,7 @@ argument, all other arguments are optional.
```ruby
require "test_helper"
-class ActionSystemTestCase < ActionSystemTest::Base
+class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :firefox, on: 3000
end
```
@@ -717,7 +717,7 @@ Now let's open that file and write our first assertion:
```ruby
require "system_test_helper"
-class UsersTest < ActionSystemTestCase
+class UsersTest < ApplicationSystemTestCase
test "viewing the index" do
visit articles_path
assert_text "h1", "Articles"
diff --git a/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb b/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb
index 77c4738d6f..1d0ae787f7 100644
--- a/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb
+++ b/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb
@@ -1,6 +1,6 @@
require "test_helper"
-class ActionSystemTestCase < ActionSystemTest::Base
+class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
teardown do
take_failed_screenshot
Capybara.reset_sessions!
diff --git a/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb b/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb
index 77c4738d6f..1d0ae787f7 100644
--- a/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb
+++ b/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb
@@ -1,6 +1,6 @@
require "test_helper"
-class ActionSystemTestCase < ActionSystemTest::Base
+class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
teardown do
take_failed_screenshot
Capybara.reset_sessions!
diff --git a/railties/lib/rails/generators/test_unit/system/templates/system_test.rb b/railties/lib/rails/generators/test_unit/system/templates/system_test.rb
index bc3abd25d9..2afc7a4aac 100644
--- a/railties/lib/rails/generators/test_unit/system/templates/system_test.rb
+++ b/railties/lib/rails/generators/test_unit/system/templates/system_test.rb
@@ -1,7 +1,9 @@
require "system_test_helper"
-class <%= class_name.pluralize %>Test < ActionSystemTestCase
- # test 'the truth' do
- # assert true
+class <%= class_name.pluralize %>Test < ApplicationSystemTestCase
+ # test "visiting the index" do
+ # visit <%= plural_table_name %>_url
+ #
+ # assert_selector "h1", text: "<%= class_name %>"
# end
end
diff --git a/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb b/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb
index 77c4738d6f..1d0ae787f7 100644
--- a/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb
+++ b/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb
@@ -1,6 +1,6 @@
require "test_helper"
-class ActionSystemTestCase < ActionSystemTest::Base
+class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
teardown do
take_failed_screenshot
Capybara.reset_sessions!
diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb
index 98bfddb197..75171f2395 100644
--- a/railties/lib/rails/test_help.rb
+++ b/railties/lib/rails/test_help.rb
@@ -7,7 +7,7 @@ require "active_support/test_case"
require "action_controller"
require "action_controller/test_case"
require "action_dispatch/testing/integration"
-require "action_system_test"
+require "action_dispatch/system_test_case"
require "rails/generators/test_case"
require "active_support/testing/autorun"
@@ -46,7 +46,7 @@ class ActionDispatch::IntegrationTest
end
end
-class ActionSystemTest::Base
+class ActionDispatch::SystemTestCase
def before_setup # :nodoc:
@routes = Rails.application.routes
super
diff --git a/railties/railties.gemspec b/railties/railties.gemspec
index fb8e666f40..76de2b4639 100644
--- a/railties/railties.gemspec
+++ b/railties/railties.gemspec
@@ -25,7 +25,6 @@ Gem::Specification.new do |s|
s.add_dependency "activesupport", version
s.add_dependency "actionpack", version
- s.add_dependency "actionsystemtest", version
s.add_dependency "rake", ">= 0.8.7"
s.add_dependency "thor", ">= 0.18.1", "< 2.0"
diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb
index 43b8ce99ed..436fbd5d73 100644
--- a/railties/test/generators/scaffold_generator_test.rb
+++ b/railties/test/generators/scaffold_generator_test.rb
@@ -64,7 +64,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
# System tests
assert_file "test/system/product_lines_test.rb" do |test|
- assert_match(/class ProductLinesTest < ActionSystemTestCase/, test)
+ assert_match(/class ProductLinesTest < ApplicationSystemTestCase/, test)
end
# Views
diff --git a/railties/test/generators/system_test_generator_test.rb b/railties/test/generators/system_test_generator_test.rb
index b6cf75b586..e8e561ec49 100644
--- a/railties/test/generators/system_test_generator_test.rb
+++ b/railties/test/generators/system_test_generator_test.rb
@@ -7,6 +7,6 @@ class SystemTestGeneratorTest < Rails::Generators::TestCase
def test_system_test_skeleton_is_created
run_generator
- assert_file "test/system/users_test.rb", /class UsersTest < ActionSystemTestCase/
+ assert_file "test/system/users_test.rb", /class UsersTest < ApplicationSystemTestCase/
end
end