aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/generators/plugin_generator_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/test/generators/plugin_generator_test.rb')
-rw-r--r--railties/test/generators/plugin_generator_test.rb105
1 files changed, 52 insertions, 53 deletions
diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb
index 823dcc50ee..0d8e6f8907 100644
--- a/railties/test/generators/plugin_generator_test.rb
+++ b/railties/test/generators/plugin_generator_test.rb
@@ -1,6 +1,6 @@
-require 'generators/generators_test_helper'
-require 'rails/generators/rails/plugin/plugin_generator'
-require 'generators/shared_generator_tests'
+require "generators/generators_test_helper"
+require "rails/generators/rails/plugin/plugin_generator"
+require "generators/shared_generator_tests"
DEFAULT_PLUGIN_FILES = %w(
.gitignore
@@ -27,19 +27,19 @@ class PluginGeneratorTest < Rails::Generators::TestCase
include SharedGeneratorTests
def test_invalid_plugin_name_raises_an_error
- content = capture(:stderr){ run_generator [File.join(destination_root, "my_plugin-31fr-extension")] }
+ content = capture(:stderr) { run_generator [File.join(destination_root, "my_plugin-31fr-extension")] }
assert_equal "Invalid plugin name my_plugin-31fr-extension. Please give a name which does not contain a namespace starting with numeric characters.\n", content
- content = capture(:stderr){ run_generator [File.join(destination_root, "things4.3")] }
+ content = capture(:stderr) { run_generator [File.join(destination_root, "things4.3")] }
assert_equal "Invalid plugin name things4.3. Please give a name which uses only alphabetic, numeric, \"_\" or \"-\" characters.\n", content
- content = capture(:stderr){ run_generator [File.join(destination_root, "43things")] }
+ content = capture(:stderr) { run_generator [File.join(destination_root, "43things")] }
assert_equal "Invalid plugin name 43things. Please give a name which does not start with numbers.\n", content
- content = capture(:stderr){ run_generator [File.join(destination_root, "plugin")] }
+ content = capture(:stderr) { run_generator [File.join(destination_root, "plugin")] }
assert_equal "Invalid plugin name plugin. Please give a name which does not match one of the reserved rails words: application, destroy, plugin, runner, test\n", content
- content = capture(:stderr){ run_generator [File.join(destination_root, "Digest")] }
+ content = capture(:stderr) { run_generator [File.join(destination_root, "Digest")] }
assert_equal "Invalid plugin name Digest, constant Digest is already in use. Please choose another plugin name.\n", content
end
@@ -68,8 +68,8 @@ class PluginGeneratorTest < Rails::Generators::TestCase
assert_match(/Rails::TestUnitReporter\.executable = 'bin\/test'/, content)
end
assert_file "test/bukkits_test.rb", /assert_kind_of Module, Bukkits/
- assert_file 'bin/test'
- assert_no_file 'bin/rails'
+ assert_file "bin/test"
+ assert_no_file "bin/rails"
end
def test_generating_test_files_in_full_mode
@@ -80,7 +80,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase
end
def test_inclusion_of_a_debugger
- run_generator [destination_root, '--full']
+ run_generator [destination_root, "--full"]
if defined?(JRUBY_VERSION) || RUBY_ENGINE == "rbx"
assert_file "Gemfile" do |content|
assert_no_match(/byebug/, content)
@@ -101,7 +101,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase
end
def test_generating_adds_dummy_app_rake_tasks_without_unit_test_files
- run_generator [destination_root, "-T", "--mountable", '--dummy-path', 'my_dummy_app']
+ run_generator [destination_root, "-T", "--mountable", "--dummy-path", "my_dummy_app"]
assert_file "Rakefile", /APP_RAKEFILE/
end
@@ -199,13 +199,13 @@ class PluginGeneratorTest < Rails::Generators::TestCase
def test_dev_option
assert_generates_without_bundler(dev: true)
- rails_path = File.expand_path('../../..', Rails.root)
- assert_file 'Gemfile', /^gem\s+["']rails["'],\s+path:\s+["']#{Regexp.escape(rails_path)}["']$/
+ rails_path = File.expand_path("../../..", Rails.root)
+ assert_file "Gemfile", /^gem\s+["']rails["'],\s+path:\s+["']#{Regexp.escape(rails_path)}["']$/
end
def test_edge_option
assert_generates_without_bundler(edge: true)
- assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["'],\s+branch:\s+["']#{Regexp.escape("5-0-stable")}["']$}
+ assert_file "Gemfile", %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["'],\s+branch:\s+["']#{Regexp.escape("5-0-stable")}["']$}
end
def test_generation_does_not_run_bundle_install_with_full_and_mountable
@@ -236,21 +236,21 @@ class PluginGeneratorTest < Rails::Generators::TestCase
def test_ensure_that_tests_work
run_generator
FileUtils.cd destination_root
- quietly { system 'bundle install' }
+ quietly { system "bundle install" }
assert_match(/1 runs, 1 assertions, 0 failures, 0 errors/, `bin/test 2>&1`)
end
def test_ensure_that_tests_works_in_full_mode
run_generator [destination_root, "--full", "--skip_active_record"]
FileUtils.cd destination_root
- quietly { system 'bundle install' }
+ quietly { system "bundle install" }
assert_match(/1 runs, 1 assertions, 0 failures, 0 errors/, `bundle exec rake test 2>&1`)
end
def test_ensure_that_migration_tasks_work_with_mountable_option
run_generator [destination_root, "--mountable"]
FileUtils.cd destination_root
- quietly { system 'bundle install' }
+ quietly { system "bundle install" }
output = `bin/rails db:migrate 2>&1`
assert $?.success?, "Command failed: #{output}"
end
@@ -333,7 +333,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase
assert_match(/ActionDispatch::IntegrationTest\.fixture_path = ActiveSupport::TestCase\.fixture_pat/, content)
assert_no_match(/Rails::TestUnitReporter\.executable = 'bin\/test'/, content)
end
- assert_no_file 'bin/test'
+ assert_no_file "bin/test"
end
def test_create_mountable_application_with_mountable_option_and_hypenated_name
@@ -450,7 +450,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase
assert_file "spec/dummy/config/application.rb"
assert_no_file "test"
assert_no_file "test/test_helper.rb"
- assert_file '.gitignore' do |contents|
+ assert_file ".gitignore" do |contents|
assert_match(/spec\/dummy/, contents)
end
end
@@ -458,7 +458,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase
def test_dummy_appplication_skip_listen_by_default
run_generator
- assert_file 'test/dummy/config/environments/development.rb' do |contents|
+ assert_file "test/dummy/config/environments/development.rb" do |contents|
assert_match(/^\s*# config.file_watcher = ActiveSupport::EventedFileUpdateChecker/, contents)
end
end
@@ -473,21 +473,21 @@ class PluginGeneratorTest < Rails::Generators::TestCase
def test_unnecessary_files_are_not_generated_in_dummy_application
run_generator
- assert_no_file 'test/dummy/.gitignore'
- assert_no_file 'test/dummy/db/seeds.rb'
- assert_no_file 'test/dummy/Gemfile'
- assert_no_file 'test/dummy/public/robots.txt'
- assert_no_file 'test/dummy/README.md'
- assert_no_directory 'test/dummy/lib/tasks'
- assert_no_directory 'test/dummy/doc'
- assert_no_directory 'test/dummy/test'
- assert_no_directory 'test/dummy/vendor'
+ assert_no_file "test/dummy/.gitignore"
+ assert_no_file "test/dummy/db/seeds.rb"
+ assert_no_file "test/dummy/Gemfile"
+ assert_no_file "test/dummy/public/robots.txt"
+ assert_no_file "test/dummy/README.md"
+ assert_no_directory "test/dummy/lib/tasks"
+ assert_no_directory "test/dummy/doc"
+ assert_no_directory "test/dummy/test"
+ assert_no_directory "test/dummy/vendor"
end
def test_skipping_test_files
run_generator [destination_root, "--skip-test"]
assert_no_file "test"
- assert_file '.gitignore' do |contents|
+ assert_file ".gitignore" do |contents|
assert_no_match(/test\dummy/, contents)
end
end
@@ -496,7 +496,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase
run_generator [destination_root, "--skip-gemspec"]
assert_no_file "bukkits.gemspec"
assert_file "Gemfile" do |contents|
- assert_no_match('gemspec', contents)
+ assert_no_match("gemspec", contents)
assert_match(/gem 'rails'/, contents)
assert_match_sqlite3(contents)
assert_no_match(/# gem "jquery-rails"/, contents)
@@ -507,7 +507,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase
run_generator [destination_root, "--skip-gemspec", "--full"]
assert_no_file "bukkits.gemspec"
assert_file "Gemfile" do |contents|
- assert_no_match('gemspec', contents)
+ assert_no_match("gemspec", contents)
assert_match(/gem 'rails'/, contents)
assert_match_sqlite3(contents)
end
@@ -516,21 +516,21 @@ class PluginGeneratorTest < Rails::Generators::TestCase
def test_creating_plugin_in_app_directory_adds_gemfile_entry
# simulate application existence
gemfile_path = "#{Rails.root}/Gemfile"
- Object.const_set('APP_PATH', Rails.root)
+ Object.const_set("APP_PATH", Rails.root)
FileUtils.touch gemfile_path
run_generator
assert_file gemfile_path, /gem 'bukkits', path: 'tmp\/bukkits'/
ensure
- Object.send(:remove_const, 'APP_PATH')
+ Object.send(:remove_const, "APP_PATH")
FileUtils.rm gemfile_path
end
def test_skipping_gemfile_entry
# simulate application existence
gemfile_path = "#{Rails.root}/Gemfile"
- Object.const_set('APP_PATH', Rails.root)
+ Object.const_set("APP_PATH", Rails.root)
FileUtils.touch gemfile_path
run_generator [destination_root, "--skip-gemfile-entry"]
@@ -539,7 +539,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase
assert_no_match(/gem 'bukkits', path: 'tmp\/bukkits'/, contents)
end
ensure
- Object.send(:remove_const, 'APP_PATH')
+ Object.send(:remove_const, "APP_PATH")
FileUtils.rm gemfile_path
end
@@ -580,7 +580,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase
name = "TODO: Write your name"
email = "TODO: Write your email address"
- run_generator [destination_root, '--skip-git']
+ run_generator [destination_root, "--skip-git"]
assert_file "MIT-LICENSE" do |contents|
assert_match name, contents
end
@@ -591,8 +591,8 @@ class PluginGeneratorTest < Rails::Generators::TestCase
end
def test_skipping_useless_folders_generation_for_api_engines
- ['--full', '--mountable'].each do |option|
- run_generator [destination_root, option, '--api']
+ ["--full", "--mountable"].each do |option|
+ run_generator [destination_root, option, "--api"]
assert_no_directory "app/assets"
assert_no_directory "app/helpers"
@@ -603,7 +603,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase
end
def test_application_controller_parent_for_mountable_api_plugins
- run_generator [destination_root, '--mountable', '--api']
+ run_generator [destination_root, "--mountable", "--api"]
assert_file "app/controllers/bukkits/application_controller.rb" do |content|
assert_match "ApplicationController < ActionController::API", content
@@ -611,16 +611,15 @@ class PluginGeneratorTest < Rails::Generators::TestCase
end
def test_dummy_api_application_for_api_plugins
- run_generator [destination_root, '--api']
+ run_generator [destination_root, "--api"]
assert_file "test/dummy/config/application.rb" do |content|
assert_match "config.api_only = true", content
end
end
-
def test_api_generators_configuration_for_api_engines
- run_generator [destination_root, '--full', '--api']
+ run_generator [destination_root, "--full", "--api"]
assert_file "lib/bukkits/engine.rb" do |content|
assert_match "config.generators.api_only = true", content
@@ -628,7 +627,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase
end
def test_scaffold_generator_for_mountable_api_plugins
- run_generator [destination_root, '--mountable', '--api']
+ run_generator [destination_root, "--mountable", "--api"]
capture(:stdout) do
`#{destination_root}/bin/rails g scaffold article`
@@ -645,7 +644,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase
end
def test_model_with_existent_application_record_in_mountable_engine
- run_generator [destination_root, '--mountable']
+ run_generator [destination_root, "--mountable"]
capture(:stdout) do
`#{destination_root}/bin/rails g model article`
end
@@ -654,7 +653,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase
end
def test_generate_application_record_when_does_not_exist_in_mountable_engine
- run_generator [destination_root, '--mountable']
+ run_generator [destination_root, "--mountable"]
FileUtils.rm "#{destination_root}/app/models/bukkits/application_record.rb"
capture(:stdout) do
`#{destination_root}/bin/rails g model article`
@@ -668,7 +667,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase
end
def test_generate_application_mailer_when_does_not_exist_in_mountable_engine
- run_generator [destination_root, '--mountable']
+ run_generator [destination_root, "--mountable"]
FileUtils.rm "#{destination_root}/app/mailers/bukkits/application_mailer.rb"
capture(:stdout) do
`#{destination_root}/bin/rails g mailer User`
@@ -681,7 +680,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase
end
def test_generate_mailer_layouts_when_does_not_exist_in_mountable_engine
- run_generator [destination_root, '--mountable']
+ run_generator [destination_root, "--mountable"]
capture(:stdout) do
`#{destination_root}/bin/rails g mailer User`
end
@@ -696,7 +695,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase
end
def test_generate_application_job_when_does_not_exist_in_mountable_engine
- run_generator [destination_root, '--mountable']
+ run_generator [destination_root, "--mountable"]
FileUtils.rm "#{destination_root}/app/jobs/bukkits/application_job.rb"
capture(:stdout) do
`#{destination_root}/bin/rails g job refresh_counters`
@@ -711,7 +710,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase
protected
def action(*args, &block)
- silence(:stdout){ generator.send(*args, &block) }
+ silence(:stdout) { generator.send(*args, &block) }
end
def default_files
@@ -731,9 +730,9 @@ class PluginGeneratorTest < Rails::Generators::TestCase
command_check = -> command do
case command
- when 'install'
+ when "install"
flunk "install expected to not be called"
- when 'exec spring binstub --all'
+ when "exec spring binstub --all"
# Called when running tests with spring, let through unscathed.
end
end