Class: RuboCop::Cop::Thoughtbot::NoLet
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Thoughtbot::NoLet
- Includes:
- SpecGroup
- Defined in:
- lib/rubocop/cop/thoughtbot/no_let.rb
Overview
Checks for let and let! declarations in specs.
Data defined in a let sits away from the examples that use it, so a
reader has to jump around the file to work out what any one example is
actually doing (the let becomes a mystery guest). Setting data up
inside each example keeps the whole story of the test in one place,
avoids messy overrides for differing scenarios, and keeps the cost of
setup visible.
See https://thoughtbot.com/blog/lets-not
See https://thoughtbot.com/blog/the-arrange-act-assert-pattern
Constant Summary collapse
- MSG =
"Avoid `%<method>s` — set up test data inside each example so it " \ "doesn't become a mystery guest. See https://thoughtbot.com/blog/lets-not"
- RESTRICT_ON_SEND =
%i[let let!].freeze
Constants included from SpecGroup
SpecGroup::SCOPES, SpecGroup::SPEC_GROUPS
Instance Method Summary collapse
- #on_send(node) ⇒ Object (also: #on_csend)
Methods included from SpecGroup
#extends_shared_context?, #spec_group?
Instance Method Details
#on_send(node) ⇒ Object Also known as: on_csend
46 47 48 49 50 51 |
# File 'lib/rubocop/cop/thoughtbot/no_let.rb', line 46 def on_send(node) return if node.receiver return unless inside_spec_group?(node) add_offense(node.loc.selector, message: format(MSG, method: node.method_name)) end |