1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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
This commit is contained in:
eileencodes 2017-02-19 11:50:42 -05:00
parent 0a683085b1
commit 1a0ca84a06
37 changed files with 298 additions and 519 deletions

View file

@ -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 file

@ -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 file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -1,3 +0,0 @@
* Added to Rails!
*Eileen M. Uchitelle*

View file

@ -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.

View file

@ -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
```

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -24,7 +24,6 @@ class Build
"av" => "actionview",
"aj" => "activejob",
"ac" => "actioncable",
"ast" => "actionsystemtest",
"guides" => "guides"
}

View file

@ -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"

View file

@ -1,6 +1,6 @@
require "test_helper"
class ActionSystemTestCase < ActionSystemTest::Base
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
teardown do
take_failed_screenshot
Capybara.reset_sessions!

View file

@ -1,6 +1,6 @@
require "test_helper"
class ActionSystemTestCase < ActionSystemTest::Base
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
teardown do
take_failed_screenshot
Capybara.reset_sessions!

View file

@ -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

View file

@ -1,6 +1,6 @@
require "test_helper"
class ActionSystemTestCase < ActionSystemTest::Base
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
teardown do
take_failed_screenshot
Capybara.reset_sessions!

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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