foneandrew / ruby-spec-runner

Run specific rspec & minitest tests from within vscode
MIT License
9 stars 3 forks source link

Ruby spec runner

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. ¯\_(ツ)_/¯

Features

screenshot of an example spec

Extension Commands

Debugging a test

The 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.

Extension Settings

This extension contributes the following settings:

Rewriting the test file path

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:

Simple example

{
  "ruby-spec-runner.rewriteTestPaths": [
    {
      "from": "/Users/me/dev/my_project",
      "to": "/app"
    },
    {
      "from": "/Users/me/dev/my_other_project",
      "to": ""
    },
  ],
}

Complex example

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 )
    },
  ],
}

Known Issues

Release Notes

... Are found in the Changelog page (under "Resources").