rubocop-rspec icon indicating copy to clipboard operation
rubocop-rspec copied to clipboard

RSpec/HookArgument: Adding an EnforcedStyle of :all & accept both :each and :all as EnforcedStyle?

Open nc-nystromb opened this issue 6 years ago • 4 comments

I am working in a huge codebase that has a pattern of using before...do syntax and it resulted in really slow test runs because a lot of setup is happening before each test.

I would like to propose to add an all option and also the possibility accept both each and all as an enforced style. Basically, I want to enforce not using before...do in favor of either each or all. I really just want developers in our codebase to be explicit about their before/after hooks.

What do you all think about this idea? Does this make sense to make a PR on the RSpec/HookArgument cop or should I make something custom just for my project? I'm not sure if this would be useful for others.

Thanks for your consideration

nc-nystromb avatar Apr 03 '19 16:04 nc-nystromb

:example/:context are two that are recommended. There is no strong recommendation not to use :example as a hook scope.

Are you up to update the cop to provide this flexibility?

pirj avatar May 09 '19 21:05 pirj

I think I can try making a pull request. Just so the requirements are clear, would the flexibility would be to add an explicit option to the EnforcedStyle, so that you won't be able to just write before do without an argument? There appears to already be an implicit, each, and example as options.

nystromb avatar May 17 '19 20:05 nystromb

This sounds right.

pirj avatar May 18 '19 12:05 pirj

Generally, if you configure with enforced style :each (or :example for that matter), you won't be able to leave before without specifying the scope. It will still allow before(:all). So the only thing an explicit option will do is to allow either example or each to be used.

Darhazer avatar May 20 '19 08:05 Darhazer