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

Cop idea: Disallowed list of spec conditions #1724

Open
gaffneyc opened this issue Sep 20, 2023 · 3 comments
Open

Cop idea: Disallowed list of spec conditions #1724

gaffneyc opened this issue Sep 20, 2023 · 3 comments
Labels

Comments

@gaffneyc
Copy link

We have some rspec hooks which we use for debugging and don't want committed. It would be useful to have a cop which checks for those options (conditions? filters? I'm not sure on the naming). This is similar to the RSpec/Focus cop but more general and allows for a list of options.

For our use case we would only need to disallow option names without checking values (e.g. :headless, headless: true, and headless: false would all be violations).

Describe the solution you'd like

RSpec.configure do |config|
  # Allow a test to be run in the foreground for debugging
  config.before(:each, type: :system, headless: false) do
    driven_by :selenium_chrome
  end
end

RSpec.describe "foo" do
  # bad: headless not allowed
  it "does a thing", headless: false do
  end
end
@pirj
Copy link
Member

pirj commented Sep 26, 2023

It would fail on CI anyway, won’t it?

@gaffneyc
Copy link
Author

In the case of headless it may or it may not but either way it is something we don't want to commit and would ideally be caught in linting.

Another example that wouldn't fail on CI but we still don't want to commit would be :debug which enables debug logging for a specific spec we're investigating.

@pirj
Copy link
Member

pirj commented Sep 27, 2023

Should be easy to implement. Parts could be borrowed/extracted from the Focus cop,

def_node_matcher :metadata, <<-PATTERN

A PR is welcome.

@ydah ydah added the cop label Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants