Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions spec/shell_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# frozen_string_literal: true

require 'tmpdir'
require 'open3'

describe Solargraph::Shell do
let(:shell) { described_class.new }

describe 'rbs' do
let(:api_map) { instance_double(Solargraph::ApiMap) }

before do
allow(shell).to receive(:`)
allow(Solargraph::ApiMap).to receive(:load).and_return(api_map)
allow(api_map).to receive(:source_maps).and_return(source_maps)
end

context 'without inference' do
let(:source_maps) { [] }

it 'invokes sord' do
capture_both do
shell.options = { filename: 'foo.rbs' }
shell.rbs
end
expect(shell)
.to have_received(:`)
.with("sord #{Dir.pwd}/sig/foo.rbs --rbs --no-regenerate")
end
end

context 'with inference' do
let(:source_maps) { [source_map] }
let(:source_map) { instance_double(Solargraph::SourceMap) }
let(:pin) do
instance_double(Solargraph::Pin::Method,
namespace: 'My::Namespace', path: 'My::Namespace#foo',
visibility: :public,
parameters: [],
scope: :instance,
location: nil,
name: 'foo',
class: Solargraph::Pin::Method,
return_type: Solargraph::ComplexType::UNDEFINED)
end

it 'infers unknown types on pins' do
allow(source_map).to receive(:pins).and_return([pin])
allow(pin).to receive_messages(typify: Solargraph::ComplexType.parse('String'),
docstring: YARD::Docstring.new(''))
allow(pin).to receive(:code_object).and_return(nil)
capture_both do
shell.options = { filename: 'foo.rbs', inference: true }
shell.rbs
end
expect(pin).to have_received(:typify)
end
end
end
end
26 changes: 26 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,29 @@ def with_env_var(name, value)
ENV[name] = old_value # Restore the old value
end
end

def capture_stdout &block
original_stdout = $stdout
$stdout = StringIO.new
begin
block.call
$stdout.string
ensure
$stdout = original_stdout
end
end

def capture_both &block
original_stdout = $stdout
original_stderr = $stderr
stringio = StringIO.new
$stdout = stringio
$stderr = stringio
begin
block.call
ensure
$stdout = original_stdout
$stderr = original_stderr
end
stringio.string
end