Skip to content
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 7 commits into from
Sep 30, 2019
Merged

Remove instance variables in RSpec #3736

merged 7 commits into from
Sep 30, 2019

Conversation

javierm
Copy link
Member

@javierm javierm commented Sep 29, 2019

References

Objectives

  • Make it easier for contributors to follow our coding style
  • Make the code more consistent
  • Apply guidelines developers have agreed upon to existing code

@javierm javierm added the Linters Rubocop, ERB Lint, ESLint, SCSS-Lint, ... label Sep 29, 2019
@javierm javierm self-assigned this Sep 29, 2019
@javierm javierm added this to Reviewing in Roadmap via automation Sep 29, 2019
@javierm javierm force-pushed the rspec_instance_variables branch 2 times, most recently from 176e361 to b55fbf7 Compare September 29, 2019 22:50
@javierm javierm changed the base branch from rubocop_lint to remove_unused_variables September 29, 2019 22:50
@javierm javierm force-pushed the remove_unused_variables branch 4 times, most recently from 02a0d6c to 7783547 Compare September 30, 2019 13:47
@javierm javierm force-pushed the rspec_instance_variables branch 3 times, most recently from 32f13b6 to 4f9f5cf Compare September 30, 2019 14:25
These variables were declared but never used.
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 javierm changed the base branch from remove_unused_variables to master September 30, 2019 14:44
@javierm javierm merged commit 3bb7c9b into master Sep 30, 2019
Roadmap automation moved this from Reviewing to Release 1.1.0 Sep 30, 2019
@javierm javierm deleted the rspec_instance_variables branch September 30, 2019 15:27
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
Labels
Linters Rubocop, ERB Lint, ESLint, SCSS-Lint, ...
Projects
No open projects
Roadmap
  
Release 1.1.0
Development

Successfully merging this pull request may close these issues.

None yet

2 participants