Class: RuboCop::Cop::RSpec::ReturnFromStub::BlockBodyCorrector

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/cop/rspec/return_from_stub.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(block) ⇒ BlockBodyCorrector

Returns a new instance of BlockBodyCorrector.



140
141
142
143
144
# File 'lib/rubocop/cop/rspec/return_from_stub.rb', line 140

def initialize(block)
  @block = block
  @node = block.parent
  @body = block.body || NULL_BLOCK_BODY
end

Instance Method Details

#call(corrector) ⇒ Object



146
147
148
149
150
151
152
153
154
# File 'lib/rubocop/cop/rspec/return_from_stub.rb', line 146

def call(corrector)
  # Heredoc autocorrection is not yet implemented.
  return if heredoc?

  corrector.replace(
    block,
    "#{block.send_node.source}.and_return(#{body.source})"
  )
end