Class: RuboCop::Cop::RSpec::ReturnFromStub
- Includes:
- ConfigurableEnforcedStyle
- Defined in:
- lib/rubocop/cop/rspec/return_from_stub.rb
Overview
Checks for consistent style of stub’s return setting.
Enforces either ‘and_return` or block-style return in the cases where the returned value is constant. Ignores dynamic returned values are the result would be different
This cop can be configured using the ‘EnforcedStyle` option
Defined Under Namespace
Classes: AndReturnCallCorrector, BlockBodyCorrector
Constant Summary collapse
- MSG_AND_RETURN =
'Use `and_return` for static values.'
- MSG_BLOCK =
'Use block for static values.'
Constants inherited from Cop
Cop::DEFAULT_CONFIGURATION, Cop::DEFAULT_PATTERN_RE
Constants included from RSpec::Language
RSpec::Language::ALL, RSpec::Language::RSPEC
Instance Method Summary collapse
Methods inherited from Cop
Instance Method Details
#autocorrect(node) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/rubocop/cop/rspec/return_from_stub.rb', line 61 def autocorrect(node) if style == :block AndReturnCallCorrector.new(node) else BlockBodyCorrector.new(node) end end |
#on_block(node) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/rubocop/cop/rspec/return_from_stub.rb', line 54 def on_block(node) return unless contains_stub?(node) return unless style == :and_return check_block_body(node) end |
#on_send(node) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/rubocop/cop/rspec/return_from_stub.rb', line 47 def on_send(node) return unless contains_stub?(node) return unless style == :block check_and_return_call(node) end |