Skip to content

Commit 5606783

Browse files
authored
Merge pull request rails#50903 from skipkayhil/hm-exact-generator-assertions
Change skeleton test to assert exact file output
2 parents 44e2bc2 + c278684 commit 5606783

File tree

7 files changed

+125
-107
lines changed

7 files changed

+125
-107
lines changed

railties/lib/rails/generators/rails/app/app_generator.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,6 @@ def system_test
257257
def tmp
258258
empty_directory_with_keep_file "tmp"
259259
empty_directory_with_keep_file "tmp/pids"
260-
empty_directory "tmp/cache"
261-
empty_directory "tmp/cache/assets"
262260
end
263261

264262
def vendor
@@ -461,7 +459,6 @@ def delete_app_assets_if_api_option
461459
if options[:api]
462460
remove_dir "app/assets"
463461
remove_dir "lib/assets"
464-
remove_dir "tmp/cache/assets"
465462
end
466463
end
467464

railties/lib/rails/generators/rails/plugin/plugin_generator.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,12 @@ def test
112112
def generate_test_dummy(force = false)
113113
opts = options.transform_keys(&:to_sym).except(*DUMMY_IGNORE_OPTIONS)
114114
opts[:force] = force
115+
opts[:skip_brakeman] = true
115116
opts[:skip_bundle] = true
117+
opts[:skip_ci] = true
116118
opts[:skip_git] = true
117119
opts[:skip_hotwire] = true
120+
opts[:skip_rubocop] = true
118121
opts[:dummy_app] = true
119122

120123
invoke Rails::Generators::AppGenerator,
@@ -144,7 +147,7 @@ def test_dummy_sprocket_assets
144147
def test_dummy_clean
145148
inside dummy_path do
146149
remove_file ".ruby-version"
147-
remove_file "db/seeds.rb"
150+
remove_dir "db"
148151
remove_file "Gemfile"
149152
remove_file "lib/tasks"
150153
remove_file "public/robots.txt"

railties/lib/rails/tasks/tmp.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace :tmp do
77
tmp_dirs = [ "tmp/cache",
88
"tmp/sockets",
99
"tmp/pids",
10-
"tmp/cache/assets" ]
10+
]
1111

1212
tmp_dirs.each { |d| directory d }
1313

railties/test/generators/api_app_generator_test.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ def skipped_files
189189
config/initializers/permissions_policy.rb
190190
lib/assets
191191
test/helpers
192-
tmp/cache/assets
193192
public/404.html
194193
public/422.html
195194
public/426.html

railties/test/generators/app_generator_test.rb

Lines changed: 39 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,90 +5,88 @@
55
require "generators/shared_generator_tests"
66

77
DEFAULT_APP_FILES = %w(
8+
.dockerignore
9+
.git
810
.gitattributes
911
.github/dependabot.yml
1012
.github/workflows/ci.yml
1113
.gitignore
12-
.dockerignore
1314
.rubocop.yml
1415
.ruby-version
15-
README.md
16+
Dockerfile
1617
Gemfile
18+
README.md
1719
Rakefile
18-
Dockerfile
19-
config.ru
2020
app/assets/config/manifest.js
21-
app/assets/images
22-
app/assets/stylesheets
21+
app/assets/images/.keep
2322
app/assets/stylesheets/application.css
2423
app/channels/application_cable/channel.rb
2524
app/channels/application_cable/connection.rb
26-
app/controllers
2725
app/controllers/application_controller.rb
28-
app/controllers/concerns
29-
app/helpers
26+
app/controllers/concerns/.keep
3027
app/helpers/application_helper.rb
31-
app/mailers
28+
app/jobs/application_job.rb
3229
app/mailers/application_mailer.rb
33-
app/models
3430
app/models/application_record.rb
35-
app/models/concerns
36-
app/jobs
37-
app/jobs/application_job.rb
38-
app/views/layouts
31+
app/models/concerns/.keep
3932
app/views/layouts/application.html.erb
4033
app/views/layouts/mailer.html.erb
4134
app/views/layouts/mailer.text.erb
42-
bin/docker-entrypoint
35+
app/views/pwa/manifest.json.erb
36+
app/views/pwa/service-worker.js
4337
bin/brakeman
38+
bin/docker-entrypoint
4439
bin/rails
4540
bin/rake
4641
bin/rubocop
4742
bin/setup
43+
config.ru
4844
config/application.rb
4945
config/boot.rb
5046
config/cable.yml
47+
config/credentials.yml.enc
48+
config/database.yml
5149
config/environment.rb
52-
config/environments
5350
config/environments/development.rb
5451
config/environments/production.rb
5552
config/environments/test.rb
56-
config/initializers
5753
config/initializers/assets.rb
5854
config/initializers/content_security_policy.rb
5955
config/initializers/enable_yjit.rb
6056
config/initializers/filter_parameter_logging.rb
6157
config/initializers/inflections.rb
62-
config/locales
58+
config/initializers/permissions_policy.rb
6359
config/locales/en.yml
60+
config/master.key
6461
config/puma.rb
6562
config/routes.rb
66-
config/credentials.yml.enc
6763
config/storage.yml
68-
db
6964
db/seeds.rb
70-
lib
71-
lib/tasks
72-
lib/assets
73-
log
74-
public
75-
storage
65+
lib/assets/.keep
66+
lib/tasks/.keep
67+
log/.keep
68+
public/404.html
69+
public/422.html
70+
public/426.html
71+
public/500.html
72+
public/icon.png
73+
public/icon.svg
74+
public/robots.txt
75+
storage/.keep
7676
test/application_system_test_case.rb
77-
test/test_helper.rb
78-
test/fixtures
79-
test/fixtures/files
8077
test/channels/application_cable/connection_test.rb
81-
test/controllers
82-
test/models
83-
test/helpers
84-
test/mailers
85-
test/integration
86-
test/system
87-
vendor
88-
tmp
89-
tmp/cache
90-
tmp/cache/assets
91-
tmp/storage
78+
test/controllers/.keep
79+
test/fixtures/files/.keep
80+
test/helpers/.keep
81+
test/integration/.keep
82+
test/mailers/.keep
83+
test/models/.keep
84+
test/system/.keep
85+
test/test_helper.rb
86+
tmp/.keep
87+
tmp/pids/.keep
88+
tmp/storage/.keep
89+
vendor/.keep
9290
)
9391

