-
-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathdelegated_method_spec.rb
40 lines (32 loc) · 1.08 KB
/
delegated_method_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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