It runs *_spec.rb
files with RSpec.
It integrates the test results back into Neovim. So you don't have to take your attention away from coding.
It uses Neovim's built-in features to fit seamlessly into your existing workflow:
vim.notify
for notifications.vim.diagnostics
orquickfix list
for presentation of test failures.- Terminal emulator for interactive debugging.
- Runs RSpec spec files individually, registering failures as Neovim diagnostic entries.
- Executes a single test example determined by the cursor position.
- Remembers the last spec file and can re-run it while in the production code buffer.
Ideal during TDD and/or refactoring. - Can repeat the last run on command.
- Runs the test suite (except system tests), presenting failures as a quickfix list.
- Allows interactive debugging by running the nearest test example in the terminal.
- Has good intuition when choosing the RSpec execution command (in the following order of availability):
bin/rspec
bundle exec rspec
rspec
- Resets the command when the current working directory changes.
- Saves open buffers before execution. (One less action to keep in mind.)
- Shows non-RSpec output with error messages.
Hint: Useputs obj.pretty_inspect
to see it as it appears in the IRB console.
At least Neovim v0.7.0 is required.
Please refer to the usage guide of your preferred plugin manager on how to install plugins.
With packer.nvim
use { "melopilosyan/rspec-integrated.nvim" }
With lazy.nvim
{ "melopilosyan/rspec-integrated.nvim", lazy = true }
By default rspec-integrated.nvim
doesn't add any mappings or create user commands.
In fact, it will be auto-loaded only on the first invocation.
Add mappings in your neovim
configuration to invoke the exposed function.
-- Lua API
local opts = { silent = true, noremap = true }
vim.keymap.set("n", "<leader>tI", "<cmd>lua require('rspec.integrated').run()<cr>", opts)
vim.keymap.set("n", "<leader>ti", "<cmd>lua require('rspec.integrated').run({current_example = true})<cr>", opts)
vim.keymap.set("n", "<leader>t.", "<cmd>lua require('rspec.integrated').run({repeat_last_run = true})<cr>", opts)
vim.keymap.set("n", "<leader>td", "<cmd>lua require('rspec.integrated').run({debug = true})<cr>", opts)
vim.keymap.set("n", "<leader>tS", "<cmd>lua require('rspec.integrated').run({suite = true})<cr>", opts)
" VimL
nnoremap <leader>tI <cmd>lua require('rspec.integrated').run()<cr>
nnoremap <leader>ti <cmd>lua require('rspec.integrated').run({current_example = true})<cr>
nnoremap <leader>t. <cmd>lua require('rspec.integrated').run({repeat_last_run = true})<cr>
nnoremap <leader>td <cmd>lua require('rspec.integrated').run({debug = true})<cr>
nnoremap <leader>tS <cmd>lua require('rspec.integrated').run({suite = true})<cr>
The plugin has no configuration.
You should be able to just say “RSpec run” and
display/jump to diagnostic entries as you normally do with LSP or linter messages,
or use quickfix list to navigate failures across multiple files.
Notifications designed to work with the nvim-notify plugin.
But even without it, you'll still see the Neovim's default print lines,
or the look of the plugin assigned to vim.notify
.
Big shout-out to @tjdevries for the initial idea and
valuable lessons on how to run external commands from Neovim and integrate the output
back into the editor. Watch his video tutorial Integrated Test Results in Neovim,
which was the inspiration for rspec-integrated.nvim
.