Permalink
Browse files

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
  • Loading branch information...
eileencodes committed Aug 5, 2016
1 parent e9abbb7 commit 5b9aa43bc8dafcc2a00eb43741c495262f5ca45e
@@ -53,6 +53,7 @@ module Generators
force_plural: false,
helper: true,
integration_tool: nil,
+ system_tool: nil,
javascripts: true,
javascript_engine: :js,
orm: false,
@@ -151,6 +152,7 @@ def hidden_namespaces
"#{test}:controller",
"#{test}:helper",
"#{test}:integration",
+ "#{test}:system",
"#{test}:mailer",
"#{test}:model",
"#{test}:scaffold",
@@ -82,6 +82,9 @@ def self.add_shared_options_for(name)
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"
@@ -150,6 +150,10 @@ def test
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 @@ def create_test_files
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
@@ -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
@@ -14,6 +14,7 @@
<%= 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
@@ -11,6 +11,7 @@
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 -%>
@@ -19,6 +19,8 @@ def handle_skip
hook_for :scaffold_controller, required: true
+ hook_for :system_tool, as: :system
+
hook_for :assets do |assets|
invoke assets, [controller_name]
end
@@ -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
@@ -0,0 +1,7 @@
+module Rails
+ module Generators
+ class SystemTestGenerator < NamedBase # :nodoc:
+ hook_for :system_tool, as: :system
+ end
+ end
+end
@@ -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
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class <%= class_name.pluralize %>Test < Rails::SystemTestCase
+ # test 'the truth' do
+ # assert true
+ # end
+end
@@ -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) }
@@ -11,6 +11,7 @@ class TestUnitRailtie < Rails::Railtie
fixture_replacement: nil
c.integration_tool :test_unit
+ c.system_tool :test_unit
end
initializer "test_unit.line_filtering" do
@@ -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

0 comments on commit 5b9aa43

Please sign in to comment.