Class: RuboCop::Cop::RSpec::FactoryBot::FactoryClassName
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb
Overview
Use string value when setting the class attribute explicitly.
This cop would promote faster tests by lazy-loading of application files. Also, this could help you suppress potential bugs in combination with external libraries by avoiding a preload of application files from the factory files.
Constant Summary collapse
- MSG =
"Pass '%<class_name>s' string instead of `%<class_name>s` " \ 'constant.'
- ALLOWED_CONSTANTS =
%w[Hash OpenStruct].freeze
Instance Method Summary collapse
Methods inherited from Base
inherited, #on_new_investigation
Methods included from RSpec::Language::NodePattern
Instance Method Details
#on_send(node) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb', line 33 def on_send(node) class_name(node) do |cn| next if allowed?(cn.const_name) msg = format(MSG, class_name: cn.const_name) add_offense(cn, message: msg) do |corrector| corrector.replace(cn, "'#{cn.source}'") end end end |