diff options
Diffstat (limited to 'railties/test/generators')
29 files changed, 602 insertions, 564 deletions
diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index 3b2b3c37d0..360e8e97d7 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -1,6 +1,6 @@ -require 'generators/generators_test_helper' -require 'rails/generators/rails/app/app_generator' -require 'env_helpers' +require "generators/generators_test_helper" +require "rails/generators/rails/app/app_generator" +require "env_helpers" class ActionsTest < Rails::Generators::TestCase include GeneratorsTestHelper @@ -19,98 +19,98 @@ class ActionsTest < Rails::Generators::TestCase end def test_invoke_other_generator_with_shortcut - action :invoke, 'model', ['my_model'] - assert_file 'app/models/my_model.rb', /MyModel/ + action :invoke, "model", ["my_model"] + assert_file "app/models/my_model.rb", /MyModel/ end def test_invoke_other_generator_with_full_namespace - action :invoke, 'rails:model', ['my_model'] - assert_file 'app/models/my_model.rb', /MyModel/ + action :invoke, "rails:model", ["my_model"] + assert_file "app/models/my_model.rb", /MyModel/ end def test_create_file_should_write_data_to_file_path - action :create_file, 'lib/test_file.rb', 'heres test data' - assert_file 'lib/test_file.rb', 'heres test data' + action :create_file, "lib/test_file.rb", "heres test data" + assert_file "lib/test_file.rb", "heres test data" end def test_create_file_should_write_block_contents_to_file_path - action(:create_file, 'lib/test_file.rb'){ 'heres block data' } - assert_file 'lib/test_file.rb', 'heres block data' + action(:create_file, "lib/test_file.rb") { "heres block data" } + assert_file "lib/test_file.rb", "heres block data" end def test_add_source_adds_source_to_gemfile run_generator - action :add_source, 'http://gems.github.com' - assert_file 'Gemfile', /source 'http:\/\/gems\.github\.com'/ + action :add_source, "http://gems.github.com" + assert_file "Gemfile", /source 'http:\/\/gems\.github\.com'/ end def test_add_source_with_block_adds_source_to_gemfile_with_gem run_generator - action :add_source, 'http://gems.github.com' do - gem 'rspec-rails' + action :add_source, "http://gems.github.com" do + gem "rspec-rails" end - assert_file 'Gemfile', /source 'http:\/\/gems\.github\.com' do\n gem 'rspec-rails'\nend/ + assert_file "Gemfile", /source 'http:\/\/gems\.github\.com' do\n gem 'rspec-rails'\nend/ end def test_add_source_with_block_adds_source_to_gemfile_after_gem run_generator - action :gem, 'will-paginate' - action :add_source, 'http://gems.github.com' do - gem 'rspec-rails' + action :gem, "will-paginate" + action :add_source, "http://gems.github.com" do + gem "rspec-rails" end - assert_file 'Gemfile', /gem 'will-paginate'\nsource 'http:\/\/gems\.github\.com' do\n gem 'rspec-rails'\nend/ + assert_file "Gemfile", /gem 'will-paginate'\nsource 'http:\/\/gems\.github\.com' do\n gem 'rspec-rails'\nend/ end def test_gem_should_put_gem_dependency_in_gemfile run_generator - action :gem, 'will-paginate' - assert_file 'Gemfile', /gem 'will\-paginate'/ + action :gem, "will-paginate" + assert_file "Gemfile", /gem 'will\-paginate'/ end def test_gem_with_version_should_include_version_in_gemfile run_generator - action :gem, 'rspec', '>=2.0.0.a5' + action :gem, "rspec", ">=2.0.0.a5" - assert_file 'Gemfile', /gem 'rspec', '>=2.0.0.a5'/ + assert_file "Gemfile", /gem 'rspec', '>=2.0.0.a5'/ end def test_gem_should_insert_on_separate_lines run_generator - File.open('Gemfile', 'a') {|f| f.write('# Some content...') } + File.open("Gemfile", "a") { |f| f.write("# Some content...") } - action :gem, 'rspec' - action :gem, 'rspec-rails' + action :gem, "rspec" + action :gem, "rspec-rails" - assert_file 'Gemfile', /^gem 'rspec'$/ - assert_file 'Gemfile', /^gem 'rspec-rails'$/ + assert_file "Gemfile", /^gem 'rspec'$/ + assert_file "Gemfile", /^gem 'rspec-rails'$/ end def test_gem_should_include_options run_generator - action :gem, 'rspec', github: 'dchelimsky/rspec', tag: '1.2.9.rc1' + action :gem, "rspec", github: "dchelimsky/rspec", tag: "1.2.9.rc1" - assert_file 'Gemfile', /gem 'rspec', github: 'dchelimsky\/rspec', tag: '1\.2\.9\.rc1'/ + assert_file "Gemfile", /gem 'rspec', github: 'dchelimsky\/rspec', tag: '1\.2\.9\.rc1'/ end def test_gem_with_non_string_options run_generator - action :gem, 'rspec', require: false - action :gem, 'rspec-rails', group: [:development, :test] + action :gem, "rspec", require: false + action :gem, "rspec-rails", group: [:development, :test] - assert_file 'Gemfile', /^gem 'rspec', require: false$/ - assert_file 'Gemfile', /^gem 'rspec-rails', group: \[:development, :test\]$/ + assert_file "Gemfile", /^gem 'rspec', require: false$/ + assert_file "Gemfile", /^gem 'rspec-rails', group: \[:development, :test\]$/ end def test_gem_falls_back_to_inspect_if_string_contains_single_quote run_generator - action :gem, 'rspec', ">=2.0'0" + action :gem, "rspec", ">=2.0'0" - assert_file 'Gemfile', /^gem 'rspec', ">=2\.0'0"$/ + assert_file "Gemfile", /^gem 'rspec', ">=2\.0'0"$/ end def test_gem_works_even_if_frozen_string_is_passed_as_argument @@ -118,34 +118,34 @@ class ActionsTest < Rails::Generators::TestCase action :gem, "frozen_gem".freeze, "1.0.0".freeze - assert_file 'Gemfile', /^gem 'frozen_gem', '1.0.0'$/ + assert_file "Gemfile", /^gem 'frozen_gem', '1.0.0'$/ end def test_gem_group_should_wrap_gems_in_a_group run_generator action :gem_group, :development, :test do - gem 'rspec-rails' + gem "rspec-rails" end action :gem_group, :test do - gem 'fakeweb' + gem "fakeweb" end - assert_file 'Gemfile', /\ngroup :development, :test do\n gem 'rspec-rails'\nend\n\ngroup :test do\n gem 'fakeweb'\nend/ + assert_file "Gemfile", /\ngroup :development, :test do\n gem 'rspec-rails'\nend\n\ngroup :test do\n gem 'fakeweb'\nend/ end def test_environment_should_include_data_in_environment_initializer_block run_generator autoload_paths = 'config.autoload_paths += %w["#{Rails.root}/app/extras"]' action :environment, autoload_paths - assert_file 'config/application.rb', / class Application < Rails::Application\n #{Regexp.escape(autoload_paths)}/ + assert_file "config/application.rb", / class Application < Rails::Application\n #{Regexp.escape(autoload_paths)}/ end def test_environment_should_include_data_in_environment_initializer_block_with_env_option run_generator autoload_paths = 'config.autoload_paths += %w["#{Rails.root}/app/extras"]' - action :environment, autoload_paths, env: 'development' + action :environment, autoload_paths, env: "development" assert_file "config/environments/development.rb", /Rails\.application\.configure do\n #{Regexp.escape(autoload_paths)}/ end @@ -153,80 +153,80 @@ class ActionsTest < Rails::Generators::TestCase run_generator action :environment do - _ = '# This wont be added'# assignment to silence parse-time warning "unused literal ignored" - '# This will be added' + _ = "# This wont be added"# assignment to silence parse-time warning "unused literal ignored" + "# This will be added" end - assert_file 'config/application.rb' do |content| + assert_file "config/application.rb" do |content| assert_match(/# This will be added/, content) assert_no_match(/# This wont be added/, content) end end def test_git_with_symbol_should_run_command_using_git_scm - assert_called_with(generator, :run, ['git init']) do + assert_called_with(generator, :run, ["git init"]) do action :git, :init end end def test_git_with_hash_should_run_each_command_using_git_scm assert_called_with(generator, :run, [ ["git rm README"], ["git add ."] ]) do - action :git, rm: 'README', add: '.' + action :git, rm: "README", add: "." end end def test_vendor_should_write_data_to_file_in_vendor - action :vendor, 'vendor_file.rb', '# vendor data' - assert_file 'vendor/vendor_file.rb', '# vendor data' + action :vendor, "vendor_file.rb", "# vendor data" + assert_file "vendor/vendor_file.rb", "# vendor data" end def test_lib_should_write_data_to_file_in_lib - action :lib, 'my_library.rb', 'class MyLibrary' - assert_file 'lib/my_library.rb', 'class MyLibrary' + action :lib, "my_library.rb", "class MyLibrary" + assert_file "lib/my_library.rb", "class MyLibrary" end def test_rakefile_should_write_date_to_file_in_lib_tasks - action :rakefile, 'myapp.rake', 'task run: [:environment]' - assert_file 'lib/tasks/myapp.rake', 'task run: [:environment]' + action :rakefile, "myapp.rake", "task run: [:environment]" + assert_file "lib/tasks/myapp.rake", "task run: [:environment]" end def test_initializer_should_write_date_to_file_in_config_initializers - action :initializer, 'constants.rb', 'MY_CONSTANT = 42' - assert_file 'config/initializers/constants.rb', 'MY_CONSTANT = 42' + action :initializer, "constants.rb", "MY_CONSTANT = 42" + assert_file "config/initializers/constants.rb", "MY_CONSTANT = 42" end def test_generate_should_run_script_generate_with_argument_and_options - assert_called_with(generator, :run_ruby_script, ['bin/rails generate model MyModel', verbose: false]) do - action :generate, 'model', 'MyModel' + assert_called_with(generator, :run_ruby_script, ["bin/rails generate model MyModel", verbose: false]) do + action :generate, "model", "MyModel" end end def test_rails_should_run_rake_command_with_default_env assert_called_with(generator, :run, ["rake log:clear RAILS_ENV=development", verbose: false]) do with_rails_env nil do - action :rake, 'log:clear' + action :rake, "log:clear" end end end def test_rails_with_env_option_should_run_rake_command_in_env - assert_called_with(generator, :run, ['rake log:clear RAILS_ENV=production', verbose: false]) do - action :rake, 'log:clear', env: 'production' + assert_called_with(generator, :run, ["rake log:clear RAILS_ENV=production", verbose: false]) do + action :rake, "log:clear", env: "production" end end test "rails command with RAILS_ENV variable should run rake command in env" do - assert_called_with(generator, :run, ['rake log:clear RAILS_ENV=production', verbose: false]) do + assert_called_with(generator, :run, ["rake log:clear RAILS_ENV=production", verbose: false]) do with_rails_env "production" do - action :rake, 'log:clear' + action :rake, "log:clear" end end end test "env option should win over RAILS_ENV variable when running rake" do - assert_called_with(generator, :run, ['rake log:clear RAILS_ENV=production', verbose: false]) do + assert_called_with(generator, :run, ["rake log:clear RAILS_ENV=production", verbose: false]) do with_rails_env "staging" do - action :rake, 'log:clear', env: 'production' + action :rake, "log:clear", env: "production" end end end @@ -234,7 +234,7 @@ class ActionsTest < Rails::Generators::TestCase test "rails command with sudo option should run rake command with sudo" do assert_called_with(generator, :run, ["sudo rake log:clear RAILS_ENV=development", verbose: false]) do with_rails_env nil do - action :rake, 'log:clear', sudo: true + action :rake, "log:clear", sudo: true end end end @@ -242,29 +242,29 @@ class ActionsTest < Rails::Generators::TestCase test "rails command should run rails_command with default env" do assert_called_with(generator, :run, ["rails log:clear RAILS_ENV=development", verbose: false]) do with_rails_env nil do - action :rails_command, 'log:clear' + action :rails_command, "log:clear" end end end test "rails command with env option should run rails_command with same env" do - assert_called_with(generator, :run, ['rails log:clear RAILS_ENV=production', verbose: false]) do - action :rails_command, 'log:clear', env: 'production' + assert_called_with(generator, :run, ["rails log:clear RAILS_ENV=production", verbose: false]) do + action :rails_command, "log:clear", env: "production" end end test "rails command with RAILS_ENV variable should run rails_command in env" do - assert_called_with(generator, :run, ['rails log:clear RAILS_ENV=production', verbose: false]) do + assert_called_with(generator, :run, ["rails log:clear RAILS_ENV=production", verbose: false]) do with_rails_env "production" do - action :rails_command, 'log:clear' + action :rails_command, "log:clear" end end end def test_env_option_should_win_over_rails_env_variable_when_running_rails - assert_called_with(generator, :run, ['rails log:clear RAILS_ENV=production', verbose: false]) do + assert_called_with(generator, :run, ["rails log:clear RAILS_ENV=production", verbose: false]) do with_rails_env "staging" do - action :rails_command, 'log:clear', env: 'production' + action :rails_command, "log:clear", env: "production" end end end @@ -272,13 +272,13 @@ class ActionsTest < Rails::Generators::TestCase test "rails command with sudo option should run rails_command with sudo" do assert_called_with(generator, :run, ["sudo rails log:clear RAILS_ENV=development", verbose: false]) do with_rails_env nil do - action :rails_command, 'log:clear', sudo: true + action :rails_command, "log:clear", sudo: true end end end def test_capify_should_run_the_capify_command - assert_called_with(generator, :run, ['capify .', verbose: false]) do + assert_called_with(generator, :run, ["capify .", verbose: false]) do action :capify! end end @@ -287,12 +287,12 @@ class ActionsTest < Rails::Generators::TestCase run_generator route_command = "route '/login', controller: 'sessions', action: 'new'" action :route, route_command - assert_file 'config/routes.rb', /#{Regexp.escape(route_command)}/ + assert_file "config/routes.rb", /#{Regexp.escape(route_command)}/ end def test_route_should_be_idempotent run_generator - route_path = File.expand_path('config/routes.rb', destination_root) + route_path = File.expand_path("config/routes.rb", destination_root) # runs first time, not asserting action :route, "root 'welcome#index'" @@ -312,8 +312,8 @@ class ActionsTest < Rails::Generators::TestCase content = File.read(route_path) # Remove all of the comments and blank lines from the routes file - content.gsub!(/^ \#.*\n/, '') - content.gsub!(/^\n/, '') + content.gsub!(/^ \#.*\n/, "") + content.gsub!(/^\n/, "") File.open(route_path, "wb") { |file| file.write(content) } @@ -369,10 +369,9 @@ F assert_equal("", action(:log, :yes, "YES")) end - protected + private def action(*args, &block) - capture(:stdout){ generator.send(*args, &block) } + capture(:stdout) { generator.send(*args, &block) } end - end diff --git a/railties/test/generators/api_app_generator_test.rb b/railties/test/generators/api_app_generator_test.rb index 92779452e1..c54d9cc599 100644 --- a/railties/test/generators/api_app_generator_test.rb +++ b/railties/test/generators/api_app_generator_test.rb @@ -1,11 +1,11 @@ -require 'generators/generators_test_helper' -require 'rails/generators/rails/app/app_generator' +require "generators/generators_test_helper" +require "rails/generators/rails/app/app_generator" class ApiAppGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper tests Rails::Generators::AppGenerator - arguments [destination_root, '--api'] + arguments [destination_root, "--api"] def setup Rails.application = TestApp::Application @@ -35,7 +35,6 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase assert_file "Gemfile" do |content| assert_no_match(/gem 'coffee-rails'/, content) - assert_no_match(/gem 'jquery-rails'/, content) assert_no_match(/gem 'sass-rails'/, content) assert_no_match(/gem 'web-console'/, content) assert_match(/# gem 'jbuilder'/, content) @@ -73,51 +72,52 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase private - def default_files - files = %W( - .gitignore - Gemfile - Rakefile - config.ru - app/controllers - app/mailers - app/models - app/views/layouts/mailer.html.erb - app/views/layouts/mailer.text.erb - config/environments - config/initializers - config/locales - db - lib - lib/tasks - log - test/fixtures - test/controllers - test/integration - test/models - tmp - vendor - ) - files.concat %w(bin/bundle bin/rails bin/rake) - files - end + def default_files + files = %W( + .gitignore + Gemfile + Rakefile + config.ru + app/controllers + app/mailers + app/models + app/views/layouts/mailer.html.erb + app/views/layouts/mailer.text.erb + config/environments + config/initializers + config/locales + db + lib + lib/tasks + log + test/fixtures + test/controllers + test/integration + test/models + tmp + vendor + ) + files.concat %w(bin/bundle bin/rails bin/rake) + files + end - def skipped_files - %w(app/assets - app/helpers - app/views/layouts/application.html.erb - config/initializers/assets.rb - config/initializers/cookies_serializer.rb - config/initializers/session_store.rb - lib/assets - vendor/assets - test/helpers - tmp/cache/assets - public/404.html - public/422.html - public/500.html - public/apple-touch-icon-precomposed.png - public/apple-touch-icon.png - public/favicon.ico) - end + def skipped_files + %w(app/assets + app/helpers + app/views/layouts/application.html.erb + bin/yarn + config/initializers/assets.rb + config/initializers/cookies_serializer.rb + lib/assets + test/helpers + tmp/cache/assets + public/404.html + public/422.html + public/500.html + public/apple-touch-icon-precomposed.png + public/apple-touch-icon.png + public/favicon.icon + vendor/package.json + ) + end end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index ac1488abb3..20de2258c5 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -1,6 +1,6 @@ -require 'generators/generators_test_helper' -require 'rails/generators/rails/app/app_generator' -require 'generators/shared_generator_tests' +require "generators/generators_test_helper" +require "rails/generators/rails/app/app_generator" +require "generators/shared_generator_tests" DEFAULT_APP_FILES = %w( .gitignore @@ -43,9 +43,6 @@ DEFAULT_APP_FILES = %w( test/mailers test/integration vendor - vendor/assets - vendor/assets/stylesheets - vendor/assets/javascripts tmp tmp/cache tmp/cache/assets @@ -77,7 +74,7 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_invalid_application_name_raises_an_error - content = capture(:stderr){ run_generator [File.join(destination_root, "43-things")] } + content = capture(:stderr) { run_generator [File.join(destination_root, "43-things")] } assert_equal "Invalid application name 43-things. Please give a name which does not start with numbers.\n", content end @@ -88,12 +85,12 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_application_new_exits_with_non_zero_code_on_invalid_application_name - quietly { system 'rails new test --no-rc' } + quietly { system "rails new test --no-rc" } assert_equal false, $?.success? end def test_application_new_exits_with_message_and_non_zero_code_when_generating_inside_existing_rails_directory - app_root = File.join(destination_root, 'myfirstapp') + app_root = File.join(destination_root, "myfirstapp") run_generator [app_root] output = nil Dir.chdir(app_root) do @@ -104,7 +101,7 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_application_new_show_help_message_inside_existing_rails_directory - app_root = File.join(destination_root, 'myfirstapp') + app_root = File.join(destination_root, "myfirstapp") run_generator [app_root] output = Dir.chdir(app_root) do `rails new --help` @@ -131,20 +128,18 @@ class AppGeneratorTest < Rails::Generators::TestCase generator.send(:app_const) quietly { generator.send(:update_config_files) } assert_file "myapp_moved/config/environment.rb", /Rails\.application\.initialize!/ - assert_file "myapp_moved/config/initializers/session_store.rb", /_myapp_session/ end end end def test_rails_update_generates_correct_session_key - app_root = File.join(destination_root, 'myapp') + app_root = File.join(destination_root, "myapp") run_generator [app_root] stub_rails_application(app_root) do generator = Rails::Generators::AppGenerator.new ["rails"], [], destination_root: app_root, shell: @shell generator.send(:app_const) quietly { generator.send(:update_config_files) } - assert_file "myapp/config/initializers/session_store.rb", /_myapp_session/ end end @@ -157,11 +152,11 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_new_application_not_include_api_initializers run_generator - assert_no_file 'config/initializers/cors.rb' + assert_no_file "config/initializers/cors.rb" end def test_rails_update_keep_the_cookie_serializer_if_it_is_already_configured - app_root = File.join(destination_root, 'myapp') + app_root = File.join(destination_root, "myapp") run_generator [app_root] stub_rails_application(app_root) do @@ -173,7 +168,7 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_rails_update_set_the_cookie_serializer_to_marshal_if_it_is_not_already_configured - app_root = File.join(destination_root, 'myapp') + app_root = File.join(destination_root, "myapp") run_generator [app_root] FileUtils.rm("#{app_root}/config/initializers/cookies_serializer.rb") @@ -188,7 +183,7 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_rails_update_dont_set_file_watcher - app_root = File.join(destination_root, 'myapp') + app_root = File.join(destination_root, "myapp") run_generator [app_root] stub_rails_application(app_root) do @@ -202,7 +197,7 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_rails_update_does_not_create_new_framework_defaults_by_default - app_root = File.join(destination_root, 'myapp') + app_root = File.join(destination_root, "myapp") run_generator [app_root] FileUtils.rm("#{app_root}/config/initializers/new_framework_defaults.rb") @@ -221,7 +216,7 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_rails_update_does_not_create_rack_cors - app_root = File.join(destination_root, 'myapp') + app_root = File.join(destination_root, "myapp") run_generator [app_root] stub_rails_application(app_root) do @@ -233,7 +228,7 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_rails_update_does_not_remove_rack_cors_if_already_present - app_root = File.join(destination_root, 'myapp') + app_root = File.join(destination_root, "myapp") run_generator [app_root] FileUtils.touch("#{app_root}/config/initializers/cors.rb") @@ -254,7 +249,7 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_gemfile_has_no_whitespace_errors run_generator absolute = File.expand_path("Gemfile", destination_root) - File.open(absolute, 'r') do |f| + File.open(absolute, "r") do |f| f.each_line do |line| assert_no_match %r{/^[ \t]+$/}, line end @@ -358,12 +353,19 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_generator_if_skip_active_record_is_given run_generator [destination_root, "--skip-active-record"] + assert_no_directory "db/" assert_no_file "config/database.yml" assert_no_file "app/models/application_record.rb" assert_file "config/application.rb", /#\s+require\s+["']active_record\/railtie["']/ assert_file "test/test_helper.rb" do |helper_content| assert_no_match(/fixtures :all/, helper_content) end + assert_file "bin/setup" do |setup_content| + assert_no_match(/db:setup/, setup_content) + end + assert_file "bin/update" do |update_content| + assert_no_match(/db:migrate/, update_content) + end assert_file "config/initializers/new_framework_defaults.rb" do |initializer_content| assert_no_match(/belongs_to_required_by_default/, initializer_content) @@ -382,13 +384,15 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "config/environments/production.rb" do |content| assert_no_match(/config\.action_mailer/, content) end + assert_no_directory "app/mailers" + assert_no_directory "test/mailers" end def test_generator_has_assets_gems run_generator - assert_gem 'sass-rails' - assert_gem 'uglifier' + assert_gem "sass-rails" + assert_gem "uglifier" end def test_generator_if_skip_sprockets_is_given @@ -398,7 +402,6 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_match(/#\s+require\s+["']sprockets\/railtie["']/, content) end assert_file "Gemfile" do |content| - assert_no_match(/jquery-rails/, content) assert_no_match(/sass-rails/, content) assert_no_match(/uglifier/, content) assert_no_match(/coffee-rails/, content) @@ -411,6 +414,16 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_no_match(/config\.assets\.js_compressor = :uglifier/, content) assert_no_match(/config\.assets\.css_compressor = :sass/, content) end + assert_file "config/initializers/new_framework_defaults.rb" do |content| + assert_no_match(/unknown_asset_fallback/, content) + end + end + + def test_generator_if_skip_yarn_is_given + run_generator [destination_root, "--skip-yarn"] + + assert_no_file "vendor/package.json" + assert_no_file "bin/yarn" end def test_generator_if_skip_action_cable_is_given @@ -438,29 +451,25 @@ class AppGeneratorTest < Rails::Generators::TestCase end end - def test_jquery_is_the_default_javascript_library + def test_rails_ujs_is_the_default_ujs_library run_generator assert_file "app/assets/javascripts/application.js" do |contents| - assert_match %r{^//= require jquery}, contents - assert_match %r{^//= require jquery_ujs}, contents + assert_match %r{^//= require rails-ujs}, contents end - assert_gem "jquery-rails" end - def test_other_javascript_libraries - run_generator [destination_root, '-j', 'prototype'] + def test_inclusion_of_javascript_libraries_if_required + run_generator [destination_root, "-j", "jquery"] assert_file "app/assets/javascripts/application.js" do |contents| - assert_match %r{^//= require prototype}, contents - assert_match %r{^//= require prototype_ujs}, contents + assert_match %r{^//= require jquery}, contents end - assert_gem "prototype-rails" + assert_gem "jquery-rails" end def test_javascript_is_skipped_if_required run_generator [destination_root, "--skip-javascript"] assert_no_file "app/assets/javascripts" - assert_no_file "vendor/assets/javascripts" assert_file "app/views/layouts/application.html.erb" do |contents| assert_match(/stylesheet_link_tag\s+'application', media: 'all' %>/, contents) @@ -469,13 +478,41 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "Gemfile" do |content| assert_no_match(/coffee-rails/, content) - assert_no_match(/jquery-rails/, content) + assert_no_match(/uglifier/, content) + end + + assert_file "config/environments/production.rb" do |content| + assert_no_match(/config\.assets\.js_compressor = :uglifier/, content) + end + end + + def test_coffeescript_is_skipped_if_required + run_generator [destination_root, "--skip-coffee"] + + assert_file "Gemfile" do |content| + assert_no_match(/coffee-rails/, content) + assert_match(/uglifier/, content) + end + end + + def test_generator_for_yarn + run_generator([destination_root]) + assert_file "vendor/package.json", /dependencies/ + assert_file "config/initializers/assets.rb", /node_modules/ + end + + def test_generator_for_yarn_skipped + run_generator([destination_root, "--skip-yarn"]) + assert_no_file "vendor/package.json" + + assert_file "config/initializers/assets.rb" do |content| + assert_no_match(/node_modules/, content) end end def test_inclusion_of_jbuilder run_generator - assert_gem 'jbuilder' + assert_gem "jbuilder" end def test_inclusion_of_a_debugger @@ -485,13 +522,13 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_no_match(/byebug/, content) end else - assert_gem 'byebug' + assert_gem "byebug" end end def test_inclusion_of_listen_related_configuration_by_default run_generator - if RbConfig::CONFIG['host_os'] =~ /darwin|linux/ + if RbConfig::CONFIG["host_os"] =~ /darwin|linux/ assert_listen_related_configuration else assert_no_listen_related_configuration @@ -499,14 +536,14 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_non_inclusion_of_listen_related_configuration_if_skip_listen - run_generator [destination_root, '--skip-listen'] + run_generator [destination_root, "--skip-listen"] assert_no_listen_related_configuration end def test_evented_file_update_checker_config run_generator - assert_file 'config/environments/development.rb' do |content| - if RbConfig::CONFIG['host_os'] =~ /darwin|linux/ + assert_file "config/environments/development.rb" do |content| + if RbConfig::CONFIG["host_os"] =~ /darwin|linux/ assert_match(/^\s*config.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content) else assert_match(/^\s*# config.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content) @@ -536,8 +573,8 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_file_is_added_for_backwards_compatibility - action :file, 'lib/test_file.rb', 'heres test data' - assert_file 'lib/test_file.rb', 'heres test data' + action :file, "lib/test_file.rb", "heres test data" + assert_file "lib/test_file.rb", "heres test data" end def test_tests_are_removed_from_frameworks_if_skip_test_is_given @@ -552,13 +589,6 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "config/application.rb", /\s+require\s+["']active_job\/railtie["']/ end - def test_new_hash_style - run_generator - assert_file "config/initializers/session_store.rb" do |file| - assert_match(/config.session_store :cookie_store, key: '_.+_session'/, file) - end - end - def test_pretend_option output = run_generator [File.join(destination_root, "myapp"), "--pretend"] assert_no_match(/run bundle install/, output) @@ -568,15 +598,14 @@ class AppGeneratorTest < Rails::Generators::TestCase path = File.join(destination_root, "foo bar") # This also applies to MySQL apps but not with SQLite - run_generator [path, "-d", 'postgresql'] + run_generator [path, "-d", "postgresql"] assert_file "foo bar/config/database.yml", /database: foo_bar_development/ - assert_file "foo bar/config/initializers/session_store.rb", /key: '_foo_bar/ end def test_web_console run_generator - assert_gem 'web-console' + assert_gem "web-console" end def test_web_console_with_dev_option @@ -584,7 +613,7 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "Gemfile" do |content| assert_match(/gem 'web-console',\s+github: 'rails\/web-console'/, content) - assert_no_match(/\Agem 'web-console'\z/, content) + assert_no_match(/\Agem 'web-console', '>= 3.3.0'\z/, content) end end @@ -593,7 +622,7 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "Gemfile" do |content| assert_match(/gem 'web-console',\s+github: 'rails\/web-console'/, content) - assert_no_match(/\Agem 'web-console'\z/, content) + assert_no_match(/\Agem 'web-console', '>= 3.3.0'\z/, content) end end @@ -603,18 +632,18 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_dev_option assert_generates_with_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_with_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")}["']$} end def test_spring run_generator - assert_gem 'spring' + assert_gem "spring" end def test_spring_binstubs @@ -623,9 +652,9 @@ class AppGeneratorTest < Rails::Generators::TestCase @binstub_called ||= 0 case command - when 'install' + when "install" # Called when running bundle, we just want to stub it so nothing to do here. - when 'exec spring binstub --all' + when "exec spring binstub --all" @binstub_called += 1 assert_equal 1, @binstub_called, "exec spring binstub --all expected to be called once, but was called #{@install_called} times." end @@ -650,7 +679,7 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_skip_spring run_generator [destination_root, "--skip-spring"] - assert_no_file 'config/spring.rb' + assert_no_file "config/spring.rb" assert_file "Gemfile" do |content| assert_no_match(/spring/, content) end @@ -681,15 +710,15 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_gitignore_when_sqlite3 run_generator - assert_file '.gitignore' do |content| + assert_file ".gitignore" do |content| assert_match(/sqlite3/, content) end end def test_gitignore_when_no_active_record - run_generator [destination_root, '--skip-active-record'] + run_generator [destination_root, "--skip-active-record"] - assert_file '.gitignore' do |content| + assert_file ".gitignore" do |content| assert_no_match(/sqlite/i, content) end end @@ -697,7 +726,7 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_gitignore_when_non_sqlite3_db run_generator([destination_root, "-d", "mysql"]) - assert_file '.gitignore' do |content| + assert_file ".gitignore" do |content| assert_no_match(/sqlite/i, content) end end @@ -719,7 +748,6 @@ class AppGeneratorTest < Rails::Generators::TestCase test/helpers test/integration tmp - vendor/assets/stylesheets ) folders_with_keep.each do |folder| assert_file("#{folder}/.keep") @@ -740,17 +768,17 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_after_bundle_callback - path = 'http://example.org/rails_template' + path = "http://example.org/rails_template" template = %{ after_bundle { run 'echo ran after_bundle' } } template.instance_eval "def read; self; end" # Make the string respond to read check_open = -> *args do - assert_equal [ path, 'Accept' => 'application/x-thor-template' ], args + assert_equal [ path, "Accept" => "application/x-thor-template" ], args template end - sequence = ['install', 'exec spring binstub --all', 'echo ran after_bundle'] - @sequence_step ||= 0 + sequence = ["install", "exec spring binstub --all", "echo ran after_bundle"] + @sequence_step ||= 0 ensure_bundler_first = -> command do assert_equal sequence[@sequence_step], command, "commands should be called in sequence #{sequence}" @sequence_step += 1 @@ -767,7 +795,7 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_equal 3, @sequence_step end - protected + private def stub_rails_application(root) Rails.application.config.root = root @@ -789,20 +817,20 @@ class AppGeneratorTest < Rails::Generators::TestCase end def assert_listen_related_configuration - assert_gem 'listen' - assert_gem 'spring-watcher-listen' + assert_gem "listen" + assert_gem "spring-watcher-listen" - assert_file 'config/environments/development.rb' do |content| + assert_file "config/environments/development.rb" do |content| assert_match(/^\s*config.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content) end end def assert_no_listen_related_configuration - assert_file 'Gemfile' do |content| + assert_file "Gemfile" do |content| assert_no_match(/listen/, content) end - assert_file 'config/environments/development.rb' do |content| + assert_file "config/environments/development.rb" do |content| assert_match(/^\s*# config.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content) end end @@ -814,10 +842,10 @@ class AppGeneratorTest < Rails::Generators::TestCase @install_called ||= 0 case command - when 'install' + when "install" @install_called += 1 assert_equal 1, @install_called, "install expected to be called once, but was called #{@install_called} times" - when 'exec spring binstub --all' + when "exec spring binstub --all" # Called when running tests with spring, let through unscathed. end end diff --git a/railties/test/generators/argv_scrubber_test.rb b/railties/test/generators/argv_scrubber_test.rb index 31e07bc8da..7f4295a20f 100644 --- a/railties/test/generators/argv_scrubber_test.rb +++ b/railties/test/generators/argv_scrubber_test.rb @@ -1,7 +1,7 @@ -require 'active_support/test_case' -require 'active_support/testing/autorun' -require 'rails/generators/rails/app/app_generator' -require 'tempfile' +require "active_support/test_case" +require "active_support/testing/autorun" +require "rails/generators/rails/app/app_generator" +require "tempfile" module Rails module Generators @@ -11,7 +11,7 @@ module Rails # *must* act this way, I just want to prevent regressions. def test_version - ['-v', '--version'].each do |str| + ["-v", "--version"].each do |str| scrubber = ARGVScrubber.new [str] output = nil exit_code = nil @@ -26,37 +26,37 @@ module Rails end def test_default_help - argv = ['zomg', 'how', 'are', 'you'] + argv = ["zomg", "how", "are", "you"] scrubber = ARGVScrubber.new argv args = scrubber.prepare! - assert_equal ['--help'] + argv.drop(1), args + assert_equal ["--help"] + argv.drop(1), args end def test_prepare_returns_args - scrubber = ARGVScrubber.new ['hi mom'] + scrubber = ARGVScrubber.new ["hi mom"] args = scrubber.prepare! - assert_equal '--help', args.first + assert_equal "--help", args.first end def test_no_mutations - scrubber = ARGVScrubber.new ['hi mom'].freeze + scrubber = ARGVScrubber.new ["hi mom"].freeze args = scrubber.prepare! - assert_equal '--help', args.first + assert_equal "--help", args.first end def test_new_command_no_rc scrubber = Class.new(ARGVScrubber) { def self.default_rc_file - File.join(Dir.tmpdir, 'whatever') + File.join(Dir.tmpdir, "whatever") end - }.new ['new'] + }.new ["new"] args = scrubber.prepare! assert_equal [], args end def test_new_homedir_rc - file = Tempfile.new 'myrcfile' - file.puts '--hello-world' + file = Tempfile.new "myrcfile" + file.puts "--hello-world" file.flush message = nil @@ -65,10 +65,10 @@ module Rails file.path end define_method(:puts) { |msg| message = msg } - }.new ['new'] + }.new ["new"] args = scrubber.prepare! - assert_equal ['--hello-world'], args - assert_match 'hello-world', message + assert_equal ["--hello-world"], args + assert_match "hello-world", message assert_match file.path, message ensure file.close @@ -76,33 +76,33 @@ module Rails end def test_rc_whitespace_separated - file = Tempfile.new 'myrcfile' - file.puts '--hello --world' + file = Tempfile.new "myrcfile" + file.puts "--hello --world" file.flush message = nil scrubber = Class.new(ARGVScrubber) { define_method(:puts) { |msg| message = msg } - }.new ['new', "--rc=#{file.path}"] + }.new ["new", "--rc=#{file.path}"] args = scrubber.prepare! - assert_equal ['--hello', '--world'], args + assert_equal ["--hello", "--world"], args ensure file.close file.unlink end def test_new_rc_option - file = Tempfile.new 'myrcfile' - file.puts '--hello-world' + file = Tempfile.new "myrcfile" + file.puts "--hello-world" file.flush message = nil scrubber = Class.new(ARGVScrubber) { define_method(:puts) { |msg| message = msg } - }.new ['new', "--rc=#{file.path}"] + }.new ["new", "--rc=#{file.path}"] args = scrubber.prepare! - assert_equal ['--hello-world'], args - assert_match 'hello-world', message + assert_equal ["--hello-world"], args + assert_match "hello-world", message assert_match file.path, message ensure file.close @@ -110,14 +110,14 @@ module Rails end def test_new_rc_option_and_custom_options - file = Tempfile.new 'myrcfile' - file.puts '--hello' - file.puts '--world' + file = Tempfile.new "myrcfile" + file.puts "--hello" + file.puts "--world" file.flush scrubber = Class.new(ARGVScrubber) { define_method(:puts) { |msg| } - }.new ['new', 'tenderapp', '--love', "--rc=#{file.path}"] + }.new ["new", "tenderapp", "--love", "--rc=#{file.path}"] args = scrubber.prepare! assert_equal ["tenderapp", "--hello", "--world", "--love"], args @@ -127,7 +127,7 @@ module Rails end def test_no_rc - scrubber = ARGVScrubber.new ['new', '--no-rc'] + scrubber = ARGVScrubber.new ["new", "--no-rc"] args = scrubber.prepare! assert_equal [], args end diff --git a/railties/test/generators/assets_generator_test.rb b/railties/test/generators/assets_generator_test.rb index a2b94f2e50..1c02c67e42 100644 --- a/railties/test/generators/assets_generator_test.rb +++ b/railties/test/generators/assets_generator_test.rb @@ -1,5 +1,5 @@ -require 'generators/generators_test_helper' -require 'rails/generators/rails/assets/assets_generator' +require "generators/generators_test_helper" +require "rails/generators/rails/assets/assets_generator" class AssetsGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper diff --git a/railties/test/generators/channel_generator_test.rb b/railties/test/generators/channel_generator_test.rb index e3edde681f..a1d54200ba 100644 --- a/railties/test/generators/channel_generator_test.rb +++ b/railties/test/generators/channel_generator_test.rb @@ -1,12 +1,12 @@ -require 'generators/generators_test_helper' -require 'rails/generators/channel/channel_generator' +require "generators/generators_test_helper" +require "rails/generators/channel/channel_generator" class ChannelGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper tests Rails::Generators::ChannelGenerator def test_application_cable_skeleton_is_created - run_generator ['books'] + run_generator ["books"] assert_file "app/channels/application_cable/channel.rb" do |cable| assert_match(/module ApplicationCable\n class Channel < ActionCable::Channel::Base\n/, cable) @@ -18,7 +18,7 @@ class ChannelGeneratorTest < Rails::Generators::TestCase end def test_channel_is_created - run_generator ['chat'] + run_generator ["chat"] assert_file "app/channels/chat_channel.rb" do |channel| assert_match(/class ChatChannel < ApplicationCable::Channel/, channel) @@ -30,7 +30,7 @@ class ChannelGeneratorTest < Rails::Generators::TestCase end def test_channel_with_multiple_actions_is_created - run_generator ['chat', 'speak', 'mute'] + run_generator ["chat", "speak", "mute"] assert_file "app/channels/chat_channel.rb" do |channel| assert_match(/class ChatChannel < ApplicationCable::Channel/, channel) @@ -46,7 +46,7 @@ class ChannelGeneratorTest < Rails::Generators::TestCase end def test_channel_asset_is_not_created_when_skip_assets_is_passed - run_generator ['chat', '--skip-assets'] + run_generator ["chat", "--skip-assets"] assert_file "app/channels/chat_channel.rb" do |channel| assert_match(/class ChatChannel < ApplicationCable::Channel/, channel) @@ -56,16 +56,16 @@ class ChannelGeneratorTest < Rails::Generators::TestCase end def test_cable_js_is_created_if_not_present_already - run_generator ['chat'] + run_generator ["chat"] FileUtils.rm("#{destination_root}/app/assets/javascripts/cable.js") - run_generator ['camp'] + run_generator ["camp"] assert_file "app/assets/javascripts/cable.js" end def test_channel_on_revoke - run_generator ['chat'] - run_generator ['chat'], behavior: :revoke + run_generator ["chat"] + run_generator ["chat"], behavior: :revoke assert_no_file "app/channels/chat_channel.rb" assert_no_file "app/assets/javascripts/channels/chat.js" diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb index 1351151afb..af86a0136f 100644 --- a/railties/test/generators/controller_generator_test.rb +++ b/railties/test/generators/controller_generator_test.rb @@ -1,5 +1,5 @@ -require 'generators/generators_test_helper' -require 'rails/generators/rails/controller/controller_generator' +require "generators/generators_test_helper" +require "rails/generators/rails/controller/controller_generator" class ControllerGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper @@ -19,7 +19,7 @@ class ControllerGeneratorTest < Rails::Generators::TestCase def test_check_class_collision Object.send :const_set, :ObjectController, Class.new - content = capture(:stderr){ run_generator ["object"] } + content = capture(:stderr) { run_generator ["object"] } assert_match(/The name 'ObjectController' is either already used in your application or reserved/, content) ensure Object.send :remove_const, :ObjectController @@ -65,7 +65,7 @@ class ControllerGeneratorTest < Rails::Generators::TestCase def test_add_routes run_generator - assert_file "config/routes.rb", /get 'account\/foo'/, /get 'account\/bar'/ + assert_file "config/routes.rb", /^ get 'account\/foo'/, /^ get 'account\/bar'/ end def test_skip_routes diff --git a/railties/test/generators/create_migration_test.rb b/railties/test/generators/create_migration_test.rb index e16a77479a..ddd40e4d02 100644 --- a/railties/test/generators/create_migration_test.rb +++ b/railties/test/generators/create_migration_test.rb @@ -1,5 +1,5 @@ -require 'generators/generators_test_helper' -require 'rails/generators/rails/migration/migration_generator' +require "generators/generators_test_helper" +require "rails/generators/rails/migration/migration_generator" class CreateMigrationTest < Rails::Generators::TestCase include GeneratorsTestHelper @@ -19,12 +19,12 @@ class CreateMigrationTest < Rails::Generators::TestCase end def create_migration(destination_path = default_destination_path, config = {}, generator_options = {}, &block) - migration_name = File.basename(destination_path, '.rb') + migration_name = File.basename(destination_path, ".rb") generator([migration_name], generator_options) generator.set_migration_assigns!(destination_path) dir, base = File.split(destination_path) - timestamped_destination_path = File.join(dir, ["%migration_number%", base].join('_')) + timestamped_destination_path = File.join(dir, ["%migration_number%", base].join("_")) @migration = Rails::Generators::Actions::CreateMigration.new(generator, timestamped_destination_path, block || "contents", config) end @@ -51,7 +51,7 @@ class CreateMigrationTest < Rails::Generators::TestCase end def test_invoke_pretended - create_migration(default_destination_path, {}, { pretend: true }) + create_migration(default_destination_path, {}, pretend: true) assert_no_file @migration.destination end @@ -92,7 +92,7 @@ class CreateMigrationTest < Rails::Generators::TestCase def test_invoke_forced_pretended_when_exists_not_identical migration_exists! - create_migration(default_destination_path, { force: true }, { pretend: true }) do + create_migration(default_destination_path, { force: true }, pretend: true) do "different content" end @@ -104,7 +104,7 @@ class CreateMigrationTest < Rails::Generators::TestCase def test_invoke_skipped_when_exists_not_identical migration_exists! - create_migration(default_destination_path, {}, { skip: true }) { "different content" } + create_migration(default_destination_path, {}, skip: true) { "different content" } assert_match(/skip db\/migrate\/2_create_articles.rb\n/, invoke!) assert_no_file @migration.destination @@ -120,7 +120,7 @@ class CreateMigrationTest < Rails::Generators::TestCase def test_revoke_pretended migration_exists! - create_migration(default_destination_path, {}, { pretend: true }) + create_migration(default_destination_path, {}, pretend: true) assert_match(/remove db\/migrate\/1_create_articles.rb\n/, revoke!) assert_file @existing_migration.destination diff --git a/railties/test/generators/generated_attribute_test.rb b/railties/test/generators/generated_attribute_test.rb index ee7c009305..97847c8624 100644 --- a/railties/test/generators/generated_attribute_test.rb +++ b/railties/test/generators/generated_attribute_test.rb @@ -1,5 +1,5 @@ -require 'generators/generators_test_helper' -require 'rails/generators/generated_attribute' +require "generators/generators_test_helper" +require "rails/generators/generated_attribute" class GeneratedAttributeTest < Rails::Generators::TestCase include GeneratorsTestHelper @@ -51,7 +51,7 @@ class GeneratedAttributeTest < Rails::Generators::TestCase end def test_default_value_is_decimal - assert_field_default_value :decimal, '9.99' + assert_field_default_value :decimal, "9.99" end def test_default_value_is_datetime @@ -65,7 +65,7 @@ class GeneratedAttributeTest < Rails::Generators::TestCase end def test_default_value_is_string - assert_field_default_value :string, 'MyString' + assert_field_default_value :string, "MyString" end def test_default_value_for_type @@ -74,7 +74,7 @@ class GeneratedAttributeTest < Rails::Generators::TestCase end def test_default_value_is_text - assert_field_default_value :text, 'MyText' + assert_field_default_value :text, "MyText" end def test_default_value_is_boolean @@ -89,14 +89,14 @@ class GeneratedAttributeTest < Rails::Generators::TestCase def test_default_value_is_empty_string %w(foo bar baz).each do |attribute_type| - assert_field_default_value attribute_type, '' + assert_field_default_value attribute_type, "" end end def test_human_name assert_equal( - 'Full name', - create_generated_attribute(:string, 'full_name').human_name + "Full name", + create_generated_attribute(:string, "full_name").human_name ) end @@ -125,21 +125,21 @@ class GeneratedAttributeTest < Rails::Generators::TestCase end def test_blank_type_defaults_to_string_raises_exception - assert_equal :string, create_generated_attribute(nil, 'title').type - assert_equal :string, create_generated_attribute("", 'title').type + assert_equal :string, create_generated_attribute(nil, "title").type + assert_equal :string, create_generated_attribute("", "title").type end def test_handles_index_names_for_references - assert_equal "post", create_generated_attribute('string', 'post').index_name - assert_equal "post_id", create_generated_attribute('references', 'post').index_name - assert_equal "post_id", create_generated_attribute('belongs_to', 'post').index_name - assert_equal ["post_id", "post_type"], create_generated_attribute('references{polymorphic}', 'post').index_name + assert_equal "post", create_generated_attribute("string", "post").index_name + assert_equal "post_id", create_generated_attribute("references", "post").index_name + assert_equal "post_id", create_generated_attribute("belongs_to", "post").index_name + assert_equal ["post_id", "post_type"], create_generated_attribute("references{polymorphic}", "post").index_name end def test_handles_column_names_for_references - assert_equal "post", create_generated_attribute('string', 'post').column_name - assert_equal "post_id", create_generated_attribute('references', 'post').column_name - assert_equal "post_id", create_generated_attribute('belongs_to', 'post').column_name + assert_equal "post", create_generated_attribute("string", "post").column_name + assert_equal "post_id", create_generated_attribute("references", "post").column_name + assert_equal "post_id", create_generated_attribute("belongs_to", "post").column_name end def test_parse_required_attribute_with_index diff --git a/railties/test/generators/generator_generator_test.rb b/railties/test/generators/generator_generator_test.rb index dcfeaaa8e0..5ff8bb0357 100644 --- a/railties/test/generators/generator_generator_test.rb +++ b/railties/test/generators/generator_generator_test.rb @@ -1,5 +1,5 @@ -require 'generators/generators_test_helper' -require 'rails/generators/rails/generator/generator_generator' +require "generators/generators_test_helper" +require "rails/generators/rails/generator/generator_generator" class GeneratorGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper @@ -12,7 +12,7 @@ class GeneratorGeneratorTest < Rails::Generators::TestCase lib/generators/awesome lib/generators/awesome/USAGE lib/generators/awesome/templates - ).each{ |path| assert_file path } + ).each { |path| assert_file path } assert_file "lib/generators/awesome/awesome_generator.rb", /class AwesomeGenerator < Rails::Generators::NamedBase/ @@ -28,7 +28,7 @@ class GeneratorGeneratorTest < Rails::Generators::TestCase lib/generators/rails/awesome lib/generators/rails/awesome/USAGE lib/generators/rails/awesome/templates - ).each{ |path| assert_file path } + ).each { |path| assert_file path } assert_file "lib/generators/rails/awesome/awesome_generator.rb", /class Rails::AwesomeGenerator < Rails::Generators::NamedBase/ @@ -44,7 +44,7 @@ class GeneratorGeneratorTest < Rails::Generators::TestCase lib/generators/ lib/generators/USAGE lib/generators/templates - ).each{ |path| assert_file path } + ).each { |path| assert_file path } assert_file "lib/generators/awesome_generator.rb", /class AwesomeGenerator < Rails::Generators::NamedBase/ @@ -60,7 +60,7 @@ class GeneratorGeneratorTest < Rails::Generators::TestCase lib/generators/rails lib/generators/rails/USAGE lib/generators/rails/templates - ).each{ |path| assert_file path } + ).each { |path| assert_file path } assert_file "lib/generators/rails/awesome_generator.rb", /class Rails::AwesomeGenerator < Rails::Generators::NamedBase/ diff --git a/railties/test/generators/generator_test.rb b/railties/test/generators/generator_test.rb index 8ef44a8dcb..904bade658 100644 --- a/railties/test/generators/generator_test.rb +++ b/railties/test/generators/generator_test.rb @@ -1,6 +1,6 @@ -require 'active_support/test_case' -require 'active_support/testing/autorun' -require 'rails/generators/app_base' +require "active_support/test_case" +require "active_support/testing/autorun" +require "rails/generators/app_base" module Rails module Generators @@ -20,47 +20,47 @@ module Rails end def test_construction - klass = make_builder_class - assert klass.start(['new', 'blah']) + klass = make_builder_class + assert klass.start(["new", "blah"]) end def test_add_gem klass = make_builder_class - generator = klass.start(['new', 'blah']) - generator.gemfile_entry 'tenderlove' - assert_includes generator.gemfile_entries.map(&:name), 'tenderlove' + generator = klass.start(["new", "blah"]) + generator.gemfile_entry "tenderlove" + assert_includes generator.gemfile_entries.map(&:name), "tenderlove" end def test_add_gem_with_version klass = make_builder_class - generator = klass.start(['new', 'blah']) - generator.gemfile_entry 'tenderlove', '2.0.0' + generator = klass.start(["new", "blah"]) + generator.gemfile_entry "tenderlove", "2.0.0" assert generator.gemfile_entries.find { |gfe| - gfe.name == 'tenderlove' && gfe.version == '2.0.0' + gfe.name == "tenderlove" && gfe.version == "2.0.0" } end def test_add_github_gem klass = make_builder_class - generator = klass.start(['new', 'blah']) - generator.gemfile_entry 'tenderlove', github: 'hello world' + generator = klass.start(["new", "blah"]) + generator.gemfile_entry "tenderlove", github: "hello world" assert generator.gemfile_entries.find { |gfe| - gfe.name == 'tenderlove' && gfe.options[:github] == 'hello world' + gfe.name == "tenderlove" && gfe.options[:github] == "hello world" } end def test_add_path_gem klass = make_builder_class - generator = klass.start(['new', 'blah']) - generator.gemfile_entry 'tenderlove', path: 'hello world' + generator = klass.start(["new", "blah"]) + generator.gemfile_entry "tenderlove", path: "hello world" assert generator.gemfile_entries.find { |gfe| - gfe.name == 'tenderlove' && gfe.options[:path] == 'hello world' + gfe.name == "tenderlove" && gfe.options[:path] == "hello world" } end def test_filter klass = make_builder_class - generator = klass.start(['new', 'blah']) + generator = klass.start(["new", "blah"]) gems = generator.gemfile_entries generator.add_gem_entry_filter { |gem| gem.name != gems.first.name @@ -70,7 +70,7 @@ module Rails def test_two_filters klass = make_builder_class - generator = klass.start(['new', 'blah']) + generator = klass.start(["new", "blah"]) gems = generator.gemfile_entries generator.add_gem_entry_filter { |gem| gem.name != gems.first.name @@ -83,17 +83,17 @@ module Rails def test_recommended_rails_versions klass = make_builder_class - generator = klass.start(['new', 'blah']) + generator = klass.start(["new", "blah"]) specifier_for = -> v { generator.send(:rails_version_specifier, Gem::Version.new(v)) } - assert_equal '~> 4.1.13', specifier_for['4.1.13'] - assert_equal ['>= 4.1.6.rc1', '< 4.2'], specifier_for['4.1.6.rc1'] - assert_equal ['~> 4.1.7', '>= 4.1.7.1'], specifier_for['4.1.7.1'] - assert_equal ['~> 4.1.7', '>= 4.1.7.1.2'], specifier_for['4.1.7.1.2'] - assert_equal ['>= 4.1.7.1.rc2', '< 4.2'], specifier_for['4.1.7.1.rc2'] - assert_equal ['>= 4.2.0.beta1', '< 4.3'], specifier_for['4.2.0.beta1'] - assert_equal ['>= 5.0.0.beta1', '< 5.1'], specifier_for['5.0.0.beta1'] + assert_equal "~> 4.1.13", specifier_for["4.1.13"] + assert_equal [">= 4.1.6.rc1", "< 4.2"], specifier_for["4.1.6.rc1"] + assert_equal ["~> 4.1.7", ">= 4.1.7.1"], specifier_for["4.1.7.1"] + assert_equal ["~> 4.1.7", ">= 4.1.7.1.2"], specifier_for["4.1.7.1.2"] + assert_equal [">= 4.1.7.1.rc2", "< 4.2"], specifier_for["4.1.7.1.rc2"] + assert_equal [">= 4.2.0.beta1", "< 4.3"], specifier_for["4.2.0.beta1"] + assert_equal [">= 5.0.0.beta1", "< 5.1"], specifier_for["5.0.0.beta1"] end end end diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb index b19a5a7144..2cdddc8713 100644 --- a/railties/test/generators/generators_test_helper.rb +++ b/railties/test/generators/generators_test_helper.rb @@ -1,15 +1,15 @@ -require 'abstract_unit' -require 'active_support/core_ext/module/remove_method' -require 'active_support/testing/stream' -require 'active_support/testing/method_call_assertions' -require 'rails/generators' -require 'rails/generators/test_case' +require "abstract_unit" +require "active_support/core_ext/module/remove_method" +require "active_support/testing/stream" +require "active_support/testing/method_call_assertions" +require "rails/generators" +require "rails/generators/test_case" module Rails class << self remove_possible_method :root def root - @root ||= Pathname.new(File.expand_path('../../fixtures', __FILE__)) + @root ||= Pathname.new(File.expand_path("../../fixtures", __FILE__)) end end end @@ -20,9 +20,9 @@ Rails.application.config.generators.templates = [File.join(Rails.root, "lib", "t # Rails.application.config.generators to Rails::Generators Rails.application.load_generators -require 'active_record' -require 'action_dispatch' -require 'action_view' +require "active_record" +require "action_dispatch" +require "action_view" module GeneratorsTestHelper include ActiveSupport::Testing::Stream @@ -34,7 +34,7 @@ module GeneratorsTestHelper setup :prepare_destination begin - base.tests Rails::Generators.const_get(base.name.sub(/Test$/, '')) + base.tests Rails::Generators.const_get(base.name.sub(/Test$/, "")) rescue end end @@ -46,5 +46,4 @@ module GeneratorsTestHelper FileUtils.mkdir_p(destination) FileUtils.cp routes, destination end - end diff --git a/railties/test/generators/helper_generator_test.rb b/railties/test/generators/helper_generator_test.rb index add04f21a4..d9e6e0a85a 100644 --- a/railties/test/generators/helper_generator_test.rb +++ b/railties/test/generators/helper_generator_test.rb @@ -1,5 +1,5 @@ -require 'generators/generators_test_helper' -require 'rails/generators/rails/helper/helper_generator' +require "generators/generators_test_helper" +require "rails/generators/rails/helper/helper_generator" ObjectHelper = Class.new AnotherObjectHelperTest = Class.new @@ -14,7 +14,7 @@ class HelperGeneratorTest < Rails::Generators::TestCase end def test_check_class_collision - content = capture(:stderr){ run_generator ["object"] } + content = capture(:stderr) { run_generator ["object"] } assert_match(/The name 'ObjectHelper' is either already used in your application or reserved/, content) end diff --git a/railties/test/generators/integration_test_generator_test.rb b/railties/test/generators/integration_test_generator_test.rb index d05ed76d24..8bcc02440a 100644 --- a/railties/test/generators/integration_test_generator_test.rb +++ b/railties/test/generators/integration_test_generator_test.rb @@ -1,5 +1,5 @@ -require 'generators/generators_test_helper' -require 'rails/generators/rails/integration_test/integration_test_generator' +require "generators/generators_test_helper" +require "rails/generators/rails/integration_test/integration_test_generator" class IntegrationTestGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper diff --git a/railties/test/generators/job_generator_test.rb b/railties/test/generators/job_generator_test.rb index dbff0ab704..68d158eb39 100644 --- a/railties/test/generators/job_generator_test.rb +++ b/railties/test/generators/job_generator_test.rb @@ -1,5 +1,5 @@ -require 'generators/generators_test_helper' -require 'rails/generators/job/job_generator' +require "generators/generators_test_helper" +require "rails/generators/job/job_generator" class JobGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper diff --git a/railties/test/generators/mailer_generator_test.rb b/railties/test/generators/mailer_generator_test.rb index 6a4951840d..7d69d7470d 100644 --- a/railties/test/generators/mailer_generator_test.rb +++ b/railties/test/generators/mailer_generator_test.rb @@ -1,5 +1,5 @@ -require 'generators/generators_test_helper' -require 'rails/generators/mailer/mailer_generator' +require "generators/generators_test_helper" +require "rails/generators/mailer/mailer_generator" class MailerGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper @@ -13,7 +13,7 @@ class MailerGeneratorTest < Rails::Generators::TestCase assert_no_match(/layout :mailer_notifier/, mailer) end - assert_file 'app/mailers/application_mailer.rb' do |mailer| + assert_file "app/mailers/application_mailer.rb" do |mailer| assert_match(/class ApplicationMailer < ActionMailer::Base/, mailer) assert_match(/default from: 'from@example.com'/, mailer) assert_match(/layout 'mailer'/, mailer) @@ -30,7 +30,7 @@ class MailerGeneratorTest < Rails::Generators::TestCase def test_check_class_collision Object.send :const_set, :NotifierMailer, Class.new - content = capture(:stderr){ run_generator } + content = capture(:stderr) { run_generator } assert_match(/The name 'NotifierMailer' is either already used in your application or reserved/, content) ensure Object.send :remove_const, :NotifierMailer @@ -59,7 +59,7 @@ class MailerGeneratorTest < Rails::Generators::TestCase def test_check_test_class_collision Object.send :const_set, :NotifierMailerTest, Class.new - content = capture(:stderr){ run_generator } + content = capture(:stderr) { run_generator } assert_match(/The name 'NotifierMailerTest' is either already used in your application or reserved/, content) ensure Object.send :remove_const, :NotifierMailerTest @@ -67,7 +67,7 @@ class MailerGeneratorTest < Rails::Generators::TestCase def test_check_preview_class_collision Object.send :const_set, :NotifierMailerPreview, Class.new - content = capture(:stderr){ run_generator } + content = capture(:stderr) { run_generator } assert_match(/The name 'NotifierMailerPreview' is either already used in your application or reserved/, content) ensure Object.send :remove_const, :NotifierMailerPreview diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb index 46154b7db2..6e1d1b70a9 100644 --- a/railties/test/generators/migration_generator_test.rb +++ b/railties/test/generators/migration_generator_test.rb @@ -1,5 +1,5 @@ -require 'generators/generators_test_helper' -require 'rails/generators/rails/migration/migration_generator' +require "generators/generators_test_helper" +require "rails/generators/rails/migration/migration_generator" class MigrationGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper @@ -17,7 +17,7 @@ class MigrationGeneratorTest < Rails::Generators::TestCase run_generator [migration] file_name = migration_file_name "db/migrate/#{migration}.rb" - File.basename(file_name).split('_').first + File.basename(file_name).split("_").first end assert_not_equal first_migration_number, second_migration_number @@ -248,7 +248,7 @@ class MigrationGeneratorTest < Rails::Generators::TestCase def test_migration_with_singular_table_name with_singular_table_name do migration = "add_title_body_to_post" - run_generator [migration, 'title:string'] + run_generator [migration, "title:string"] assert_migration "db/migrate/#{migration}.rb" do |content| assert_method :change, content do |change| assert_match(/add_column :post, :title, :string/, change) diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index 6b30c40476..2b9f3ed7f2 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -1,18 +1,18 @@ -require 'generators/generators_test_helper' -require 'rails/generators/rails/model/model_generator' -require 'active_support/core_ext/string/strip' +require "generators/generators_test_helper" +require "rails/generators/rails/model/model_generator" +require "active_support/core_ext/string/strip" class ModelGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper arguments %w(Account name:string age:integer) - def test_application_record_skeleton_is_created - run_generator - assert_file "app/models/application_record.rb" do |record| - assert_match(/class ApplicationRecord < ActiveRecord::Base/, record) - assert_match(/self.abstract_class = true/, record) - end - end + def test_application_record_skeleton_is_created + run_generator + assert_file "app/models/application_record.rb" do |record| + assert_match(/class ApplicationRecord < ActiveRecord::Base/, record) + assert_match(/self.abstract_class = true/, record) + end + end def test_help_shows_invoked_generators_options content = run_generator ["--help"] @@ -212,10 +212,10 @@ class ModelGeneratorTest < Rails::Generators::TestCase def test_migration_without_timestamps ActiveRecord::Base.timestamped_migrations = false run_generator ["account"] - assert_file "db/migrate/001_create_accounts.rb", /class CreateAccounts < ActiveRecord::Migration\[[0-9.]+\]/ + assert_file "db/migrate/001_create_accounts.rb", /class CreateAccounts < ActiveRecord::Migration\[[0-9.]+\]/ run_generator ["project"] - assert_file "db/migrate/002_create_projects.rb", /class CreateProjects < ActiveRecord::Migration\[[0-9.]+\]/ + assert_file "db/migrate/002_create_projects.rb", /class CreateProjects < ActiveRecord::Migration\[[0-9.]+\]/ ensure ActiveRecord::Base.timestamped_migrations = true end @@ -275,7 +275,7 @@ class ModelGeneratorTest < Rails::Generators::TestCase def test_migration_error_is_not_shown_on_revoke run_generator - error = capture(:stderr){ run_generator ["Account"], behavior: :revoke } + error = capture(:stderr) { run_generator ["Account"], behavior: :revoke } assert_no_match(/Another migration is already named create_accounts/, error) end @@ -300,7 +300,7 @@ class ModelGeneratorTest < Rails::Generators::TestCase assert_file "test/fixtures/accounts.yml", /name: MyString/, /age: 1/ assert_generated_fixture("test/fixtures/accounts.yml", - {"one"=>{"name"=>"MyString", "age"=>1}, "two"=>{"name"=>"MyString", "age"=>1}}) + "one" => { "name" => "MyString", "age" => 1 }, "two" => { "name" => "MyString", "age" => 1 }) end def test_fixtures_use_the_references_ids @@ -308,7 +308,7 @@ class ModelGeneratorTest < Rails::Generators::TestCase assert_file "test/fixtures/line_items.yml", /product: one\n cart: one/ assert_generated_fixture("test/fixtures/line_items.yml", - {"one"=>{"product"=>"one", "cart"=>"one"}, "two"=>{"product"=>"two", "cart"=>"two"}}) + "one" => { "product" => "one", "cart" => "one" }, "two" => { "product" => "two", "cart" => "two" }) end def test_fixtures_use_the_references_ids_and_type @@ -316,15 +316,15 @@ class ModelGeneratorTest < Rails::Generators::TestCase assert_file "test/fixtures/line_items.yml", /product: one\n product_type: Product\n cart: one/ assert_generated_fixture("test/fixtures/line_items.yml", - {"one"=>{"product"=>"one", "product_type"=>"Product", "cart"=>"one"}, - "two"=>{"product"=>"two", "product_type"=>"Product", "cart"=>"two"}}) + "one" => { "product" => "one", "product_type" => "Product", "cart" => "one" }, + "two" => { "product" => "two", "product_type" => "Product", "cart" => "two" }) end def test_fixtures_respect_reserved_yml_keywords run_generator ["LineItem", "no:integer", "Off:boolean", "ON:boolean"] assert_generated_fixture("test/fixtures/line_items.yml", - {"one"=>{"no"=>1, "Off"=>false, "ON"=>false}, "two"=>{"no"=>1, "Off"=>false, "ON"=>false}}) + "one" => { "no" => 1, "Off" => false, "ON" => false }, "two" => { "no" => 1, "Off" => false, "ON" => false }) end def test_fixture_is_skipped @@ -343,13 +343,13 @@ class ModelGeneratorTest < Rails::Generators::TestCase ActiveRecord::Base.pluralize_table_names = false run_generator assert_generated_fixture("test/fixtures/account.yml", - {"one"=>{"name"=>"MyString", "age"=>1}, "two"=>{"name"=>"MyString", "age"=>1}}) + "one" => { "name" => "MyString", "age" => 1 }, "two" => { "name" => "MyString", "age" => 1 }) ensure ActiveRecord::Base.pluralize_table_names = original_pluralize_table_name end def test_check_class_collision - content = capture(:stderr){ run_generator ["object"] } + content = capture(:stderr) { run_generator ["object"] } assert_match(/The name 'Object' is either already used in your application or reserved/, content) end diff --git a/railties/test/generators/named_base_test.rb b/railties/test/generators/named_base_test.rb index 291f5e06c3..3015b5363b 100644 --- a/railties/test/generators/named_base_test.rb +++ b/railties/test/generators/named_base_test.rb @@ -1,84 +1,84 @@ -require 'generators/generators_test_helper' -require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator' +require "generators/generators_test_helper" +require "rails/generators/rails/scaffold_controller/scaffold_controller_generator" class NamedBaseTest < Rails::Generators::TestCase include GeneratorsTestHelper tests Rails::Generators::ScaffoldControllerGenerator def test_named_generator_with_underscore - g = generator ['line_item'] - assert_name g, 'line_item', :name + g = generator ["line_item"] + assert_name g, "line_item", :name assert_name g, %w(), :class_path - assert_name g, 'LineItem', :class_name - assert_name g, 'line_item', :file_path - assert_name g, 'line_item', :file_name - assert_name g, 'Line item', :human_name - assert_name g, 'line_item', :singular_name - assert_name g, 'line_items', :plural_name - assert_name g, 'line_item', :i18n_scope - assert_name g, 'line_items', :table_name + assert_name g, "LineItem", :class_name + assert_name g, "line_item", :file_path + assert_name g, "line_item", :file_name + assert_name g, "Line item", :human_name + assert_name g, "line_item", :singular_name + assert_name g, "line_items", :plural_name + assert_name g, "line_item", :i18n_scope + assert_name g, "line_items", :table_name end def test_named_generator_attributes - g = generator ['admin/foo'] - assert_name g, 'admin/foo', :name + g = generator ["admin/foo"] + assert_name g, "admin/foo", :name assert_name g, %w(admin), :class_path - assert_name g, 'Admin::Foo', :class_name - assert_name g, 'admin/foo', :file_path - assert_name g, 'foo', :file_name - assert_name g, 'Foo', :human_name - assert_name g, 'foo', :singular_name - assert_name g, 'foos', :plural_name - assert_name g, 'admin.foo', :i18n_scope - assert_name g, 'admin_foos', :table_name + assert_name g, "Admin::Foo", :class_name + assert_name g, "admin/foo", :file_path + assert_name g, "foo", :file_name + assert_name g, "Foo", :human_name + assert_name g, "foo", :singular_name + assert_name g, "foos", :plural_name + assert_name g, "admin.foo", :i18n_scope + assert_name g, "admin_foos", :table_name end def test_named_generator_attributes_as_ruby - g = generator ['Admin::Foo'] - assert_name g, 'Admin::Foo', :name + g = generator ["Admin::Foo"] + assert_name g, "Admin::Foo", :name assert_name g, %w(admin), :class_path - assert_name g, 'Admin::Foo', :class_name - assert_name g, 'admin/foo', :file_path - assert_name g, 'foo', :file_name - assert_name g, 'foo', :singular_name - assert_name g, 'Foo', :human_name - assert_name g, 'foos', :plural_name - assert_name g, 'admin.foo', :i18n_scope - assert_name g, 'admin_foos', :table_name + assert_name g, "Admin::Foo", :class_name + assert_name g, "admin/foo", :file_path + assert_name g, "foo", :file_name + assert_name g, "foo", :singular_name + assert_name g, "Foo", :human_name + assert_name g, "foos", :plural_name + assert_name g, "admin.foo", :i18n_scope + assert_name g, "admin_foos", :table_name end def test_named_generator_attributes_without_pluralized original_pluralize_table_names = ActiveRecord::Base.pluralize_table_names ActiveRecord::Base.pluralize_table_names = false - g = generator ['admin/foo'] - assert_name g, 'admin_foo', :table_name + g = generator ["admin/foo"] + assert_name g, "admin_foo", :table_name ensure ActiveRecord::Base.pluralize_table_names = original_pluralize_table_names end def test_scaffold_plural_names - g = generator ['admin/foo'] - assert_name g, 'admin/foos', :controller_name + g = generator ["admin/foo"] + assert_name g, "admin/foos", :controller_name assert_name g, %w(admin), :controller_class_path - assert_name g, 'Admin::Foos', :controller_class_name - assert_name g, 'admin/foos', :controller_file_path - assert_name g, 'foos', :controller_file_name - assert_name g, 'admin.foos', :controller_i18n_scope + assert_name g, "Admin::Foos", :controller_class_name + assert_name g, "admin/foos", :controller_file_path + assert_name g, "foos", :controller_file_name + assert_name g, "admin.foos", :controller_i18n_scope end def test_scaffold_plural_names_as_ruby - g = generator ['Admin::Foo'] - assert_name g, 'Admin::Foos', :controller_name + g = generator ["Admin::Foo"] + assert_name g, "Admin::Foos", :controller_name assert_name g, %w(admin), :controller_class_path - assert_name g, 'Admin::Foos', :controller_class_name - assert_name g, 'admin/foos', :controller_file_path - assert_name g, 'foos', :controller_file_name - assert_name g, 'admin.foos', :controller_i18n_scope + assert_name g, "Admin::Foos", :controller_class_name + assert_name g, "admin/foos", :controller_file_path + assert_name g, "foos", :controller_file_name + assert_name g, "admin.foos", :controller_i18n_scope end def test_application_name - g = generator ['Admin::Foo'] + g = generator ["Admin::Foo"] Rails.stub(:application, Object.new) do assert_name g, "object", :application_name end @@ -89,49 +89,49 @@ class NamedBaseTest < Rails::Generators::TestCase end def test_index_helper - g = generator ['Post'] - assert_name g, 'posts', :index_helper + g = generator ["Post"] + assert_name g, "posts", :index_helper end def test_index_helper_to_pluralize_once - g = generator ['Stadium'] - assert_name g, 'stadia', :index_helper + g = generator ["Stadium"] + assert_name g, "stadia", :index_helper end def test_index_helper_with_uncountable - g = generator ['Sheep'] - assert_name g, 'sheep_index', :index_helper + g = generator ["Sheep"] + assert_name g, "sheep_index", :index_helper end def test_hide_namespace - g = generator ['Hidden'] - g.class.stub(:namespace, 'hidden') do - assert !Rails::Generators.hidden_namespaces.include?('hidden') + g = generator ["Hidden"] + g.class.stub(:namespace, "hidden") do + assert_not_includes Rails::Generators.hidden_namespaces, "hidden" g.class.hide! - assert Rails::Generators.hidden_namespaces.include?('hidden') + assert_includes Rails::Generators.hidden_namespaces, "hidden" end end def test_scaffold_plural_names_with_model_name_option - g = generator ['Admin::Foo'], model_name: 'User' - assert_name g, 'user', :singular_name - assert_name g, 'User', :name - assert_name g, 'user', :file_path - assert_name g, 'User', :class_name - assert_name g, 'user', :file_name - assert_name g, 'User', :human_name - assert_name g, 'users', :plural_name - assert_name g, 'user', :i18n_scope - assert_name g, 'users', :table_name - assert_name g, 'Admin::Foos', :controller_name + g = generator ["Admin::Foo"], model_name: "User" + assert_name g, "user", :singular_name + assert_name g, "User", :name + assert_name g, "user", :file_path + assert_name g, "User", :class_name + assert_name g, "user", :file_name + assert_name g, "User", :human_name + assert_name g, "users", :plural_name + assert_name g, "user", :i18n_scope + assert_name g, "users", :table_name + assert_name g, "Admin::Foos", :controller_name assert_name g, %w(admin), :controller_class_path - assert_name g, 'Admin::Foos', :controller_class_name - assert_name g, 'admin/foos', :controller_file_path - assert_name g, 'foos', :controller_file_name - assert_name g, 'admin.foos', :controller_i18n_scope + assert_name g, "Admin::Foos", :controller_class_name + assert_name g, "admin/foos", :controller_file_path + assert_name g, "foos", :controller_file_name + assert_name g, "admin.foos", :controller_i18n_scope end - protected + private def assert_name(generator, value, method) assert_equal value, generator.send(method) diff --git a/railties/test/generators/namespaced_generators_test.rb b/railties/test/generators/namespaced_generators_test.rb index 902c340321..1caabbe6b1 100644 --- a/railties/test/generators/namespaced_generators_test.rb +++ b/railties/test/generators/namespaced_generators_test.rb @@ -1,8 +1,8 @@ -require 'generators/generators_test_helper' -require 'rails/generators/rails/controller/controller_generator' -require 'rails/generators/rails/model/model_generator' -require 'rails/generators/mailer/mailer_generator' -require 'rails/generators/rails/scaffold/scaffold_generator' +require "generators/generators_test_helper" +require "rails/generators/rails/controller/controller_generator" +require "rails/generators/rails/model/model_generator" +require "rails/generators/mailer/mailer_generator" +require "rails/generators/rails/scaffold/scaffold_generator" class NamespacedGeneratorTestCase < Rails::Generators::TestCase include GeneratorsTestHelper diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index 823dcc50ee..9921a80342 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) @@ -100,8 +100,16 @@ class PluginGeneratorTest < Rails::Generators::TestCase end end + def test_generating_adds_dummy_app_in_full_mode_without_sprockets + run_generator [destination_root, "-S", "--full"] + + assert_file "test/dummy/config/environments/production.rb" do |contents| + assert_no_match(/config\.assets/, contents) + end + 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 +207,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")}["']$} end def test_generation_does_not_run_bundle_install_with_full_and_mountable @@ -236,21 +244,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 +341,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 +458,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 +466,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 +481,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,10 +504,9 @@ 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) end end @@ -507,7 +514,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 +523,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 +546,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 +587,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 +598,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 +610,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 +618,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 +634,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 +651,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 +660,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 +674,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 +687,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 +702,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` @@ -708,10 +714,10 @@ class PluginGeneratorTest < Rails::Generators::TestCase end end - protected + private def action(*args, &block) - silence(:stdout){ generator.send(*args, &block) } + silence(:stdout) { generator.send(*args, &block) } end def default_files @@ -731,9 +737,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 diff --git a/railties/test/generators/plugin_test_helper.rb b/railties/test/generators/plugin_test_helper.rb index 96c1b1d31f..8ac90e3484 100644 --- a/railties/test/generators/plugin_test_helper.rb +++ b/railties/test/generators/plugin_test_helper.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'tmpdir' +require "abstract_unit" +require "tmpdir" module PluginTestHelper def create_test_file(name, pass: true) @@ -15,7 +15,7 @@ module PluginTestHelper RUBY end - def plugin_file(path, contents, mode: 'w') + def plugin_file(path, contents, mode: "w") FileUtils.mkdir_p File.dirname("#{plugin_path}/#{path}") File.open("#{plugin_path}/#{path}", mode) do |f| f.puts contents diff --git a/railties/test/generators/plugin_test_runner_test.rb b/railties/test/generators/plugin_test_runner_test.rb index ef6359fece..0bdf3b2726 100644 --- a/railties/test/generators/plugin_test_runner_test.rb +++ b/railties/test/generators/plugin_test_runner_test.rb @@ -1,12 +1,12 @@ -require 'generators/plugin_test_helper' +require "generators/plugin_test_helper" class PluginTestRunnerTest < ActiveSupport::TestCase include PluginTestHelper def setup - @destination_root = Dir.mktmpdir('bukkits') + @destination_root = Dir.mktmpdir("bukkits") Dir.chdir(@destination_root) { `bundle exec rails plugin new bukkits --skip-bundle` } - plugin_file 'test/dummy/db/schema.rb', '' + plugin_file "test/dummy/db/schema.rb", "" end def teardown @@ -14,20 +14,20 @@ class PluginTestRunnerTest < ActiveSupport::TestCase end def test_run_single_file - create_test_file 'foo' - create_test_file 'bar' + create_test_file "foo" + create_test_file "bar" assert_match "1 runs, 1 assertions, 0 failures", run_test_command("test/foo_test.rb") end def test_run_multiple_files - create_test_file 'foo' - create_test_file 'bar' + create_test_file "foo" + create_test_file "bar" assert_match "2 runs, 2 assertions, 0 failures", run_test_command("test/foo_test.rb test/bar_test.rb") end def test_mix_files_and_line_filters - create_test_file 'account' - plugin_file 'test/post_test.rb', <<-RUBY + create_test_file "account" + plugin_file "test/post_test.rb", <<-RUBY require 'test_helper' class PostTest < ActiveSupport::TestCase @@ -42,50 +42,56 @@ class PluginTestRunnerTest < ActiveSupport::TestCase end RUBY - run_test_command('test/account_test.rb test/post_test.rb:4').tap do |output| - assert_match 'AccountTest', output - assert_match 'PostTest', output - assert_match '2 runs, 2 assertions', output + run_test_command("test/account_test.rb test/post_test.rb:4").tap do |output| + assert_match "AccountTest", output + assert_match "PostTest", output + assert_match "2 runs, 2 assertions", output end end def test_multiple_line_filters - create_test_file 'account' - create_test_file 'post' + create_test_file "account" + create_test_file "post" - run_test_command('test/account_test.rb:4 test/post_test.rb:4').tap do |output| - assert_match 'AccountTest', output - assert_match 'PostTest', output + run_test_command("test/account_test.rb:4 test/post_test.rb:4").tap do |output| + assert_match "AccountTest", output + assert_match "PostTest", output end end def test_output_inline_by_default - create_test_file 'post', pass: false + create_test_file "post", pass: false - output = run_test_command('test/post_test.rb') + output = run_test_command("test/post_test.rb") expect = %r{Running:\n\nPostTest\nF\n\nFailure:\nPostTest#test_truth \[[^\]]+test/post_test.rb:6\]:\nwups!\n\nbin/test (/private)?#{plugin_path}/test/post_test.rb:4} assert_match expect, output end def test_only_inline_failure_output - create_test_file 'post', pass: false + create_test_file "post", pass: false - output = run_test_command('test/post_test.rb') + output = run_test_command("test/post_test.rb") assert_match %r{Finished in.*\n\n1 runs, 1 assertions}, output end def test_fail_fast - create_test_file 'post', pass: false + create_test_file "post", pass: false assert_match(/Interrupt/, - capture(:stderr) { run_test_command('test/post_test.rb --fail-fast') }) + capture(:stderr) { run_test_command("test/post_test.rb --fail-fast") }) end def test_raise_error_when_specified_file_does_not_exist - error = capture(:stderr) { run_test_command('test/not_exists.rb') } + error = capture(:stderr) { run_test_command("test/not_exists.rb") } assert_match(%r{cannot load such file.+test/not_exists\.rb}, error) end + def test_executed_only_once + create_test_file "foo" + result = run_test_command("test/foo_test.rb") + assert_equal 1, result.scan(/1 runs, 1 assertions, 0 failures/).length + end + private def plugin_path "#{@destination_root}/bukkits" diff --git a/railties/test/generators/resource_generator_test.rb b/railties/test/generators/resource_generator_test.rb index 53dcfc4024..e976e58180 100644 --- a/railties/test/generators/resource_generator_test.rb +++ b/railties/test/generators/resource_generator_test.rb @@ -1,5 +1,5 @@ -require 'generators/generators_test_helper' -require 'rails/generators/rails/resource/resource_generator' +require "generators/generators_test_helper" +require "rails/generators/rails/resource/resource_generator" class ResourceGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb index 736ff0b41f..bd23faf268 100644 --- a/railties/test/generators/scaffold_controller_generator_test.rb +++ b/railties/test/generators/scaffold_controller_generator_test.rb @@ -1,5 +1,5 @@ -require 'generators/generators_test_helper' -require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator' +require "generators/generators_test_helper" +require "rails/generators/rails/scaffold_controller/scaffold_controller_generator" module Unknown module Generators diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index bd69906b9d..6b7e2c91d7 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -1,5 +1,5 @@ -require 'generators/generators_test_helper' -require 'rails/generators/rails/scaffold/scaffold_generator' +require "generators/generators_test_helper" +require "rails/generators/rails/scaffold/scaffold_generator" class ScaffoldGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper @@ -74,8 +74,8 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase end assert_file "app/views/product_lines/_form.html.erb" do |test| - assert_match 'product_line', test - assert_no_match '@product_line', test + assert_match "product_line", test + assert_no_match "@product_line", test end # Helpers @@ -269,7 +269,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase def test_scaffold_with_namespace_on_revoke run_generator [ "admin/role", "name:string", "description:string" ] - run_generator [ "admin/role" ], :behavior => :revoke + run_generator [ "admin/role" ], behavior: :revoke # Model assert_file "app/models/admin.rb" # ( should not be remove ) @@ -310,7 +310,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase end File.open(route_path, "wb") { |file| file.write(content) } - run_generator ["product_line"], :behavior => :revoke + run_generator ["product_line"], behavior: :revoke assert_file "config/routes.rb", /\.routes\.draw do\s*\|map\|\s*$/ end @@ -322,13 +322,13 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase content = File.read(route_path) # Remove all of the comments and blank lines from the routes file - content.gsub!(/^ \#.*\n/, '') - content.gsub!(/^\n/, '') + content.gsub!(/^ \#.*\n/, "") + content.gsub!(/^\n/, "") File.open(route_path, "wb") { |file| file.write(content) } assert_file "config/routes.rb", /\.routes\.draw do\n resources :product_lines\nend\n\z/ - run_generator ["product_line"], :behavior => :revoke + run_generator ["product_line"], behavior: :revoke assert_file "config/routes.rb", /\.routes\.draw do\nend\n\z/ end diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb index 03ea521355..08b0e34fe2 100644 --- a/railties/test/generators/shared_generator_tests.rb +++ b/railties/test/generators/shared_generator_tests.rb @@ -5,7 +5,7 @@ module SharedGeneratorTests def setup Rails.application = TestApp::Application super - Rails::Generators::AppGenerator.instance_variable_set('@desc', nil) + Rails::Generators::AppGenerator.instance_variable_set("@desc", nil) Kernel::silence_warnings do Thor::Base.shell.send(:attr_accessor, :always_force) @@ -16,7 +16,7 @@ module SharedGeneratorTests def teardown super - Rails::Generators::AppGenerator.instance_variable_set('@desc', nil) + Rails::Generators::AppGenerator.instance_variable_set("@desc", nil) Rails.application = TestApp::Application.instance end @@ -28,11 +28,11 @@ module SharedGeneratorTests def test_plugin_new_generate_pretend run_generator ["testapp", "--pretend"] - default_files.each{ |path| assert_no_file File.join("testapp",path) } + default_files.each { |path| assert_no_file File.join("testapp", path) } end def test_invalid_database_option_raises_an_error - content = capture(:stderr){ run_generator([destination_root, "-d", "unknown"]) } + content = capture(:stderr) { run_generator([destination_root, "-d", "unknown"]) } assert_match(/Invalid value for \-\-database option/, content) end @@ -44,14 +44,14 @@ module SharedGeneratorTests def test_name_collision_raises_an_error reserved_words = %w[application destroy plugin runner test] reserved_words.each do |reserved| - content = capture(:stderr){ run_generator [File.join(destination_root, reserved)] } + content = capture(:stderr) { run_generator [File.join(destination_root, reserved)] } assert_match(/Invalid \w+ name #{reserved}. Please give a name which does not match one of the reserved rails words: application, destroy, plugin, runner, test\n/, content) end end def test_name_raises_an_error_if_name_already_used_constant %w{ String Hash Class Module Set Symbol }.each do |ruby_class| - content = capture(:stderr){ run_generator [File.join(destination_root, ruby_class)] } + content = capture(:stderr) { run_generator [File.join(destination_root, ruby_class)] } assert_match(/Invalid \w+ name #{ruby_class}, constant #{ruby_class} is already in use. Please choose another \w+ name.\n/, content) end end @@ -68,7 +68,7 @@ module SharedGeneratorTests def test_template_raises_an_error_with_invalid_path quietly do - content = capture(:stderr){ run_generator([destination_root, "-m", "non/existent/path"]) } + content = capture(:stderr) { run_generator([destination_root, "-m", "non/existent/path"]) } assert_match(/The template \[.*\] could not be loaded/, content) assert_match(/non\/existent\/path/, content) @@ -81,7 +81,7 @@ module SharedGeneratorTests template.instance_eval "def read; self; end" # Make the string respond to read check_open = -> *args do - assert_equal [ path, 'Accept' => 'application/x-thor-template' ], args + assert_equal [ path, "Accept" => "application/x-thor-template" ], args template end @@ -93,7 +93,7 @@ module SharedGeneratorTests def test_skip_gemfile assert_not_called(generator([destination_root], skip_gemfile: true), :bundle_command) do quietly { generator.invoke_all } - assert_no_file 'Gemfile' + assert_no_file "Gemfile" end end @@ -102,22 +102,22 @@ module SharedGeneratorTests quietly { generator.invoke_all } # skip_bundle is only about running bundle install, ensure the Gemfile is still # generated. - assert_file 'Gemfile' + assert_file "Gemfile" end end def test_skip_git - run_generator [destination_root, '--skip-git', '--full'] - assert_no_file('.gitignore') + run_generator [destination_root, "--skip-git", "--full"] + assert_no_file(".gitignore") end def test_skip_keeps - run_generator [destination_root, '--skip-keeps', '--full'] + run_generator [destination_root, "--skip-keeps", "--full"] - assert_file '.gitignore' do |content| + assert_file ".gitignore" do |content| assert_no_match(/\.keep/, content) end - assert_no_file('app/models/concerns/.keep') + assert_no_file("app/models/concerns/.keep") end end diff --git a/railties/test/generators/task_generator_test.rb b/railties/test/generators/task_generator_test.rb index d5bd44b9db..2285534bb9 100644 --- a/railties/test/generators/task_generator_test.rb +++ b/railties/test/generators/task_generator_test.rb @@ -1,5 +1,5 @@ -require 'generators/generators_test_helper' -require 'rails/generators/rails/task/task_generator' +require "generators/generators_test_helper" +require "rails/generators/rails/task/task_generator" class TaskGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper @@ -15,10 +15,10 @@ class TaskGeneratorTest < Rails::Generators::TestCase end def test_task_on_revoke - task_path = 'lib/tasks/feeds.rake' + task_path = "lib/tasks/feeds.rake" run_generator assert_file task_path - run_generator ['feeds'], behavior: :revoke + run_generator ["feeds"], behavior: :revoke assert_no_file task_path end end diff --git a/railties/test/generators/test_runner_in_engine_test.rb b/railties/test/generators/test_runner_in_engine_test.rb index d37e261fbb..4b5fb3ba3f 100644 --- a/railties/test/generators/test_runner_in_engine_test.rb +++ b/railties/test/generators/test_runner_in_engine_test.rb @@ -1,12 +1,12 @@ -require 'generators/plugin_test_helper' +require "generators/plugin_test_helper" class TestRunnerInEngineTest < ActiveSupport::TestCase include PluginTestHelper def setup - @destination_root = Dir.mktmpdir('bukkits') + @destination_root = Dir.mktmpdir("bukkits") Dir.chdir(@destination_root) { `bundle exec rails plugin new bukkits --full --skip-bundle` } - plugin_file 'test/dummy/db/schema.rb', '' + plugin_file "test/dummy/db/schema.rb", "" end def teardown @@ -14,9 +14,9 @@ class TestRunnerInEngineTest < ActiveSupport::TestCase end def test_rerun_snippet_is_relative_path - create_test_file 'post', pass: false + create_test_file "post", pass: false - output = run_test_command('test/post_test.rb') + output = run_test_command("test/post_test.rb") expect = %r{Running:\n\nPostTest\nF\n\nFailure:\nPostTest#test_truth \[[^\]]+test/post_test.rb:6\]:\nwups!\n\nbin/rails test test/post_test.rb:4} assert_match expect, output end |