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.



522
523
524
# File 'lib/pink_spoon/constant_resolver.rb', line 522

def result
  @result
end

Instance Method Details

#visit_call_node(node) ⇒ Object



524
525
526
527
528
529
530
531
532
533
# File 'lib/pink_spoon/constant_resolver.rb', line 524

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