9492
class AppGeneratorTest < Rails::Generators::TestCase
@@ -111,12 +109,6 @@ def test_skip_bundle
111109
assert_file "Gemfile"
112110
end
113111

114-
def test_assets
115-
run_generator
116-
117-
assert_file("app/assets/stylesheets/application.css")
118-
end
119-
120112
def test_invalid_javascript_option_raises_an_error
121113
content = capture(:stderr) { run_generator([destination_root, "-j", "unknown"]) }
122114
assert_match(/Expected '--javascript' to be one of/, content)
@@ -132,11 +124,6 @@ def test_invalid_css_option_raises_an_error
132124
assert_match(/Expected '--css' to be one of/, content)
133125
end
134126

135-
def test_application_job_file_present
136-
run_generator
137-
assert_file("app/jobs/application_job.rb")
138-
end
139-
140127
def test_invalid_application_name_raises_an_error
141128
content = capture(:stderr) { run_generator [File.join(destination_root, "43-things")] }
142129
assert_equal "Invalid application name 43-things. Please give a name which does not start with numbers.\n", content
@@ -183,17 +170,6 @@ def test_application_name_is_detected_if_it_exists_and_app_folder_renamed
183170
assert_file "#{app_moved_root}/config/environment.rb", /Rails\.application\.initialize!/
184171
end
185172

186-
def test_new_application_not_include_api_initializers
187-
run_generator
188-
189-
assert_no_file "config/initializers/cors.rb"
190-
end
191-
192-
def test_new_application_doesnt_need_defaults
193-
run_generator
194-
assert_empty Dir.glob("config/initializers/new_framework_defaults_*.rb", base: destination_root)
195-
end
196-
197173
def test_new_application_load_defaults
198174
run_generator
199175
assert_file "config/application.rb", /\s+config\.load_defaults #{Rails::VERSION::STRING.to_f}/

railties/test/generators/plugin_generator_test.rb

Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,70 @@
77
require "rails/engine/updater"
88

