An extension that handles VS Code automated testing is the Test Explorer UI (https://marketplace.visualstudio.com/items?itemName=hbenl.vscode-test-explorer). The adapter for ruby of this extension is Ruby Test Explorer, which can handle rspec and minitest.
There is also an extension called Ruby that allows you to use Breakpoint and step execution for Ruby.
This backend is realized by the gems ruby-debug-ide
and debase
.
Ruby Test Explorer uses "Ruby" as an extension to drive the debug icon.
Expected figure that seems to be such an image
Breakpoint doesn't work when I run a test from a view in the Test Explorer UI for a minitest that Rails automatically generates. In a little more detail, breakpoints work in the (main) context of the test file, but not in the test block.
When rails new, minitest is designed to perform parallel test by default.
test/test_helper.rb
ENV['RAILS_ENV'] ||= 'test'
require_relative '../config/environment'
require 'rails/test_help'
class ActiveSupport::TestCase
# Run tests in parallel with specified workers
parallelize(workers: :number_of_processors) # <=here! !!
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
# Add more helper methods to be used by all tests here...
end
According to Rails Guide For example, it seems that this is done in DRb and runs on different instances of RubyVM. If the understanding of the previous figure is correct, it will be a different RubyVM = ruby-debug-ide will be a VM for which debase is not set, so the breakpoint will not work.
I mean, the controller should have a few tests, On the log of Ruby Test Explorer, it seems that information such as 0 successes in all 0 cases is returned.
If possible, I want to make "parallelize works when executing normally from Test Explorer, and works as a single when executing debug". However, it was difficult to say from the conclusion.
For example, there is a setting to specify the command to be given, so I thought that it could be switched with an environment variable ...
parallelize(workers: :number_of_processors) unless ENV['TEST_SERIAL'].present?
{
"rubyTestExplorer.minitestCommand": "TEST_SERIAL=1 ./bin/rake"
}
This specifies the command for normal execution, When I run the debug icon, the result looks like this:
[2020-11-06 17:34:09.425] [INFO] Debugging test(s) ["controllers"] of /.................
[2020-11-06 17:34:09.425] [INFO] Running Ruby tests ["controllers"]
[2020-11-06 17:34:09.425] [INFO] Starting the debug session
[2020-11-06 17:34:09.426] [INFO] Running test file: /............../test/controllers/posts_controller_test.rb
[2020-11-06 17:34:09.426] [INFO] Running command: rdebug-ide --host 127.0.0.1 --port 1234 -- $EXT_DIR/debug_minitest.rb 'test/controllers/posts_controller_test.rb'
...
Unfortunately, Ruby Test Explorer can't customize commands when debugging.
parallelize(workers: :number_of_processors, with: :threads)
I thought that Thread should work on the same RubyVM ... but apparently it doesn't work.
After all, if you completely abandon parallel execution, the solution will be solved.
test/test_helper.rb
ENV['RAILS_ENV'] ||= 'test'
require_relative '../config/environment'
require 'rails/test_help'
class ActiveSupport::TestCase
# Run tests in parallel with specified workers
# parallelize(workers: :number_of_processors) # <= comment out or delete this line.
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
# Add more helper methods to be used by all tests here...
end
Recommended Posts