Class: RuboCop::Cop::RSpec::CreateListMax
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::RSpec::CreateListMax
- Defined in:
- lib/rubocop/cop/rspec/create_list_max.rb
Overview
Prevent creating to most records with ‘FactoryBot.create_list`. Creating to much records can significantly increase spec time.
Constant Summary collapse
- MSG =
'Creating more than `%<max_config>s` records is discouraged.'
- DEFAULT_MAX =
5
- RESTRICT_ON_SEND =
[:create_list].freeze
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/rubocop/cop/rspec/create_list_max.rb', line 30 def on_send(node) amount = create_list(node).to_a.first return unless amount max_config = cop_config['Max'] || DEFAULT_MAX add_offense(node, message: format(MSG, max_config: max_config)) if amount > max_config end |