Run ruby rspec specs and minitest tests from vscode.
This extension is very heavily inspired by the vscode-jest-runner and ruby-test-runner extensions. ruby-test-runner didn't quite meet my needs to I decided to try and build my own version. ¯\_(ツ)_/¯
Ctrl+Alt+/
(mac: Ctrl+Cmd+/
) will also run tests for the current fileruby-spec-runner.runRspecOrMinitestLine
): Run current line in minitest/rspec. Shortcut: Ctrl+Alt+/
(mac: Ctrl+Cmd+/
)ruby-spec-runner.debugRspecLine
): Debug current line in rspec with your configured debugger. See Debugging a test for more info. Shortcut: Ctrl+K Ctrl+Alt+/
(mac: Cmd+K Ctrl+Cmd+/
)ruby-spec-runner.runRspecOrMinitestFile
): Run whole current minitest/rspec file. Shortcut: Ctrl+Shift+Alt+/
(mac: Ctrl+Shift+Cmd+/
)ruby-spec-runner.debugRspecFile
): Debug whole current rspec file with your configured debugger. See Debugging a test for more info. Shortcut: Ctrl+K Ctrl+Shift+Alt+/
(mac: Cmd+K Ctrl+Shift+Cmd+/
)ruby-spec-runner.clearResults
): Clear test results for the current file (sometimes the extension can get confused if edits are made while tests are running and this command can be used to clear up mistakes)ruby-spec-runner.runFailedExamples
): Re-run failed rspec testsThe following ruby debugging extensions are supported for rspec.
Make sure one of these is installed (and any required setup has been done). Then configure the one you are using via the rubyDebugger
setting for this extension.
I have not had any luck getting minitest working with these debuggers. Help is welcome.
This extension contributes the following settings:
ruby-spec-runner.rspecCommand
: Override the rspec commandruby-spec-runner.rspecEnv
: Pass env vars to the rspec commandruby-spec-runner.rspecDebugEnv
: Additional env vars to the rspec command when debugging. Merges into and overrides env vars set via "rspecEnv"ruby-spec-runner.minitestCommand
: Override the minitest commandruby-spec-runner.minitestEnv
: Pass env vars to the minitest commandruby-spec-runner.changeDirectoryToWorkspaceRoot
: When true the test command will cd to workspace root firstruby-spec-runner.projectPath
: Override the root project pathruby-spec-runner.rspecFormat
: Configure rspec's terminal output formatruby-spec-runner.saveBeforeRunning
: When true the test file is saved before it is runruby-spec-runner.rspecRunButton
: Show a run button in the status barruby-spec-runner.rspecDebugButton
: Show a debug button in the status barruby-spec-runner.rspecRunAllFailedButton
: Show a button to re-run failed tests in the status bar (disabled by default)ruby-spec-runner.minitestRunButton
: Show a run button in the status barruby-spec-runner.rspecCodeLensPrompts
: Show prompts in the editor to run an rspec testruby-spec-runner.rspecCodeLensDebugPrompts
: Show prompts in the editor to debug an rspec testruby-spec-runner.minitestCodeLensPrompts
: Show prompts in the editor to run a minitest testruby-spec-runner.rspecDecorateEditorWithResults
: Show the results of rspec test runs in the editorruby-spec-runner.rspecDecorateEditorWithStaleResults
: Show stale results of rspec test runs in the editorruby-spec-runner.minitestDecorateEditorWithResults
: Show the results of minitest runs in the editorruby-spec-runner.minitestDecorateEditorWithStaleResults
: Show stale results of minitest runs in the editorruby-spec-runner.windowsTerminalType
: For windows users that are using bash instead of powershellruby-spec-runner.overviewHighlightPosition
: Configure the position of result highlights in the overview rulerruby-spec-runner.clearTerminalOnTestRun
: Clear the terminal before running a test commandruby-spec-runner.rubyDebugger
: Select which debugging extension to useruby-spec-runner.rewriteTestPaths
: Change the test path that is run. See Rewriting the test file path for more info.If you're running tests inside a docker container you may need to rewrite the test file path. You can do this with the ruby-spec-runner.rewriteTestPaths
setting. At the moment vscode will only let you edit it via the json file.
Each entry takes 2-4 fields:
from
This is the string to matchto
This is the string to replace the match with. When using a regex can reference group constructs like "$1" (see mdn docs for capabilities)regex
(Optional, default: false) treat "from" as a regex. Regexs are applied with global flag. \
characters will need to be escaped.exclusive
(Optional, default: true) if this entry produces a match, stop looking for other matches{
"ruby-spec-runner.rewriteTestPaths": [
{
"from": "/Users/me/dev/my_project",
"to": "/app"
},
{
"from": "/Users/me/dev/my_other_project",
"to": ""
},
],
}
For more complex re-mappings regex can use regex, regex groups, and combine entries together.
{
// For path "/Users/me/dev/my_project/spec/models/model_spec.rb"
"ruby-spec-runner.rewriteTestPaths": [
{
"from": "me/",
"to": "someone/",
"exclusive": false
// Result is "/Users/someone/dev/my_project/spec/models/model_spec.rb"
},
{
"from": "^.*/my_project",
"to": "/app",
"regex": true
// Result is "/app/spec/models/model_spec.rb"
},
{
"from": "^/Users/(\\w+)/dev/",
"to": "devs/$1_home/",
"regex": true
// Result is "devs/someone_home/my_project/spec/models/model_spec.rb"
// (as "me" is replaced with "someone" by the first entry )
},
],
}
... Are found in the Changelog
page (under "Resources").