Class: RuboCop::Cop::RSpec::FactoryBot::StaticAttributeDefinedDynamically
- Inherits:
-
Cop
- Object
- WorkaroundCop
- Cop
- RuboCop::Cop::RSpec::FactoryBot::StaticAttributeDefinedDynamically
- Defined in:
- lib/rubocop/cop/rspec/factory_bot/static_attribute_defined_dynamically.rb
Overview
Prefer declaring static attribute values without a block.
Constant Summary collapse
- MSG =
'Do not use a block to set a static value ' \ 'to an attribute.'.freeze
Constants inherited from Cop
Cop::DEFAULT_CONFIGURATION, Cop::DEFAULT_PATTERN_RE
Constants included from RSpec::Language
Instance Method Summary collapse
Methods inherited from Cop
Instance Method Details
#autocorrect(node) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/rubocop/cop/rspec/factory_bot/static_attribute_defined_dynamically.rb', line 49 def autocorrect(node) lambda do |corrector| corrector.replace( node.loc.expression, autocorrected_source(node) ) end end |
#on_block(node) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/rubocop/cop/rspec/factory_bot/static_attribute_defined_dynamically.rb', line 41 def on_block(node) factory_attributes(node).to_a.flatten.each do |attribute| values = block_value_matcher(attribute) next if values.to_a.none? { |v| static?(v) } add_offense(attribute, location: :expression) end end |