Class: Solargraph::Rspec::SpecConfigurationWalker

Inherits:
Object
  • Object
show all
Defined in:
lib/solargraph/rspec/spec_configuration_walker.rb

Overview

Walks AST to find RSpec.configure blocks and extract included modules

Defined Under Namespace

Classes: IncludedModule

Instance Method Summary collapse

Constructor Details

#initialize(ast, filename) ⇒ SpecConfigurationWalker

Returns a new instance of SpecConfigurationWalker.

Parameters:

  • ast (::Parser::AST::Node)
  • filename (String)

    The file being parsed



12
13
14
15
16
17
# File 'lib/solargraph/rspec/spec_configuration_walker.rb', line 12

def initialize(ast, filename)
  @ast = ast
  @filename = filename
  @walker = Walker.new(ast)
  @included_modules = []
end

Instance Method Details

#extract_included_modulesArray<IncludedModule>

Walk the AST and extract included modules

Returns:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/solargraph/rspec/spec_configuration_walker.rb', line 28

def extract_included_modules
  @walker.on :block, [:send] do |node|
    send_node = node.children[0]
    send_receiver = send_node.children[0]

    # Check if this is RSpec.configure
    next unless send_receiver&.type == :const
    next unless send_receiver.children[1] == :RSpec
    next unless send_node.children[1] == :configure

    # Ensure block has arguments (the config parameter)
    next if node.children[1].children.empty?

    process_configure_block(node)
  end

  @walker.walk
  @included_modules
end