Skip to content

Commit

Permalink
Start a spec for Pin::DelegatedMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
grncdr committed Jan 8, 2023
1 parent 3a1d810 commit e961c1c
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions spec/pin/delegated_method_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require 'pry'

describe Solargraph::Pin::DelegatedMethod do
it 'can be constructed from a Method pin' do
method_pin = Solargraph::Pin::Method.new(comments: '@return [Hash<String, String>]')

delegation_pin = Solargraph::Pin::DelegatedMethod.new(method: method_pin, scope: :instance)
expect(delegation_pin.return_type.to_s).to eq('Hash<String, String>')
end

it 'can be constructed from a receiver source and method name' do
api_map = Solargraph::ApiMap.new
source = Solargraph::Source.load_string(%(
class Class1
# @return [String]
def name; end
end
class Class2
# @return [Class1]
def collaborator; end
end
))
api_map.map source

class2 = api_map.get_path_pins('Class2').first

chain = Solargraph::Source::Chain.new([Solargraph::Source::Chain::Call.new('collaborator')])
pin = Solargraph::Pin::DelegatedMethod.new(
closure: class2,
scope: :instance,
name: 'name',
receiver: chain
)

pin.probe(api_map)

expect(pin.return_type.to_s).to eq('String')
end
end

0 comments on commit e961c1c

Please sign in to comment.