diff --git a/README.md b/README.md index 05ca644..b5cd7b0 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ If the extension doesn't work for you, here are a few things you can try: - If you're using RSpec, make sure you're using a recent version of the `rspec-core` gem. If you're on a version prior to 3.6.0, the extension may not work. - If you're using RSpec, make sure that the RSpec command and `spec` directory are configured correctly. By default, tests are run with `bundle exec rspec` and the tests are assumed to be in the `./spec/` directory. You can configure these with `rubyTestExplorer.rspecCommand` and `rubyTestExplorer.rspecDirectory` respectively. - If the test suite info isn't loading, your `testFramework` config may be set to `none` or the auto-detect may be failing to determine the test framework. Try setting the `testFramework` config to `rspec` or `minitest` depending on what you want to use. +- If you are using rvm you may need to manually specify the gemset `rvm use 2.5.0@gemset_name do ./bin/rspec` for example If all else fails or you suspect something is broken with the extension, please feel free to open an issue! :) diff --git a/src/minitestTests.ts b/src/minitestTests.ts index 2d841a9..a1d20a8 100644 --- a/src/minitestTests.ts +++ b/src/minitestTests.ts @@ -86,12 +86,42 @@ export class MinitestTests extends Tests { * * @return The env */ + protected getProcessEnv(): any { + let envPath: string = process.env.PATH; + let newPath: string = envPath; + + let newGemPath: string = process.env.GEM_PATH; + let newGemHome: string = process.env.GEM_HOME + + let vscodeRubyPath: string = vscode.workspace.getConfiguration('ruby', null).get('interpreter.commandPath').replace(/ruby$/,''); + let rvmPattern = new RegExp('/.rvm/rubies/(ruby-[^/]*)/'); // check if rvm is used, extract ruby verision + if( vscodeRubyPath.match(rvmPattern) && envPath.match(rvmPattern) ) { + let vscodeRubyVersion: string = vscodeRubyPath.match(rvmPattern)[1]; + let envRubyVersion: string = envPath.match(rvmPattern)[1]; + this.log.info(`checking ruby versions in vs code config '${vscodeRubyVersion}' vs env ${envRubyVersion}`); + if( vscodeRubyVersion != envRubyVersion ) { + this.log.info(`replace all refrences to ${envRubyVersion} with '${vscodeRubyVersion} in env:`); + // replaceAll still not working in node.js, we have 3 occurences + newPath = envPath.replace(envRubyVersion, vscodeRubyVersion) + .replace(envRubyVersion, vscodeRubyVersion) + .replace(envRubyVersion, vscodeRubyVersion); + this.log.info(`constructed new PATH ${newPath}`); + newGemPath = newGemPath.replace(envRubyVersion, vscodeRubyVersion); + this.log.info(`constructed new GEM_PATH ${newGemPath}`); + newGemHome = newGemHome.replace(envRubyVersion, vscodeRubyVersion); + this.log.info(`constructed new GEM_HOME ${newGemHome}`); + } + } + return Object.assign({}, process.env, { - "RAILS_ENV": "test", - "EXT_DIR": this.getRubyScriptsLocation(), - "TESTS_DIR": this.getTestDirectory(), - "TESTS_PATTERN": this.getFilePattern().join(',') + "RAILS_ENV": "test", + "EXT_DIR": this.getRubyScriptsLocation(), + "TESTS_DIR": this.getTestDirectory(), + "TESTS_PATTERN": this.getFilePattern().join(','), + "PATH": newPath, + "GEM_PATH": newGemPath, + "GEM_HOME": newGemHome }); }