Class: Solargraph::Rspec::SpecWalker::RspecContextNamespace

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

Class Method Summary collapse

Class Method Details

.from_block_ast(block_ast) ⇒ String?

Parameters:

  • block_ast (RubyVM::AbstractSyntaxTree::Node)

Returns:

  • (String, nil)


10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/solargraph/rspec/spec_walker/rspec_context_namespace.rb', line 10

def from_block_ast(block_ast)
  return unless block_ast.is_a?(RubyVM::AbstractSyntaxTree::Node)

  ast = NodeTypes.context_description_node(block_ast)
  if ast.type == :STR
    string_to_const_name(ast)
  elsif NodeTypes.a_constant?(ast)
    FullConstantName.from_ast(ast).gsub('::', '')
  else
    Solargraph.logger.warn "[RSpec] Unexpected AST type #{ast.type}"
    nil
  end
end