Class: RuboCop::Cop::Thoughtbot::NoLet
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Thoughtbot::NoLet
- 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
Instance Method Summary collapse
- #on_send(node) ⇒ Object (also: #on_csend)
Instance Method Details
#on_send(node) ⇒ Object Also known as: on_csend
40 41 42 43 44 |
# File 'lib/rubocop/cop/thoughtbot/no_let.rb', line 40 def on_send(node) return if node.receiver add_offense(node.loc.selector, message: format(MSG, method: node.method_name)) end |