From e961c1c57c41273357833afa573cec78cc36726c Mon Sep 17 00:00:00 2001 From: Stephen Sugden Date: Sun, 8 Jan 2023 14:29:21 +0100 Subject: [PATCH] Start a spec for Pin::DelegatedMethod --- spec/pin/delegated_method_spec.rb | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 spec/pin/delegated_method_spec.rb diff --git a/spec/pin/delegated_method_spec.rb b/spec/pin/delegated_method_spec.rb new file mode 100644 index 000000000..551f63928 --- /dev/null +++ b/spec/pin/delegated_method_spec.rb @@ -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]') + + delegation_pin = Solargraph::Pin::DelegatedMethod.new(method: method_pin, scope: :instance) + expect(delegation_pin.return_type.to_s).to eq('Hash') + 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