Class: Rubocop::Cop::RSpec::FactoryBot::ExcessiveCreateList
- Inherits:
-
Base
- Object
- RuboCop::Cop::RSpec::Base
- Base
- Rubocop::Cop::RSpec::FactoryBot::ExcessiveCreateList
- Defined in:
- lib/rubocop/cop/rspec/factory_bot/excessive_create_list.rb
Overview
Check for create_list FactoryBot declarations higher than configured MaxAmount.
Constant Summary collapse
- MESSAGE =
'Avoid using `create_list` with more than %{max_amount} items.'- RESTRICT_ON_SEND =
i[create_list].freeze
Instance Method Summary collapse
Instance Method Details
#create_list?(node) ⇒ Object
33 34 35 |
# File 'lib/rubocop/cop/rspec/factory_bot/excessive_create_list.rb', line 33 def_node_matcher :create_list?, "(send nil? :create_list (sym ...) $(int _) ...)\n" |
#on_send(node) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/rubocop/cop/rspec/factory_bot/excessive_create_list.rb', line 39 def on_send(node) number_node = create_list?(node) return unless number_node max_amount = cop_config['MaxAmount'] return if number_node.value <= max_amount add_offense(number_node, message: format(MESSAGE, max_amount: max_amount)) end |