99
DEFAULT_PLUGIN_FILES = %w(
10+
.git
1011
.gitignore
1112
Gemfile
12-
Rakefile
13+
MIT-LICENSE
1314
README.md
15+
Rakefile
16+
bin/test
1417
bukkits.gemspec
15-
MIT-LICENSE
16-
lib
1718
lib/bukkits.rb
18-
lib/tasks/bukkits_tasks.rake
19+
lib/bukkits/railtie.rb
1920
lib/bukkits/version.rb
21+
lib/tasks/bukkits_tasks.rake
2022
test/bukkits_test.rb
23+
test/dummy/Rakefile
24+
test/dummy/app/assets/images/.keep
25+
test/dummy/app/assets/stylesheets/application.css
26+
test/dummy/app/channels/application_cable/channel.rb
27+
test/dummy/app/channels/application_cable/connection.rb
28+
test/dummy/app/controllers/application_controller.rb
29+
test/dummy/app/controllers/concerns/.keep
30+
test/dummy/app/helpers/application_helper.rb
31+
test/dummy/app/jobs/application_job.rb
32+
test/dummy/app/mailers/application_mailer.rb
33+
test/dummy/app/models/application_record.rb
34+
test/dummy/app/models/concerns/.keep
35+
test/dummy/app/views/layouts/application.html.erb
36+
test/dummy/app/views/layouts/mailer.html.erb
37+
test/dummy/app/views/layouts/mailer.text.erb
38+
test/dummy/app/views/pwa/manifest.json.erb
39+
test/dummy/app/views/pwa/service-worker.js
40+
test/dummy/bin/rails
41+
test/dummy/bin/rake
42+
test/dummy/bin/setup
43+
test/dummy/config.ru
44+
test/dummy/config/application.rb
45+
test/dummy/config/boot.rb
46+
test/dummy/config/cable.yml
47+
test/dummy/config/database.yml
48+
test/dummy/config/environment.rb
49+
test/dummy/config/environments/development.rb
50+
test/dummy/config/environments/production.rb
51+
test/dummy/config/environments/test.rb
52+
test/dummy/config/initializers/content_security_policy.rb
53+
test/dummy/config/initializers/enable_yjit.rb
54+
test/dummy/config/initializers/filter_parameter_logging.rb
55+
test/dummy/config/initializers/inflections.rb
56+
test/dummy/config/initializers/permissions_policy.rb
57+
test/dummy/config/locales/en.yml
58+
test/dummy/config/puma.rb
59+
test/dummy/config/routes.rb
60+
test/dummy/config/storage.yml
61+
test/dummy/lib/assets/.keep
62+
test/dummy/log/.keep
63+
test/dummy/public/404.html
64+
test/dummy/public/422.html
65+
test/dummy/public/426.html
66+
test/dummy/public/500.html
67+
test/dummy/public/icon.png
68+
test/dummy/public/icon.svg
69+
test/dummy/storage/.keep
70+
test/dummy/tmp/.keep
71+
test/dummy/tmp/pids/.keep
72+
test/dummy/tmp/storage/.keep
2173
test/test_helper.rb
22-
test/dummy
2374
)
2475

2576
class PluginGeneratorTest < Rails::Generators::TestCase
@@ -68,8 +119,6 @@ def test_correct_file_in_lib_folder_of_camelcase_plugin_name
68119
def test_generating_without_options
69120
run_generator
70121
assert_file "README.md", /Bukkits/
71-
assert_no_file "config/routes.rb"
72-
assert_no_file "app/assets/config/bukkits_manifest.js"
73122
assert_file "test/test_helper.rb" do |content|
74123
assert_match(/require_relative.+test\/dummy\/config\/environment/, content)
75124
assert_match(/ActiveRecord::Migrator\.migrations_paths.+test\/dummy\/db\/migrate/, content)
@@ -83,13 +132,6 @@ def test_generating_without_options
83132
assert_match(/class BukkitsTest < ActiveSupport::TestCase/, content)
84133
assert_match(/assert Bukkits::VERSION/, content)
85134
end
86-
assert_file "bin/test"
87-
assert_no_file "bin/rails"
88-
end
89-
90-
def test_initializes_git_repo
91-
run_generator
92-
assert_directory ".git"
93135
end
94136

95137
def test_initializes_git_repo_with_main_branch_without_user_default
@@ -176,12 +218,6 @@ def test_generating_adds_dummy_app_rake_tasks_without_unit_test_files
176218
assert_file "bin/rails", /APP_PATH/
177219
end
178220

179-
def test_generating_adds_dummy_app_without_javascript_and_assets_deps
180-
run_generator
181-
182-
assert_file "test/dummy/app/assets/stylesheets/application.css"
183-
end
184-
185221
def test_ensure_that_plugin_options_are_not_passed_to_app_generator
186222
FileUtils.cd(fixtures_root)
187223
assert_no_match(/It works from file!.*It works_from_file/, run_generator([destination_root, "-m", "lib/template.rb"]))
@@ -608,24 +644,6 @@ def test_ensure_that_gitignore_can_be_generated_from_a_template_for_dummy_path
608644
end
609645
end
610646

611-
def test_unnecessary_files_are_not_generated_in_dummy_application
612-
run_generator
613-
assert_no_file "test/dummy/.gitignore"
614-
assert_no_file "test/dummy/.ruby-version"
615-
assert_no_file "test/dummy/db/seeds.rb"
616-
assert_no_file "test/dummy/Gemfile"
617-
assert_no_file "test/dummy/public/robots.txt"
618-
assert_no_file "test/dummy/README.md"
619-
assert_no_file "test/dummy/config/master.key"
620-
assert_no_file "test/dummy/config/credentials.yml.enc"
621-
assert_no_file "test/dummy/Dockerfile"
622-
assert_no_file "test/dummy/.dockerignore"
623-
assert_no_directory "test/dummy/lib/tasks"
624-
assert_no_directory "test/dummy/test"
625-
assert_no_directory "test/dummy/vendor"
626-
assert_no_directory "test/dummy/.git"
627-
end
628-
629647
def test_skipping_test_files
630648
run_generator [destination_root, "--skip-test"]
631649
assert_no_directory "test"

0 commit comments

Comments
 (0)