|
| 1 | +require 'tmpdir' |
| 2 | +require 'open3' |
| 3 | + |
| 4 | +describe Solargraph::Shell do |
| 5 | + before do |
| 6 | + @temp_dir = Dir.mktmpdir |
| 7 | + File.open(File.join(@temp_dir, 'Gemfile'), 'w') do |file| |
| 8 | + file.puts "source 'https://rubygems.org'" |
| 9 | + file.puts "gem 'solargraph', path: #{File.expand_path('../..', __FILE__)}" |
| 10 | + end |
| 11 | + output, status = Open3.capture2e("bundle install", chdir: @temp_dir) |
| 12 | + expect(status.success?).to eq(true), ->{ "Bundle install failed: output=#{output}" } |
| 13 | + end |
| 14 | + |
| 15 | + def bundle_exec(*cmd) |
| 16 | + # run the command in the temporary directory with bundle exec |
| 17 | + output, status = Open3.capture2e("bundle exec #{cmd.join(' ')}", chdir: @temp_dir) |
| 18 | + expect(status.success?).to eq(true), "Command failed: #{output}" |
| 19 | + output |
| 20 | + end |
| 21 | + |
| 22 | + after do |
| 23 | + # remove the temporary directory after the tests |
| 24 | + FileUtils.remove_entry(@temp_dir) if Dir.exist?(@temp_dir) |
| 25 | + end |
| 26 | + |
| 27 | + describe "--version" do |
| 28 | + it "returns a version when run" do |
| 29 | + output = bundle_exec("solargraph", "--version") |
| 30 | + |
| 31 | + expect(output).to_not be_empty |
| 32 | + expect(output).to eq (Solargraph::VERSION + "\n") |
| 33 | + end |
| 34 | + end |
| 35 | + |
| 36 | + describe "uncache" do |
| 37 | + it "uncaches without erroring out" do |
| 38 | + output = bundle_exec("solargraph", "uncache", "solargraph") |
| 39 | + |
| 40 | + expect(output).to include('Clearing pin cache in') |
| 41 | + end |
| 42 | + end |
| 43 | +end |
0 commit comments