Remove instance variables in generated specs #2599
Merged
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.
Problem
I noticed some generated scaffold specs contain explicit instance variable gets and sets. But rubocop-rspec gem, at least v2.10.0, prefers no instance variable usages in specs by default (RSpec/InstanceVariable cop, introduced in 2014 rubocop/rubocop-rspec#3).
In fact, I confirmed that some specs such as
spec/views/posts/edit.html.erb_spec.rb
generated bybin/rails g scaffold post
are offended by rubocop.What I Changed
Therefore, I removed usage of instance variables from generated specs.
For historians, commits in 2010 (f06aa50 and 0d244a1) introduce the use of instance variables, maybe without strong reasons.
Changes to Specs
The following table is a summary of changes to generated
edit_spec.rb
. I generated these results on my local environment with Rails 7.0.2.4 and rspec-{core,expectations,mocks,support} 3.12.0.pre. Specs in "After" column do not contain@post
.