Class: RuboCop::Cop::Vicenzo::RSpec::ConditionalInSpec
- Inherits:
-
RSpec::Base
- Object
- RSpec::Base
- RuboCop::Cop::Vicenzo::RSpec::ConditionalInSpec
- Defined in:
- lib/rubocop/cop/vicenzo/rspec/conditional_in_spec.rb
Overview
Do not use conditional logic in spec files.
Any if, unless, or ternary expression in a spec represents a hidden
context. Each branch should be an explicit context block so that the
conditions and expectations are always clear and unconditional.
Constant Summary collapse
- MSG =
'Do not use conditional logic in specs. ' \ 'Extract each branch into an explicit context instead.'
Instance Method Summary collapse
-
#on_if(node) ⇒ Object
Both
ifandunlessare represented asifnodes in the AST, so this single hook covers all conditional forms:if,unless, modifierif/unless, and ternary?:.
Instance Method Details
#on_if(node) ⇒ Object
Both if and unless are represented as if nodes in the AST,
so this single hook covers all conditional forms: if, unless,
modifier if/unless, and ternary ?:.
64 65 66 67 |
# File 'lib/rubocop/cop/vicenzo/rspec/conditional_in_spec.rb', line 64 def on_if(node) offense_location = node.ternary? ? node : node.loc.keyword add_offense(offense_location) end |