Permalink
Browse files

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.
  • Loading branch information...
eileencodes committed Nov 6, 2016
1 parent a21e18d commit 5bf0aa6745db27c45c0778f9f6e9046f9ee9fb94
Showing with 398 additions and 219 deletions.
  1. +1 −1 .travis.yml
  2. +6 −2 Gemfile.lock
  3. +0 −1 actionpack/actionpack.gemspec
  4. +0 −57 actionpack/lib/system_test_case.rb
  5. +0 −1 actionpack/test/abstract_unit.rb
  6. +0 −39 actionpack/test/system_testing/capybara_driver_test.rb
  7. +0 −58 actionpack/test/system_testing/rails_selenium_driver_test.rb
  8. +0 −20 actionpack/test/system_testing/screenshot_helper_test.rb
  9. +3 −0 actionsystemtest/CHANGELOG.md
  10. +20 −0 actionsystemtest/MIT-LICENSE
  11. +108 −0 actionsystemtest/README.md
  12. +32 −0 actionsystemtest/Rakefile
  13. +24 −0 actionsystemtest/actionsystemtest.gemspec
  14. +59 −0 actionsystemtest/lib/action_system_test.rb
  15. +3 −3 {actionpack/lib/system_testing → actionsystemtest/lib/action_system_test}/driver_adapter.rb
  16. +3 −3 {actionpack/lib/system_testing → actionsystemtest/lib/action_system_test}/driver_adapters.rb
  17. +4 −4 .../lib/system_testing → actionsystemtest/lib/action_system_test}/driver_adapters/capybara_driver.rb
  18. +6 −6 ...ystem_testing → actionsystemtest/lib/action_system_test}/driver_adapters/rails_selenium_driver.rb
  19. +2 −2 ...npack/lib/system_testing → actionsystemtest/lib/action_system_test}/driver_adapters/web_server.rb
  20. +15 −0 actionsystemtest/lib/action_system_test/gem_version.rb
  21. +3 −3 {actionpack/lib/system_testing → actionsystemtest/lib/action_system_test}/railtie.rb
  22. +2 −2 {actionpack/lib/system_testing → actionsystemtest/lib/action_system_test}/test_helper.rb
  23. +1 −1 {actionpack/lib/system_testing → actionsystemtest/lib/action_system_test}/test_helpers.rb
  24. +1 −1 {actionpack/lib/system_testing → actionsystemtest/lib/action_system_test}/test_helpers/assertions.rb
  25. +1 −1 ...ionpack/lib/system_testing → actionsystemtest/lib/action_system_test}/test_helpers/form_helper.rb
  26. +3 −3 ...k/lib/system_testing → actionsystemtest/lib/action_system_test}/test_helpers/screenshot_helper.rb
  27. +8 −0 actionsystemtest/lib/action_system_test/version.rb
  28. +13 −0 actionsystemtest/test/abstract_unit.rb
  29. +39 −0 actionsystemtest/test/cases/capybara_driver_test.rb
  30. +2 −2 {actionpack/test/system_testing → actionsystemtest/test/cases}/driver_adapter_test.rb
  31. +11 −0 actionsystemtest/test/cases/rails_selenium_driver_test.rb
  32. +20 −0 actionsystemtest/test/cases/screenshot_helper_test.rb
  33. +1 −1 ci/travis.rb
  34. +1 −1 railties/lib/rails/all.rb
  35. +0 −1 railties/lib/rails/generators/rails/app/templates/config/application.rb
  36. +0 −1 railties/lib/rails/generators/rails/plugin/templates/rails/application.rb
  37. +1 −1 railties/lib/rails/generators/test_unit/system/templates/system_test.rb
  38. +2 −2 railties/lib/rails/test_help.rb
  39. +1 −0 railties/railties.gemspec
  40. +1 −1 railties/test/generators/scaffold_generator_test.rb
  41. +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"
