Class: PinkSpoon::ConstantResolver::DescribedClassFinder

Inherits:
Prism::Visitor
  • Object
show all
Defined in:
lib/pink_spoon/constant_resolver.rb

Overview

Finds the class constant passed as the first argument to the outermost describe(MyClass) or RSpec.describe(MyClass) call in the file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



496
497
498
# File 'lib/pink_spoon/constant_resolver.rb', line 496

def result
  @result
end

Instance Method Details

#visit_call_node(node) ⇒ Object



498
499
500
501
502
503
504
505
506
507
# File 'lib/pink_spoon/constant_resolver.rb', line 498

def visit_call_node(node)
  if node.name == :describe && @result.nil?
    first = node.arguments&.arguments&.first
    @result = case first
              when Prism::ConstantReadNode then first.name.to_s
              when Prism::ConstantPathNode then first.slice.delete_prefix("::")
              end
  end
  super
end