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

Not picking up the library paths defined in the rake task? #86

Open thomthom opened 3 years ago

thomthom commented 3 years ago

I got a Rake task for my tests that looks like this:

Rake::TestTask.new(:test) do |task|
  task.libs << 'tools/lib'
  task.libs << 'tools/tests'
  task.test_files = FileList['tools/tests/test_*.rb']
end

I originally configured the test runner as:

{
  "rubyTestExplorer.debugCommand": "bundle exec rdebug-ide",
  "rubyTestExplorer.minitestCommand": "bundle exec rake",
  "rubyTestExplorer.minitestDirectory": "./tools/tests/",
}

But that would not discover, run or debug any tests because the lib paths from the Rake task where not recognized.

I was however able to make it work by adding the lib paths again to each command:

{
  "rubyTestExplorer.debugCommand": "bundle exec rdebug-ide -I tools/lib -I tools/tests",
  "rubyTestExplorer.minitestCommand": "bundle exec rake -I tools/lib -I tools/tests",
  "rubyTestExplorer.minitestDirectory": "./tools/tests/",
}

Is this expected? Is there a different way I can set this up that avoids duplicating the paths in multiple places?

thomthom commented 2 years ago

I ran into this again with another project. I have test helpers that via Rake I'm adding the paths to (task.libs <<). This works fine via bundle exec rake from the console, but not via this extension - even though it executes bundle exec rake.

Am I going against the grain here?

kdiogenes commented 2 years ago

Hey @thomthom!

In my test file I used required_relative "../lib/file.rb" and it works. From what I dig the problem is that the extension call one rake task defined by it that uses this code that requires the test files from our lib: https://github.com/connorshea/vscode-ruby-test-adapter/blob/main/ruby/vscode/minitest/tests.rb. From my understanding, it's not using/knowing your Rakefile.

If you want to use only require you need to make sure that something like the following $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__) runs during the load of your test files.