+ - "GEM=am,amo,as,av,aj,ast"
- "GEM=as PRESERVE_TIMEZONES=1"
- "GEM=ar:mysql2"
- "GEM=ar:sqlite3"
View
@@ -45,11 +45,14 @@ PATH
actionpack (5.1.0.alpha)
actionview (= 5.1.0.alpha)
activesupport (= 5.1.0.alpha)
- capybara (~> 2.7.0)
rack (~> 2.0)
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)
@@ -84,6 +87,7 @@ 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)
@@ -126,7 +130,7 @@ GEM
bunny (2.6.2)
amq-protocol (>= 2.0.1)
byebug (9.0.6)
- capybara (2.7.0)
+ capybara (2.7.1)
addressable
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
@@ -26,7 +26,6 @@ Gem::Specification.new do |s|
s.add_dependency "rails-html-sanitizer", "~> 1.0", ">= 1.0.2"
s.add_dependency "rails-dom-testing", "~> 2.0"
s.add_dependency "actionview", version
- s.add_dependency "capybara", "~> 2.7.0"
s.add_development_dependency "activemodel", version
end
@@ -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
@@ -33,7 +33,6 @@
require "action_dispatch"
require "active_support/dependencies"
require "active_model"
-require "system_test_case"
require "pp" # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late
@@ -1,39 +0,0 @@
-require "abstract_unit"
-
-class CapybaraDriverTest < ActiveSupport::TestCase
- def setup
- Rails::SystemTestCase.driver = :poltergeist
- end
-
- def test_default_driver_adapter
- assert_kind_of SystemTesting::DriverAdapters::CapybaraDriver, Rails::SystemTestCase.driver
- end
-
- def test_default_settings
- assert_equal :poltergeist, Rails::SystemTestCase.driver.name
- assert_equal :puma, Rails::SystemTestCase.driver.server
- assert_equal 28100, Rails::SystemTestCase.driver.port
- end
-
- def test_setting_driver
- Rails::SystemTestCase.driver = :webkit
-
- assert_equal :webkit, Rails::SystemTestCase.driver.name
- end
-
- def test_setting_server
- Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraDriver.new(
- server: :webrick
- )
-
- assert_equal :webrick, Rails::SystemTestCase.driver.server
- end
-
- def test_setting_port
- Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraDriver.new(
- port: 3000
- )
-
- assert_equal 3000, Rails::SystemTestCase.driver.port
- end
-end
@@ -1,58 +0,0 @@
-require "abstract_unit"
-
-class RailsSeleniumDriverTest < ActiveSupport::TestCase
- def setup
- Rails::SystemTestCase.driver = :rails_selenium_driver
- end
-
- def test_default_driver_adapter
- assert_kind_of SystemTesting::DriverAdapters::RailsSeleniumDriver, Rails::SystemTestCase.driver
- end
-
- def test_default_settings
- assert_equal :chrome, Rails::SystemTestCase.driver.browser
- assert_equal :puma, Rails::SystemTestCase.driver.server
- assert_equal 28100, Rails::SystemTestCase.driver.port
- assert_equal [1400,1400], Rails::SystemTestCase.driver.screen_size
- end
-
- def test_setting_browser
- Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::RailsSeleniumDriver.new(
- browser: :firefox
- )
-
- assert_equal :firefox, Rails::SystemTestCase.driver.browser
- end
-
- def test_setting_server
- Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::RailsSeleniumDriver.new(
- server: :webrick
- )
-
- assert_equal :webrick, Rails::SystemTestCase.driver.server
- end
-
- def test_setting_port
- Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::RailsSeleniumDriver.new(
- port: 3000
- )
-
- assert_equal 3000, Rails::SystemTestCase.driver.port
- end
-
- def test_setting_screen_size
- Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::RailsSeleniumDriver.new(
- screen_size: [ 800, 800 ]
- )
-
- assert_equal [ 800, 800 ], Rails::SystemTestCase.driver.screen_size
- end
-
- def test_does_not_accept_nonsense_kwargs
- assert_raises ArgumentError do
- Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::RailsSeleniumDriver.new(
- made_up_arg: "x"
- )
- end
- end
-end
@@ -1,20 +0,0 @@
-require "abstract_unit"
-
-class ScreenshotHelperTest < ActiveSupport::TestCase
- def test_driver_support_for_screenshots
- Rails::SystemTestCase.driver = :rails_selenium_driver
- assert Rails::SystemTestCase.driver.supports_screenshots?
-
- Rails::SystemTestCase.driver = :rack_test
- assert_not Rails::SystemTestCase.driver.supports_screenshots?
-
- Rails::SystemTestCase.driver = :selenium
- assert Rails::SystemTestCase.driver.supports_screenshots?
-
- Rails::SystemTestCase.driver = :webkit
- assert Rails::SystemTestCase.driver.supports_screenshots?
-
- Rails::SystemTestCase.driver = :poltergeist
- assert Rails::SystemTestCase.driver.supports_screenshots?
- end
-end
@@ -0,0 +1,3 @@
+* Added to Rails!
+
+ *Eileen M. Uchitelle*
@@ -0,0 +1,20 @@
+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
@@ -0,0 +1,108 @@
+# Action System Test
+
+Action System Test adds Capybara integration to your Rails application for
+acceptance testing. This allows you to test the entire user experience
+of your application rather than just your controllers, or just your models.
+
+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".
+
+For more helpers and how to write Capybara tests visit Capybara's README.
+
+### 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.
+
+Rails preset configuration for Capybara with Selenium defaults to Puma for
+the web server on port 28100, Chrome for the browser, and a screen size of
+1400 x 1400.
+
+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
+configuration options you can initialize a new <tt>RailsSeleniumDriver</tt>
+object.
+
+```ruby
+class ActionSystemTestCase < ActionSystemTest::Base
+ ActionSystemTest.driver = RailsSeleniumDriver.new(
+ browser: :firefox,
+ server: :webrick
+ )
+end
+```
+
+Capybara itself provides 4 drivers: RackTest, Selenium, Webkit, and Poltergeist.
+Action System Test provides a shim between Rails and Capybara for these 4 drivers.
+Please note, that Rails is set up to use the Puma server by default for these
+4 drivers. Puma is the default in Rails and therefore is set as the default in
+the Rails Capybara integration.
+
+To set your application tests to use any of Capybara's defaults with no configuration,
+set the following in your <tt>system_test_helper.rb</tt> file and follow setup instructions
+for environment requirements of these drivers.
+
+The possible settings are +:rack_test+, +:selenium+, +:webkit+, or +:poltergeist+.
+
+```ruby
+class ActionSystemTestCase < ActionSystemTest::Base
+ ActionSystemTest.driver = :poltergeist
+end
+```
+
+If you want to change the default server (puma) or port (28100) for Capbyara drivers
+you can initialize a new object.
+
+```ruby
+class ActionSystemTestCase < ActionSystemTest::Base
+ ActionSystemTest.driver = ActionSystemTest::DriverAdapters::CapybaraDriver.new(
+ name: :poltergeist,
+ server: :webkit,
+ port: 3000
+ )
+end
+```
Oops, something went wrong.

0 comments on commit 5bf0aa6

Please sign in to comment.