Class: Solargraph::Rspec::Correctors::SubjectMethodCorrector

Inherits:
LetMethodsCorrector show all
Defined in:
lib/solargraph/rspec/correctors/subject_method_corrector.rb

Overview

Defines let-like methods in the example group block

Instance Attribute Summary

Attributes inherited from WalkerBase

#namespace_pins, #rspec_walker

Attributes inherited from Base

#namespace_pins

Instance Method Summary collapse

Methods inherited from WalkerBase

#initialize

Methods inherited from Base

#initialize

Constructor Details

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

Instance Method Details

#correct(_source_map) ⇒ void

This method returns an undefined value.

Parameters:

  • source_map (Solargraph::SourceMap)


12
13
14
15
16
17
18
19
20
21
22
# File 'lib/solargraph/rspec/correctors/subject_method_corrector.rb', line 12

def correct(_source_map)
  rspec_walker.on_subject do |subject_name, location_range, fake_method_ast|
    next unless subject_name

    namespace_pin = closest_namespace_pin(namespace_pins, location_range.start.line)
    next unless namespace_pin

    subject_pin = rspec_let_method(namespace_pin, subject_name, location_range, fake_method_ast)
    yield [subject_pin].compact if block_given?
  end
end