Class: Solargraph::Rspec::Correctors::ContextBlockMethodsCorrector

Inherits:
Base
  • Object
show all
Defined in:
lib/solargraph/rspec/correctors/context_block_methods_corrector.rb

Overview

A corrector that corrects pure ruby method blocks namespace defined inside describe/context blocks.

Instance Attribute Summary

Attributes inherited from Base

#added_pins, #namespace_pins, #rspec_walker

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Solargraph::Rspec::Correctors::Base

Instance Method Details

#correct(source_map) ⇒ Object

Parameters:

  • source_map (Solargraph::SourceMap)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/solargraph/rspec/correctors/context_block_methods_corrector.rb', line 11

def correct(source_map)
  rspec_walker.after_walk do
    source_map.pins.each_with_index do |pin, index|
      next unless pin.is_a?(Solargraph::Pin::Method)

      namespace_pin = closest_namespace_pin(namespace_pins, pin.location.range.start.line)
      next unless namespace_pin

      source_map.pins[index] = Solargraph::Pin::Method.new(
        visibility: pin.visibility,
        parameters: pin.parameters,
        closure: namespace_pin,
        node: pin.node,
        signatures: pin.signatures,
        location: pin.location,
        name: pin.name,
        scope: pin.scope,
        comments: pin.comments
      )
    end
  end
end