-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove instance variables in RSpec #3736
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
houndci-bot
reviewed
Sep 29, 2019
javierm
force-pushed
the
rubocop_lint
branch
from
September 29, 2019 15:41
e30654e
to
78a8edf
Compare
javierm
force-pushed
the
rspec_instance_variables
branch
from
September 29, 2019 15:42
60476fd
to
bac8bf8
Compare
javierm
force-pushed
the
rubocop_lint
branch
from
September 29, 2019 22:44
78a8edf
to
e077d1b
Compare
javierm
force-pushed
the
rspec_instance_variables
branch
2 times, most recently
from
September 29, 2019 22:50
176e361
to
b55fbf7
Compare
javierm
changed the base branch from
rubocop_lint
to
remove_unused_variables
September 29, 2019 22:50
javierm
force-pushed
the
remove_unused_variables
branch
4 times, most recently
from
September 30, 2019 13:47
02a0d6c
to
7783547
Compare
javierm
force-pushed
the
rspec_instance_variables
branch
3 times, most recently
from
September 30, 2019 14:25
32f13b6
to
4f9f5cf
Compare
These variables were declared but never used.
javierm
force-pushed
the
rspec_instance_variables
branch
from
September 30, 2019 14:38
4f9f5cf
to
cec060e
Compare
Instance variables might lead to hard-to-detect issues, since using a nonexistent instance variable will return `nil` instead of raising an error.
We couldn't declare them inside the block because they would be considered local variables and its value would be lost when the block was finished. So we were using instance variables instead. However, with instance variables we don't get any warnings when we misspell their names. We can avoid them by declaring the local variables before the block starts.
Having two questions, each of them with two comments, made the code hard to follow. Grouping the comments inside the block creating the questions makes it easier to know which comment belongs to which question, even if the code is still not 100% readable. We also remove instance variables, which by the way used the same variable name for two different things.
This one is a bit different than our usual scenario, since we create three annotations and we only use two of them in the specs (because we visit the path to that annotation). So there are probably better options than the combination of `let!` and `before` I've chosen.
Note we cannot name this variable `process` because in a controller spec the word `process` is a method, like `get` or `post`.
These files create a fake class using an instance variable. While the proper thing to do would be to refactor the `HasOrders` and `HasFilters` concerns so they didn't use instance variables but methods, I don't think that's going to happen in the near future.
javierm
force-pushed
the
rspec_instance_variables
branch
from
September 30, 2019 14:43
cec060e
to
4de4045
Compare
This was referenced Oct 18, 2019
smarques
pushed a commit
to venetochevogliamo/consul
that referenced
this pull request
Apr 29, 2020
…riables Remove instance variables in RSpec
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
References
Objectives