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

Checking for necessary require on _spec files #612

Closed
danielnc opened this issue May 14, 2018 · 3 comments
Closed

Checking for necessary require on _spec files #612

danielnc opened this issue May 14, 2018 · 3 comments

Comments

@danielnc
Copy link

We want to add rubocop check for our rails _spec files that will check if the necessary

require "spec_helper" or require "rails_helper" exists on files

This is usually not a problem if you run the entire rails spec suite but could be if one file does not have the specific require and you run that individually

How can I accomplish that?

Is this a new feature or rubocop-rspec already supports this? I couldn't find any information

@dgollahon
Copy link
Contributor

Hi @danielnc. There's no cop that I know of that would enforce that, but you might consider adding rspec configuration to your project so that you don't have to. If you add a .rspec file, rspec will look for this before every test run and use the arguments you specify.

Sample .rspec contents that would always require your spec_helper.rb

--require spec_helper

@dgollahon
Copy link
Contributor

Does the rspec configuration suggestion work for you, @danielnc?

I'm closing this for the moment as I'm currently not in favor of having a cop for something like this, but if you don't think rspec configuration is a good solution / have further arguments for why this would be good, feel free to re-open this issue.

@olliebennett
Copy link

I came looking for this too; thanks for the (much better) solution of configuring it via the .rspec file.

On the back of this, I had some thoughts;

  • I wonder if it's equally useful to have a cop to identify redundant require statements in cops (when the .rspec file already requires the file globally). Perhaps there is a valid use case to have the same require defined in the file itself too - I can't think of one.
  • If (as hinted in @danielnc's original question) he wanted to explicitly require either rspec_helper or spec_helper (depending on the context of the spec file), that could be a different problem for which a cop could be useful. Just speculation; it's not something I'm doing at the moment, anyway.

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

No branches or pull requests

3 participants