Class: RuboCop::Cop::RSpec::ReturnFromStub
- Extended by:
- AutoCorrector
- 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.'
Instance Method Summary collapse
Methods inherited from Base
inherited, #on_new_investigation
Methods included from RSpec::Language::NodePattern
Instance Method Details
#on_block(node) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/rubocop/cop/rspec/return_from_stub.rb', line 56 def on_block(node) return unless style == :and_return return unless stub_with_block?(node) check_block_body(node) end |
#on_send(node) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/rubocop/cop/rspec/return_from_stub.rb', line 49 def on_send(node) return unless style == :block return unless contains_stub?(node) check_and_return_call(node) end |