From 8acac38be1052cb264fb4a3fae44796efb3a15c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Glauco=20Cust=C3=B3dio?= Date: Fri, 5 Apr 2024 19:27:55 +0100 Subject: [PATCH] document/suggest workaround to avoid crash when running rails generators --- lib/generators/rspec/install/templates/spec/rails_helper.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/generators/rspec/install/templates/spec/rails_helper.rb b/lib/generators/rspec/install/templates/spec/rails_helper.rb index 166d47d5d..15ef42609 100644 --- a/lib/generators/rspec/install/templates/spec/rails_helper.rb +++ b/lib/generators/rspec/install/templates/spec/rails_helper.rb @@ -4,6 +4,11 @@ require_relative '../config/environment' # Prevent database truncation if the environment is production abort("The Rails environment is running in production mode!") if Rails.env.production? +<% if RSpec::Rails::FeatureCheck.has_active_record_migration? -%> +# Uncomment the line below in case you have `--require rails_helper` in the `.rspec` file +# that will avoid rails generators crashing because migrations haven't been run yet +# return unless Rails.env.test? +<% end -%> require 'rspec/rails' # Add additional requires below this line. Rails is not loaded until this point!