connorshea / vscode-ruby-test-adapter

A Ruby test adapter extension for the VS Code Test Explorer
https://marketplace.visualstudio.com/items?itemName=connorshea.vscode-ruby-test-adapter
MIT License
85 stars 52 forks source link

Extension using wrong Ruby executable/in wrong environment #119

Open RyanVerhey opened 1 year ago

RyanVerhey commented 1 year ago

Your environment

Expected behavior

Extension would use appropriate ruby executable

Actual behavior

I am using asdf as a version manager for Ruby. In my Rails directory, I have both a .ruby-version and a .tool-versions file. which ruby in my terminal outputs /Users/[redacted]/.asdf/shims/ruby. However, when the extension loads, it uses the system Ruby:

[2023-03-22 20:27:03.602] [INFO] Test Explorer found
[2023-03-22 20:27:03.602] [INFO] Creating adapter for /Users/[redacted]/repo
[2023-03-22 20:27:03.602] [INFO] Initializing Ruby adapter
[2023-03-22 20:27:03.602] [INFO] Registering adapter for /Users/[redacted]/repo
[2023-03-22 20:27:03.603] [INFO] Loading Ruby tests...
[2023-03-22 20:27:03.603] [INFO] Loading Minitest tests...
[2023-03-22 20:27:03.603] [INFO] Getting a list of Minitest tests in suite with the following command: bundle exec rake -R $EXT_DIR vscode:minitest:list
[2023-03-22 20:27:03.603] [INFO] Initialization finished
[2023-03-22 20:27:03.637] [INFO] Configuration changed
[2023-03-22 20:27:03.721] [ERROR] Error while finding Minitest test suite: Command failed: bundle exec rake -R $EXT_DIR vscode:minitest:list
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': Could not find 'bundler' (2.2.33) required by your /Users/[redacted]/repo/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.2.33`
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
    from /usr/bin/bundle:23:in `<main>'

[2023-03-22 20:27:03.721] [ERROR] Output: 
[2023-03-22 20:27:03.743] [INFO] Configuration changed

Strangely, my exact configuration was working a couple of weeks ago, but isn't today. It's almost as if VSCode started using a different shell, as I'm also having issues running Rails in the Debug pane when it worked fine a couple of weeks ago.

I tried using the minitest command rake and I got a different, but similar error:

Bundler::LockfileError: You must use Bundler 2 or greater with this lockfile.
/Users/[redacted]/repo/config/boot.rb:3:in `<top (required)>'
/Users/[redacted]/repo/config/application.rb:1:in `require_relative'
/Users/[redacted]/repo/config/application.rb:1:in `<top (required)>'
/Users/[redacted]/repo/Rakefile:4:in `<top (required)>'
/Library/Ruby/Gems/2.6.0/gems/rake-12.3.3/exe/rake:27:in `<top (required)>'

Caused by:
Gem::MissingSpecVersionError: Could not find 'bundler' (2.2.33) required by your /Users/[redacted]/repo/Gemfile.lock.
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.2.33`
Checked in 'GEM_PATH=/Library/Ruby/Gems/2.6.0:/Users/[redacted]/.gem/ruby/2.6.0:/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0', execute `gem env` for more information
/Users/[redacted]/repo/config/boot.rb:3:in `<top (required)>'
/Users/[redacted]/repo/config/application.rb:1:in `require_relative'
/Users/[redacted]/repo/config/application.rb:1:in `<top (required)>'
/Users/[redacted]/repo/Rakefile:4:in `<top (required)>'
/Library/Ruby/Gems/2.6.0/gems/rake-12.3.3/exe/rake:27:in `<top (required)>'
(See full trace by running task with --trace)

I am using zsh, and the default terminal profile for VSCode also uses zsh

pheisiph commented 1 year ago

I ran into the same issue with the same configuration. Turns out that another rspec related extension was the cause - I also had https://github.com/DouglasRochaT/spec-utils installed and enabled. Deactivating this extension fixed it for me. (Your mileage may vary)