diff options
15 files changed, 72 insertions, 47 deletions
diff --git a/actionsystemtest/lib/action_system_test.rb b/actionsystemtest/lib/action_system_test.rb index 18b992a3ca..f9fb8b4e5c 100644 --- a/actionsystemtest/lib/action_system_test.rb +++ b/actionsystemtest/lib/action_system_test.rb @@ -1,20 +1,16 @@ -require "action_system_test/test_helper" -require "action_system_test/driver_adapter" - # 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 +# To create a System Test in your application, extend your test class from # <tt>ActionSystemTestCase</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. +# allow you to configure the driver. The default driver is +# <tt>RailsSeleniumDriver</tt> which provides a Capybara and the Selenium +# Driver with no configuration. It's intended to work out of the box. # # A system test looks like the following: # -# require 'test_helper' +# require 'system_test_helper' # # class Users::CreateTest < ActionSystemTestCase # def adding_a_new_user @@ -28,17 +24,23 @@ require "action_system_test/driver_adapter" # end # end # -# System test driver can be configured in your Rails configuration file for the -# test environment. +# 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. # -# config.system_testing.driver = :rails_selenium_driver +# class ActionSystemTestCase < ActionSystemTest::Base +# ActionSystemTest.driver = :rack_test +# end # # 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 = ActionSystemTest::DriverAdapters::RailsSeleniumDriver.new( -# browser: :firefox -# ) +# class ActionSystemTestCase < ActionSystemTest::Base +# ActionSystemTest.driver = ActionSystemTest::DriverAdapters::RailsSeleniumDriver.new( +# browser: :firefox +# ) +# end # # A list of supported adapters can be found in DriverAdapters. # @@ -47,11 +49,19 @@ require "action_system_test/driver_adapter" # +: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. + +require "action_system_test/test_helper" +require "action_system_test/driver_adapter" + module ActionSystemTest include ActionSystemTest::TestHelper include ActionSystemTest::DriverAdapter -end -class ActionSystemTestCase < ActionDispatch::IntegrationTest - include ActionSystemTest + DEFAULT_DRIVER = :rails_selenium_driver + + class Base < ActionDispatch::IntegrationTest + include ActionSystemTest + + ActionSystemTest.driver = DEFAULT_DRIVER + end end diff --git a/actionsystemtest/lib/action_system_test/driver_adapter.rb b/actionsystemtest/lib/action_system_test/driver_adapter.rb index fe12ecaf80..892edd2d32 100644 --- a/actionsystemtest/lib/action_system_test/driver_adapter.rb +++ b/actionsystemtest/lib/action_system_test/driver_adapter.rb @@ -9,15 +9,11 @@ module ActionSystemTest extend ActiveSupport::Concern module ClassMethods - def default_driver # :nodoc - :rails_selenium_driver - end - # Returns the current driver that is set. If no driver is set in the # Rails' configuration file then +:rails_selenium_driver+ will be # initialized. def driver - @driver ||= DriverAdapters.lookup(default_driver) + @driver ||= DriverAdapters.lookup(DEFAULT_DRIVER) end # Specify the adapter and settings for the system test driver set in the diff --git a/actionsystemtest/lib/action_system_test/test_helper.rb b/actionsystemtest/lib/action_system_test/test_helper.rb index 428f0faeca..c9389b83ec 100644 --- a/actionsystemtest/lib/action_system_test/test_helper.rb +++ b/actionsystemtest/lib/action_system_test/test_helper.rb @@ -15,7 +15,6 @@ module ActionSystemTest end def after_teardown - take_screenshot if supported? Capybara.reset_sessions! super 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 index 37336e976f..3264ddc86e 100644 --- a/actionsystemtest/lib/action_system_test/test_helpers/screenshot_helper.rb +++ b/actionsystemtest/lib/action_system_test/test_helpers/screenshot_helper.rb @@ -18,11 +18,11 @@ module ActionSystemTest puts find_image end - private - def supported? - ActionSystemTest.driver.supports_screenshots? && !passed? - end + def take_failed_screenshot + take_screenshot unless passed? + end + private def image_path path = "tmp/screenshots/failures_#{method_name}.png" page.save_screenshot(Rails.root.join(path)) diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index cbcbe70fdd..85f66cc416 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -53,7 +53,6 @@ module Rails force_plural: false, helper: true, integration_tool: nil, - system_tool: nil, javascripts: true, javascript_engine: :js, orm: false, @@ -63,6 +62,7 @@ module Rails stylesheets: true, stylesheet_engine: :css, scaffold_stylesheet: true, + system_tests: nil, test_framework: false, template_engine: :erb } diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 00839c5d4c..acdb66ca85 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -152,6 +152,8 @@ module Rails def system_test empty_directory_with_keep_file "test/system" + + template "test/system_test_helper.rb" end def tmp 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 new file mode 100644 index 0000000000..77c4738d6f --- /dev/null +++ b/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb @@ -0,0 +1,8 @@ +require "test_helper" + +class ActionSystemTestCase < ActionSystemTest::Base + teardown do + take_failed_screenshot + Capybara.reset_sessions! + end +end 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 new file mode 100644 index 0000000000..77c4738d6f --- /dev/null +++ b/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb @@ -0,0 +1,8 @@ +require "test_helper" + +class ActionSystemTestCase < ActionSystemTest::Base + teardown do + take_failed_screenshot + Capybara.reset_sessions! + end +end diff --git a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb index bcaa424ca8..12d6bc85b2 100644 --- a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb @@ -6,6 +6,7 @@ module Rails remove_hook_for :resource_controller remove_class_option :actions + class_option :api, type: :boolean class_option :stylesheets, type: :boolean, desc: "Generate Stylesheets" class_option :stylesheet_engine, desc: "Engine for Stylesheets" class_option :assets, type: :boolean @@ -15,11 +16,12 @@ module Rails def handle_skip @options = @options.merge(stylesheets: false) unless options[:assets] @options = @options.merge(stylesheet_engine: false) unless options[:stylesheets] && options[:scaffold_stylesheet] + @options = @options.merge(system_tests: false) if options[:api] end hook_for :scaffold_controller, required: true - hook_for :system_tool, as: :system + hook_for :system_tests, as: :system hook_for :assets do |assets| invoke assets, [controller_name] diff --git a/railties/lib/rails/generators/rails/system_test/system_test_generator.rb b/railties/lib/rails/generators/rails/system_test/system_test_generator.rb index 35bc168898..901120e892 100644 --- a/railties/lib/rails/generators/rails/system_test/system_test_generator.rb +++ b/railties/lib/rails/generators/rails/system_test/system_test_generator.rb @@ -1,7 +1,7 @@ module Rails module Generators class SystemTestGenerator < NamedBase # :nodoc: - hook_for :system_tool, as: :system + hook_for :system_tests, as: :system end end end diff --git a/railties/lib/rails/generators/test_unit/system/system_generator.rb b/railties/lib/rails/generators/test_unit/system/system_generator.rb index a05f0f924d..e77ccef009 100644 --- a/railties/lib/rails/generators/test_unit/system/system_generator.rb +++ b/railties/lib/rails/generators/test_unit/system/system_generator.rb @@ -6,7 +6,11 @@ module TestUnit # :nodoc: check_class_collision suffix: "Test" def create_test_files - template "system_test.rb", File.join("test/system", class_path, "#{file_name.pluralize}_test.rb") + if !File.exist?(File.join("test/system_test_helper.rb")) + template "system_test_helper.rb", File.join("test", "system_test_helper.rb") + end + + template "system_test.rb", File.join("test/system", "#{file_name.pluralize}_test.rb") end end end 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 a74e0bb23d..bc3abd25d9 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,4 +1,4 @@ -require 'test_helper' +require "system_test_helper" class <%= class_name.pluralize %>Test < ActionSystemTestCase # test 'the truth' do 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 new file mode 100644 index 0000000000..77c4738d6f --- /dev/null +++ b/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb @@ -0,0 +1,8 @@ +require "test_helper" + +class ActionSystemTestCase < ActionSystemTest::Base + teardown do + take_failed_screenshot + Capybara.reset_sessions! + end +end diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb index 68fc317a60..98bfddb197 100644 --- a/railties/lib/rails/test_help.rb +++ b/railties/lib/rails/test_help.rb @@ -46,7 +46,7 @@ class ActionDispatch::IntegrationTest end end -class ActionSystemTestCase +class ActionSystemTest::Base def before_setup # :nodoc: @routes = Rails.application.routes super diff --git a/railties/lib/rails/test_unit/railtie.rb b/railties/lib/rails/test_unit/railtie.rb index 694c8d92b1..9cc3f73a9c 100644 --- a/railties/lib/rails/test_unit/railtie.rb +++ b/railties/lib/rails/test_unit/railtie.rb @@ -11,7 +11,7 @@ module Rails fixture_replacement: nil c.integration_tool :test_unit - c.system_tool :test_unit + c.system_tests :test_unit end initializer "test_unit.line_filtering" do @@ -20,18 +20,6 @@ module Rails } end - config.system_testing = ActiveSupport::OrderedOptions.new - - initializer "system_testing.set_configs" do |app| - ActiveSupport.on_load(:active_support_test_case) do - require "action_system_test" - - options = app.config.system_testing - options.driver ||= ActionSystemTest.default_driver - options.each { |k, v| ActionSystemTest.send("#{k}=", v) } - end - end - rake_tasks do load "rails/test_unit/testing.rake" end |