rubocop-rspec
rubocop-rspec copied to clipboard
How to extend `RSpec/FactoryBot/CreateList` ?
FactoryBot actually has a few more list methods than just create_list:
3.0.2 :006 > pp FactoryBot::Syntax::Methods.instance_methods.sort
[:attributes_for,
:attributes_for_list,
:attributes_for_pair,
:build,
:build_list,
:build_pair,
:build_stubbed,
:build_stubbed_list,
:build_stubbed_pair,
:create,
:create_list,
:create_pair,
:generate,
:generate_list,
:null,
:null_list,
:null_pair]
I would like to add these, but then the cop name CreateList does not fit any more. Maybe MultipleInstances would be more fitting.
Can I do that? How do I inform RuboCop about a renamed cop?
If you consider a pair to be a list of two records, it's not necessary to rename the cop.
How do I inform RuboCop about a renamed cop?
Example: https://github.com/rubocop/rubocop/blob/master/config/obsoletion.yml
The enforced style is create_list. Unless you plan to also extend the cop to suggest/correct to _pair, this can be left intact, too.
In any case - a PR is welcome!
@pirj Thanks. PR to follow.
The CreateList checks for n.times { } usage. build_list was ignored on purpose, as nobody would really do n.times { build(...) } since this code has no side effect. Same got for attributes_for and build_stubbed. So if you are to extend the cop for other constructs, I guess it should be extended also for other patterns (like methods being used inside .each / .map block)
Ping