aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2016-08-05 09:36:54 -0400
committereileencodes <eileencodes@gmail.com>2017-02-20 15:07:31 -0500
commit5b9aa43bc8dafcc2a00eb43741c495262f5ca45e (patch)
treea7e843d12987cf033c4d5601dff3abc6ca05e2e6 /railties/lib
parente9abbb700acd8165a8994d8b2a700e507fb3b7ff (diff)
downloadrails-5b9aa43bc8dafcc2a00eb43741c495262f5ca45e.tar.gz
rails-5b9aa43bc8dafcc2a00eb43741c495262f5ca45e.tar.bz2
rails-5b9aa43bc8dafcc2a00eb43741c495262f5ca45e.zip
Add generators and ability to run system tests
* Generates system test requirements with new Rails app * Includes required default gems in Gemfile for Rails app * Generates a single system test case * Generates a system test case with scaffold
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/rails/generators.rb2
-rw-r--r--railties/lib/rails/generators/app_base.rb3
-rw-r--r--railties/lib/rails/generators/rails/app/app_generator.rb8
-rw-r--r--railties/lib/rails/generators/rails/app/templates/Gemfile5
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/application.rb1
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/rails/application.rb1
-rw-r--r--railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb2
-rw-r--r--railties/lib/rails/generators/rails/system_test/USAGE10
-rw-r--r--railties/lib/rails/generators/rails/system_test/system_test_generator.rb7
-rw-r--r--railties/lib/rails/generators/test_unit/system/system_generator.rb13
-rw-r--r--railties/lib/rails/generators/test_unit/system/templates/system_test.rb7
-rw-r--r--railties/lib/rails/tasks/statistics.rake1
-rw-r--r--railties/lib/rails/test_unit/railtie.rb1
-rw-r--r--railties/lib/rails/test_unit/testing.rake5
14 files changed, 66 insertions, 0 deletions
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index 99bda728ee..cbcbe70fdd 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -53,6 +53,7 @@ module Rails
force_plural: false,
helper: true,
integration_tool: nil,
+ system_tool: nil,
javascripts: true,
javascript_engine: :js,
orm: false,
@@ -151,6 +152,7 @@ module Rails
"#{test}:controller",
"#{test}:helper",
"#{test}:integration",
+ "#{test}:system",
"#{test}:mailer",
"#{test}:model",
"#{test}:scaffold",
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb
index ea88afe9f4..e55da93f45 100644
--- a/railties/lib/rails/generators/app_base.rb
+++ b/railties/lib/rails/generators/app_base.rb
@@ -82,6 +82,9 @@ module Rails
class_option :skip_test, type: :boolean, aliases: "-T", default: false,
desc: "Skip test files"
+ class_option :skip_system_test, type: :boolean, default: false,
+ desc: "Skip system test files"
+
class_option :dev, type: :boolean, default: false,
desc: "Setup the #{name} with Gemfile pointing to your Rails checkout"
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb
index 3cf923faf0..00839c5d4c 100644
--- a/railties/lib/rails/generators/rails/app/app_generator.rb
+++ b/railties/lib/rails/generators/rails/app/app_generator.rb
@@ -150,6 +150,10 @@ module Rails
template "test/test_helper.rb"
end
+ def system_test
+ empty_directory_with_keep_file "test/system"
+ end
+
def tmp
empty_directory_with_keep_file "tmp"
empty_directory "tmp/cache"
@@ -262,6 +266,10 @@ module Rails
build(:test) unless options[:skip_test]
end
+ def create_system_test_files
+ build(:system_test) unless options[:skip_system_test] || options[:skip_test] || options[:api]
+ end
+
def create_tmp_files
build(:tmp)
end
diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile
index 24d2fa1284..b082d70cba 100644
--- a/railties/lib/rails/generators/rails/app/templates/Gemfile
+++ b/railties/lib/rails/generators/rails/app/templates/Gemfile
@@ -32,6 +32,11 @@ end
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
+ <%- unless options.skip_system_test? || options.api? -%>
+ # Adds support for Capybara system testing and selenium driver
+ gem 'capybara', '~> 2.7.0'
+ gem 'selenium-webdriver'
+ <%- end -%>
end
group :development do
diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb
index c0a0bd0a3e..2488c79da3 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/application.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb
@@ -14,6 +14,7 @@ require "action_view/railtie"
<%= comment_if :skip_action_cable %>require "action_cable/engine"
<%= comment_if :skip_sprockets %>require "sprockets/railtie"
<%= comment_if :skip_test %>require "rails/test_unit/railtie"
+<%= comment_if :skip_system_test %>require "system_testing/railtie"
<% end -%>
# Require the gems listed in Gemfile, including any gems
diff --git a/railties/lib/rails/generators/rails/plugin/templates/rails/application.rb b/railties/lib/rails/generators/rails/plugin/templates/rails/application.rb
index d03b1be878..2dc9cc67a6 100644
--- a/railties/lib/rails/generators/rails/plugin/templates/rails/application.rb
+++ b/railties/lib/rails/generators/rails/plugin/templates/rails/application.rb
@@ -11,6 +11,7 @@ require "action_view/railtie"
require "active_job/railtie"
<%= comment_if :skip_action_cable %>require "action_cable/engine"
<%= comment_if :skip_test %>require "rails/test_unit/railtie"
+<%= comment_if :skip_system_test %>require "system_testing/railtie"
<%= comment_if :skip_sprockets %>require "sprockets/railtie"
<% end -%>
diff --git a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
index ed6bf7f7d7..bcaa424ca8 100644
--- a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
+++ b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
@@ -19,6 +19,8 @@ module Rails
hook_for :scaffold_controller, required: true
+ hook_for :system_tool, as: :system
+
hook_for :assets do |assets|
invoke assets, [controller_name]
end
diff --git a/railties/lib/rails/generators/rails/system_test/USAGE b/railties/lib/rails/generators/rails/system_test/USAGE
new file mode 100644
index 0000000000..f11a99e008
--- /dev/null
+++ b/railties/lib/rails/generators/rails/system_test/USAGE
@@ -0,0 +1,10 @@
+Description:
+ Stubs out a new system test. Pass the name of the test, either
+ CamelCased or under_scored, as an argument.
+
+ This generator invokes the current system tool, which defaults to
+ TestUnit.
+
+Example:
+ `rails generate system_test GeneralStories` creates a GeneralStories
+ system test in test/system/general_stories_test.rb
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
new file mode 100644
index 0000000000..35bc168898
--- /dev/null
+++ b/railties/lib/rails/generators/rails/system_test/system_test_generator.rb
@@ -0,0 +1,7 @@
+module Rails
+ module Generators
+ class SystemTestGenerator < NamedBase # :nodoc:
+ hook_for :system_tool, 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
new file mode 100644
index 0000000000..4d3b37e645
--- /dev/null
+++ b/railties/lib/rails/generators/test_unit/system/system_generator.rb
@@ -0,0 +1,13 @@
+require 'rails/generators/test_unit'
+
+module TestUnit # :nodoc:
+ module Generators # :nodoc:
+ class SystemGenerator < Base # :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")
+ end
+ 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
new file mode 100644
index 0000000000..75825c880d
--- /dev/null
+++ b/railties/lib/rails/generators/test_unit/system/templates/system_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class <%= class_name.pluralize %>Test < Rails::SystemTestCase
+ # test 'the truth' do
+ # assert true
+ # end
+end
diff --git a/railties/lib/rails/tasks/statistics.rake b/railties/lib/rails/tasks/statistics.rake
index ba1697186e..cb569be58b 100644
--- a/railties/lib/rails/tasks/statistics.rake
+++ b/railties/lib/rails/tasks/statistics.rake
@@ -17,6 +17,7 @@ STATS_DIRECTORIES = [
%w(Mailer\ tests test/mailers),
%w(Job\ tests test/jobs),
%w(Integration\ tests test/integration),
+ %w(System\ tests test/system),
].collect do |name, dir|
[ name, "#{File.dirname(Rake.application.rakefile_location)}/#{dir}" ]
end.select { |name, dir| File.directory?(dir) }
diff --git a/railties/lib/rails/test_unit/railtie.rb b/railties/lib/rails/test_unit/railtie.rb
index 746120e6a1..d3f52e8008 100644
--- a/railties/lib/rails/test_unit/railtie.rb
+++ b/railties/lib/rails/test_unit/railtie.rb
@@ -11,6 +11,7 @@ module Rails
fixture_replacement: nil
c.integration_tool :test_unit
+ c.system_tool :test_unit
end
initializer "test_unit.line_filtering" do
diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake
index 4c157c1262..4dde3d3c97 100644
--- a/railties/lib/rails/test_unit/testing.rake
+++ b/railties/lib/rails/test_unit/testing.rake
@@ -47,4 +47,9 @@ namespace :test do
$: << "test"
Minitest.rake_run(["test/controllers", "test/mailers", "test/functional"])
end
+
+ task system: "test:prepare" do
+ $: << "test"
+ Minitest.rake_run(["test/system"])
+ end
end