vscode-ruby-test-adapter icon indicating copy to clipboard operation
vscode-ruby-test-adapter copied to clipboard

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

Open thomthom opened this issue 4 years ago • 2 comments

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 avatar Nov 26 '21 13:11 thomthom

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?

thomthom avatar May 07 '22 13:05 thomthom

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.

kdiogenes avatar Nov 02 '22 22:11 kdiogenes