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 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) ⇒ void

This method returns an undefined value.

Parameters:

  • source_map (Solargraph::SourceMap)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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|
    namespace_pin = closest_namespace_pin(namespace_pins, location_range.start.line)
    next unless namespace_pin

    subject_pin = rspec_subject_method(namespace_pin, subject_name, location_range, fake_method_ast)
    add_pin(subject_pin)
    add_pins(one_liner_expectation_pins(subject_pin))
  end

  rspec_walker.after_walk do
    next unless described_class_pin

    namespace_pin = closest_namespace_pin(namespace_pins, described_class_pin.location.range.start.line)

    if namespace_pin
      implicit_subject_pin = implicit_subject_method(described_class_pin, namespace_pin)
      add_pin(implicit_subject_pin)
      add_pins(one_liner_expectation_pins(implicit_subject_pin))
    end
  end
end