Skip to content

Use a more minimal require pattern for linter specs#9756

Merged
jmhooper merged 1 commit intomainfrom
jmhooper-clean-up-rubocop-spec-requires
Dec 13, 2023
Merged

Use a more minimal require pattern for linter specs#9756
jmhooper merged 1 commit intomainfrom
jmhooper-clean-up-rubocop-spec-requires

Conversation

@jmhooper
Copy link
Contributor

The rubocop linter specs were requiring the rubocop/rspec/support. This file is defined in the Rubocop gem and adds utilities for testing rubocop linters.

The rubocop support configuration appears to make the assumption that the context in which it is included is a test suite for only testing Cops or at least for primarily testing Cops. The main clue for this is this part of the implementation:

RSpec.configure do |config|
  config.include CopHelper
  # ...
end

The CopHelper module defines a number of methods for testing a linter. The support file includes that module for every single example. As a result all of our tests have those methods.

I found this problematic when I observed an issue testing a MFA selection presenter. It referenced a configuration variable that it expected to be an MFA configuration. This variable was in fact a rubocop configuration thanks to the configuration method in the CopHelper module (ref: the failed build where I observed this)

This commit removes the require call that included rubocop/rspec/support. It replaces that with a simplified set of require calls that only bring in the tools we need to test our linters.

The rubocop linter specs were requiring the `rubocop/rspec/support`. This file is [defined in the Rubocop gem](https://github.com/rubocop/rubocop/blob/master/lib/rubocop/rspec/support.rb) and adds utilities for testing rubocop linters.

The rubocop support configuration _appears_ to make the assumption that the context in which it is included is a test suite for only testing Cops or at least for primarily testing Cops. The main clue for this is this part of the implementation:

```ruby
RSpec.configure do |config|
  config.include CopHelper
  # ...
end
```

The [`CopHelper` module](https://github.com/rubocop/rubocop/blob/master/lib/rubocop/rspec/cop_helper.rb) defines a number of methods for testing a linter. The support file includes that module for _every single example_. As a result all of our tests have those methods.

I found this problematic when I observed an issue testing a MFA selection presenter. It referenced a `configuration` variable that it expected to be an MFA configuration. This variable was in fact a rubocop configuration thanks to the `configuration` method in the `CopHelper` module (ref: [the failed build where I observed this](https://gitlab.login.gov/lg/identity-idp/-/jobs/915207))

This commit removes the `require` call that included `rubocop/rspec/support`. It replaces that with a simplified set of `require` calls that only bring in the tools we need to test our linters.

[skip changelog]
@jmhooper jmhooper changed the title Use a more minimal rubocop linter require pattern for linter specs Use a more minimal require pattern for linter specs Dec 13, 2023
@jmhooper jmhooper merged commit eb1b2f9 into main Dec 13, 2023
@jmhooper jmhooper deleted the jmhooper-clean-up-rubocop-spec-requires branch December 13, 2023 21:49
@aduth
Copy link
Contributor

aduth commented Dec 14, 2023

🤔 Interesting discovery!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants