Merge pull request #51446 from koic/fix_error_when_rails_g_rubocop_with_pretend

Fix an error for `apply_rubocop_autocorrect_after_generate!` with `--pretend`
This commit is contained in:
Ryuta Kamizono 2024-04-24 15:28:41 +09:00 committed by GitHub
commit 107fd51a22
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -133,7 +133,7 @@ module Rails
def apply_rubocop_autocorrect_after_generate!
after_generate do |files|
parsable_files = files.filter { |file| file.end_with?(".rb") }
parsable_files = files.filter { |file| File.exist?(file) && file.end_with?(".rb") }
unless parsable_files.empty?
system("bin/rubocop -A --fail-level=E #{parsable_files.shelljoin}", exception: true)
end

View File

@ -265,6 +265,16 @@ module ApplicationTests
output = rails("generate", "model", "post", "title:string", "body:string")
assert_match(/3 files inspected, no offenses detected/, output)
end
test "generators with apply_rubocop_autocorrect_after_generate! and pretend" do
with_config do |c|
c.generators.apply_rubocop_autocorrect_after_generate!
end
assert_nothing_raised do
rails("generate", "model", "post", "title:string", "body:string", "--pretend")
end
end
end
end
end