Can I whitelist a RuboCop Rails/DynamicFindBy method on a per-file basis

Viewed 872

RuboCop's Rails/DynamicFindBy cop gives false positives when it encounters Capybara's (as opposed to Rail's) find_by_id method.
There's apparently a way to whitelist methods so that they are ignored by this cop. See http://rubocop.readthedocs.io/en/latest/cops_rails/#railsdynamicfindby (mentioning Whitelist attribute).

I would like to whitelist find_by_id, but only for certain files (the ones with Capybara tests) in my tests/integration directory. Is this possible?

(I am aware that I can turn off the entire cop on a file by file basis, but I don't want to turn off the cop entirely. I am also aware that I can turn off the cop for portions of a file, or on a line-by-line basis, but those are not preferred solutions.)

4 Answers

You can exclude specs in rubocop.yml:

Rails/DynamicFindBy:
  Exclude:
    - "spec/system/**/*"
Related