Skip to content

Commit 107fd51

Browse files
authored
Merge pull request rails#51446 from koic/fix_error_when_rails_g_rubocop_with_pretend
Fix an error for `apply_rubocop_autocorrect_after_generate!` with `--pretend`
2 parents 3e15614 + 33c63f0 commit 107fd51

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

railties/lib/rails/configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def after_generate(&block)
133133

134134
def apply_rubocop_autocorrect_after_generate!
135135
after_generate do |files|
136-
parsable_files = files.filter { |file| file.end_with?(".rb") }
136+
parsable_files = files.filter { |file| File.exist?(file) && file.end_with?(".rb") }
137137
unless parsable_files.empty?
138138
system("bin/rubocop -A --fail-level=E #{parsable_files.shelljoin}", exception: true)
139139
end

railties/test/application/generators_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,16 @@ def check_expected
265265
output = rails("generate", "model", "post", "title:string", "body:string")
266266
assert_match(/3 files inspected, no offenses detected/, output)
267267
end
268+
269+
test "generators with apply_rubocop_autocorrect_after_generate! and pretend" do
270+
with_config do |c|
271+
c.generators.apply_rubocop_autocorrect_after_generate!
272+
end
273+
274+
assert_nothing_raised do
275+
rails("generate", "model", "post", "title:string", "body:string", "--pretend")
276+
end
277+
end
268278
end
269279
end
270280
end

0 commit comments

Comments
 (0)