Prevent unrelated exceptions by requiring rails_helper
at .rspec
#2579
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When there is a bug in the code on the load,
RSpec catches the exception, aborts the spec file,
proceeds to the following spec file, and retries
require
with partially loaded Rails application.
In some cases, we see many identical errors,
such as
NameError
, which are noisy but help developersfind the bug. In other cases, we see many unrelated errors,
typically
FrozenError
on finalized objects,which push out the original exception raised only from the first spec.
The following comment describes this issue in detail.
thoughtbot/factory_bot_rails#303 (comment)
This patch prevents unrelated exceptions by the following rspec-core feature.
The reason why I edited the
.rspec
is that this feature is only applicable to--require
option.rspec/rspec-core#2568
This issue is a relatively well-known issue, and the well-known
workaround is to use
--fail-fast
when we see many errors.https://stackoverflow.com/questions/47320772/rails-runtimeerror-cant-modify-frozen-array-when-running-rspec-in-rails
By introducing this patch, we no longer need the workaround.
All we need to do is run
bundle exec rspec
as usual.