Class: RuboCop::Cop::RSpec::ChewyStrategy

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/rspec/chewy_strategy.rb

Overview

Prevent to change the Chewy strategy in tests. Setting the strategy to atomic may try to import unnecessary data for the test which result to a slower test suite.

Examples:

# bad
let(:user) { Chewy.strategy(:atomic) { create(:user) } }

# good
let(:user) { create(:user) }
before { UserIndex.import! user }

Constant Summary collapse

MSG =
'Do not use Chewy.strategy in tests. Import data explicitly instead.'
RESTRICT_ON_SEND =
i[strategy].freeze

Instance Method Summary collapse

Instance Method Details

#chewy_strategy?(node) ⇒ Object



23
24
25
# File 'lib/rubocop/cop/rspec/chewy_strategy.rb', line 23

def_node_matcher :chewy_strategy?, "(send (const nil? :Chewy) :strategy ...)\n"

#on_send(node) ⇒ Object Also known as: on_csend



27
28
29
30
31
# File 'lib/rubocop/cop/rspec/chewy_strategy.rb', line 27

def on_send(node)
  return unless chewy_strategy?(node)

  add_offense(node)
end