Skip to content

Commit

Permalink
Assert exact file output for plugins too
Browse files Browse the repository at this point in the history
In a [previous commit][1], the App Generator skeleton test was updated
to verify the exact file output when generating a new application. This
commit applies the same change to the Plugin Generator.

At first, I was hesitant to add the list of dummy app files to the
`default_files` for the Plugin Generator test, however it quickly became
apparent that it was a good idea. Making this change exposed that recent
file additions to the App Generator were added to the plugin's dummy app
as well. Things like CI files, rubocop configuration, and a brakeman
command should not be created for a dummy app, and are now properly
excluded.

Similar to the App Generator commit, this change also removes tests that
are now redundant due to the skeleton test verifying the exact list of
files generated.

[1]: e5e4b80
  • Loading branch information
skipkayhil committed Jan 28, 2024
1 parent e5e4b80 commit c278684
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,12 @@ def test
def generate_test_dummy(force = false)
opts = options.transform_keys(&:to_sym).except(*DUMMY_IGNORE_OPTIONS)
opts[:force] = force
opts[:skip_brakeman] = true
opts[:skip_bundle] = true
opts[:skip_ci] = true
opts[:skip_git] = true
opts[:skip_hotwire] = true
opts[:skip_rubocop] = true
opts[:dummy_app] = true

invoke Rails::Generators::AppGenerator,
Expand Down Expand Up @@ -144,7 +147,7 @@ def test_dummy_sprocket_assets
def test_dummy_clean
inside dummy_path do
remove_file ".ruby-version"
remove_file "db/seeds.rb"
remove_dir "db"
remove_file "Gemfile"
remove_file "lib/tasks"
remove_file "public/robots.txt"
Expand Down
94 changes: 56 additions & 38 deletions railties/test/generators/plugin_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,70 @@
require "rails/engine/updater"

DEFAULT_PLUGIN_FILES = %w(
.git
.gitignore
Gemfile
Rakefile
MIT-LICENSE
README.md
Rakefile
bin/test
bukkits.gemspec
MIT-LICENSE
lib
lib/bukkits.rb
lib/tasks/bukkits_tasks.rake
lib/bukkits/railtie.rb
lib/bukkits/version.rb
lib/tasks/bukkits_tasks.rake
test/bukkits_test.rb
test/dummy/Rakefile
test/dummy/app/assets/images/.keep
test/dummy/app/assets/stylesheets/application.css
test/dummy/app/channels/application_cable/channel.rb
test/dummy/app/channels/application_cable/connection.rb
test/dummy/app/controllers/application_controller.rb
test/dummy/app/controllers/concerns/.keep
test/dummy/app/helpers/application_helper.rb
test/dummy/app/jobs/application_job.rb
test/dummy/app/mailers/application_mailer.rb
test/dummy/app/models/application_record.rb
test/dummy/app/models/concerns/.keep
test/dummy/app/views/layouts/application.html.erb
test/dummy/app/views/layouts/mailer.html.erb
test/dummy/app/views/layouts/mailer.text.erb
test/dummy/app/views/pwa/manifest.json.erb
test/dummy/app/views/pwa/service-worker.js
test/dummy/bin/rails
test/dummy/bin/rake
test/dummy/bin/setup
test/dummy/config.ru
test/dummy/config/application.rb
test/dummy/config/boot.rb
test/dummy/config/cable.yml
test/dummy/config/database.yml
test/dummy/config/environment.rb
test/dummy/config/environments/development.rb
test/dummy/config/environments/production.rb
test/dummy/config/environments/test.rb
test/dummy/config/initializers/content_security_policy.rb
test/dummy/config/initializers/enable_yjit.rb
test/dummy/config/initializers/filter_parameter_logging.rb
test/dummy/config/initializers/inflections.rb
test/dummy/config/initializers/permissions_policy.rb
test/dummy/config/locales/en.yml
test/dummy/config/puma.rb
test/dummy/config/routes.rb
test/dummy/config/storage.yml
test/dummy/lib/assets/.keep
test/dummy/log/.keep
test/dummy/public/404.html
test/dummy/public/422.html
test/dummy/public/426.html
test/dummy/public/500.html
test/dummy/public/icon.png
test/dummy/public/icon.svg
test/dummy/storage/.keep
test/dummy/tmp/.keep
test/dummy/tmp/pids/.keep
test/dummy/tmp/storage/.keep
test/test_helper.rb
test/dummy
)

class PluginGeneratorTest < Rails::Generators::TestCase
Expand Down Expand Up @@ -68,8 +119,6 @@ def test_correct_file_in_lib_folder_of_camelcase_plugin_name
def test_generating_without_options
run_generator
assert_file "README.md", /Bukkits/
assert_no_file "config/routes.rb"
assert_no_file "app/assets/config/bukkits_manifest.js"
assert_file "test/test_helper.rb" do |content|
assert_match(/require_relative.+test\/dummy\/config\/environment/, content)
assert_match(/ActiveRecord::Migrator\.migrations_paths.+test\/dummy\/db\/migrate/, content)
Expand All @@ -83,13 +132,6 @@ def test_generating_without_options
assert_match(/class BukkitsTest < ActiveSupport::TestCase/, content)
assert_match(/assert Bukkits::VERSION/, content)
end
assert_file "bin/test"
assert_no_file "bin/rails"
end

def test_initializes_git_repo
run_generator
assert_directory ".git"
end

def test_initializes_git_repo_with_main_branch_without_user_default
Expand Down Expand Up @@ -176,12 +218,6 @@ def test_generating_adds_dummy_app_rake_tasks_without_unit_test_files
assert_file "bin/rails", /APP_PATH/
end

def test_generating_adds_dummy_app_without_javascript_and_assets_deps
run_generator

assert_file "test/dummy/app/assets/stylesheets/application.css"
end

def test_ensure_that_plugin_options_are_not_passed_to_app_generator
FileUtils.cd(fixtures_root)
assert_no_match(/It works from file!.*It works_from_file/, run_generator([destination_root, "-m", "lib/template.rb"]))
Expand Down Expand Up @@ -608,24 +644,6 @@ def test_ensure_that_gitignore_can_be_generated_from_a_template_for_dummy_path
end
end

def test_unnecessary_files_are_not_generated_in_dummy_application
run_generator
assert_no_file "test/dummy/.gitignore"
assert_no_file "test/dummy/.ruby-version"
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_file "test/dummy/config/master.key"
assert_no_file "test/dummy/config/credentials.yml.enc"
assert_no_file "test/dummy/Dockerfile"
assert_no_file "test/dummy/.dockerignore"
assert_no_directory "test/dummy/lib/tasks"
assert_no_directory "test/dummy/test"
assert_no_directory "test/dummy/vendor"
assert_no_directory "test/dummy/.git"
end

def test_skipping_test_files
run_generator [destination_root, "--skip-test"]
assert_no_directory "test"
Expand Down

0 comments on commit c278684

Please sign in to comment.