diff options
author | eileencodes <eileencodes@gmail.com> | 2016-11-12 09:49:28 -0500 |
---|---|---|
committer | eileencodes <eileencodes@gmail.com> | 2017-02-20 15:07:33 -0500 |
commit | 84f82f0a84de0906d195b529a9f780141c43507a (patch) | |
tree | f2919614c9ce8f0adccdfd83e47d43f6484d17bc /railties/lib/rails | |
parent | 1db7a5c285eeb61acc998c0c27788a61bd948d5c (diff) | |
download | rails-84f82f0a84de0906d195b529a9f780141c43507a.tar.gz rails-84f82f0a84de0906d195b529a9f780141c43507a.tar.bz2 rails-84f82f0a84de0906d195b529a9f780141c43507a.zip |
Refactor config settings to use generated file
Originally I had set up system testing to have one configuration option
to be set in the test environment. After thinking it over I think a
generated class on app creation would be best. The reason for this is
Capybara has a ton of configuration options that I'm sure some folks
want to use.
Thinking about how we handle screenshots, database transactions, and a
whole bunch of other settings it would be better for users to be able to
turn all of that on and off.
When an app or scaffold is generated a `test/system_test_helper.rb` test
helper will be generated as well. This will contain the class for tests
to inherit from `ActionSystemTestCase` which will inherit from
`ActionSystemTest::Base`. Here is where users can change the test
driver, remove the screenshot helper, and add their additional Capybara
configuration.
Diffstat (limited to 'railties/lib/rails')
11 files changed, 39 insertions, 19 deletions
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 |