diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 26a8bac3b9b90..840e267256dd5 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,9 @@ +* Exit `rails g` with code 1 if generator could not be found. + + Previously `rails g` returned 0, which would make it harder to catch typos in scripts calling `rails g`. + + *Christopher Ă–zbek* + * Remove `require_*` statements from application.css to align with the transition from Sprockets to Propshaft. With Propshaft as the default asset pipeline in Rails 8, the require_tree and require_self clauses in application.css are no longer necessary, as they were specific to Sprockets. Additionally, the comment has been updated to clarify that CSS precedence now follows standard cascading order without automatic prioritization by the asset pipeline. diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 123aed7b1314a..aab87870c418a 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -272,6 +272,7 @@ def invoke(namespace, args = ARGV, config = {}) #{error.detailed_message} Run `bin/rails generate --help` for more options. MSG + exit 1 end end diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index a9fdd7116e703..0c59c8eaa9e8a 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -25,7 +25,11 @@ def test_simple_invoke def test_invoke_when_generator_is_not_found name = :unknown - output = capture(:stdout) { Rails::Generators.invoke name } + output = capture(:stdout) { + assert_raises SystemExit do + Rails::Generators.invoke name + end + } assert_match "Could not find generator '#{name}'.", output assert_match "`bin/rails generate --help`", output assert_no_match "Did you mean", output @@ -33,7 +37,11 @@ def test_invoke_when_generator_is_not_found def test_generator_suggestions name = :migrationz - output = capture(:stdout) { Rails::Generators.invoke name } + output = capture(:stdout) { + assert_raises SystemExit do + Rails::Generators.invoke name + end + } assert_match "Did you mean? migration", output end @@ -43,7 +51,11 @@ def test_generator_suggestions_except_en_locale I18n.available_locales = :ja I18n.default_locale = :ja name = :tas - output = capture(:stdout) { Rails::Generators.invoke name } + output = capture(:stdout) { + assert_raises SystemExit do + Rails::Generators.invoke name + end + } assert_match "Did you mean? task", output ensure I18n.available_locales = orig_available_locales