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
83 stars 50 forks source link

replace the ruby version in env path #60

Open bjelline opened 3 years ago

bjelline commented 3 years ago

This is a first draft for a fix. I ran into trouble with ruby test adapter using the wrong ruby version.

which version should it be using?

this patch manipulates the environment variables PATH, GEM_PATH and GEM_HOME: it replaces the ruby-version used there with the version from vs code ruby.interpreter.commandPath

only tested on macos, one rails project with minitest, ruby 2.6.6 this is not ready to be merged!

I hope to spark a discussion of how to fix this problem properly

connorshea commented 3 years ago

Interesting, I use rbenv and I haven't noticed any problems like this. I was under the impression it would just use whatever was set for the given repository (either via .ruby-version or the Gemfile) since it's running tests from the repo.

I believe you might be confusing the ruby.interpreter.commandPath as coming from this repo, when it's actually defined by the VS Code Ruby extension, which isn't a dependency of this extension. I'd rather rely on the behavior of the user's ruby version manager (rbenv, rvm, etc.) than implement custom logic like this in the extension.

quoyi commented 3 years ago

.ruby-version and ruby.interpreter.commandPath not working. projectA used ruby 2.6.6, projectB used ruby 2.7.2 will error validate_ruby!': Your Ruby version is 2.6.6, but your Gemfile specified 2.7.2 (Bundler::RubyVersionMismatch)...

AntonDiachuk commented 2 years ago

"rubyTestExplorer.rspecCommand": "rvm use 2.5.0@vault do ./bin/rspec" works for me but I agree with topicstarter.