Skip to content

grzlus-forks/neotest-rspec

 
 

Repository files navigation

neotest-rspec

This plugin provides an RSpec adapter for the Neotest framework.

Neotest and RSPec

📦 Installation

Install with the package manager of your choice:

Lazy

{
  "nvim-neotest/neotest",
  lazy = true,
  dependencies = {
    ...,
    "olimorris/neotest-rspec",
  },
  config = function()
    require("neotest").setup({
      ...,
      adapters = {
        require("neotest-rspec")
      },
    }
  end
}

Packer

use({
  "nvim-neotest/neotest",
  requires = {
    ...,
    "olimorris/neotest-rspec",
  },
  config = function()
    require("neotest").setup({
      ...,
      adapters = {
        require("neotest-rspec"),
      }
    })
  end
})

🔧 Configuration

Default configuration

Note: You only need to the call the setup function if you wish to change any of the defaults

Click to see the default configuration
adapters = {
  require("neotest-rspec")({
    rspec_cmd = function()
      return vim.tbl_flatten({
        "bundle",
        "exec",
        "rspec",
      })
    end,
    root_files = { "Gemfile", ".rspec", ".gitignore" },
    filter_dirs = { ".git", "node_modules" }
  }),
}

The test command

The command used to run tests can be changed via the rspec_cmd option:

require("neotest-rspec")({
  rspec_cmd = function()
    return vim.tbl_flatten({
      "bundle",
      "exec",
      "rspec",
    })
  end
})

Setting the root directory

For Neotest adapters to work, they need to define a project root whereby the process of discovering tests can take place. By default, the adapter looks for a Gemfile, .rspec or .gitignore file. These can be changed with:

require("neotest-rspec")({
  root_files = { "README.md" }
})

You can even set root_files with a function which returns a table:

require("neotest-rspec")({
  root_files = function() return { "README.md" } end
})

Filtering directories

By default, the adapter will search for _spec.rb files in all dirs in the root with the exception of node_modules and .git. You can change this with:

require("neotest-rspec")({
  filter_dirs = { "my_custom_dir" }
})

You can even set filter_dirs with a function which returns a table:

require("neotest-rspec")({
  filter_dirs = function() return { "my_custom_dir" } end
})

Running tests in a docker container

Whilst not directly supported by neotest, but you can accomplish this using a shell script as your Rspec command. See this comment for an example.

🚀 Usage

Note: All usages of require("neotest").run.run can be mapped to a command in your config

Test single function

To test a single test, hover over the test and run require("neotest").run.run()

Test file

To test a file run require("neotest").run.run(vim.fn.expand("%"))

Test directory

To test a directory run require("neotest").run.run("path/to/directory")

Test suite

To test the full test suite run require("neotest").run.run("path/to/root_project") e.g. require("neotest").run.run(vim.fn.getcwd()), presuming that vim's directory is the same as the project root.

🎁 Contributing

This project is maintained by the Neovim Ruby community. Please raise a PR if you are interested in adding new functionality or fixing any bugs. When submitting a bug, please include an example spec that can be tested.

To trigger the tests for the adapter, run:

make test

About

🧪 Neotest adapter for RSpec

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 85.4%
  • Ruby 9.7%
  • Makefile 4.9%