Skip to content

Run RSpec tests in Neovim. View failures as diagnostic entries, quickfix list, or debug in terminal.

License

Notifications You must be signed in to change notification settings

melopilosyan/rspec-integrated.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 

Repository files navigation

rspec-integrated.nvim

Image showing test failure as a Neovim diagnostic entry

Image of multiple failed test files listed in the quickfix list

RSpec part

It runs *_spec.rb files with RSpec.

Integrated part

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 or quickfix list for presentation of test failures.
  • Terminal emulator for interactive debugging.

Features

  • 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):
    1. bin/rspec
    2. bundle exec rspec
    3. 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: Use puts obj.pretty_inspect to see it as it appears in the IRB console.

Installation

At least Neovim v0.7.0 is required.

Please refer to the usage guide of your preferred plugin manager on how to install plugins.

use { "melopilosyan/rspec-integrated.nvim" }
{ "melopilosyan/rspec-integrated.nvim", lazy = true }

Usage

By default rspec-integrated.nvim doesn't add 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 exposed functions.

-- Lua API
local opts = { silent = true, noremap = true }
vim.keymap.set("n", "<leader>tI", "<cmd>lua require('rspec').run_current_file()<cr>", opts)
vim.keymap.set("n", "<leader>ti", "<cmd>lua require('rspec').run_current_example()<cr>", opts)
vim.keymap.set("n", "<leader>t.", "<cmd>lua require('rspec').repeat_last_run()<cr>", opts)
vim.keymap.set("n", "<leader>td", "<cmd>lua require('rspec').debug()<cr>", opts)
vim.keymap.set("n", "<leader>tS", "<cmd>lua require('rspec').run_suite()<cr>", opts)
" VimL
nnoremap <leader>tI <cmd>lua require('rspec').run_current_file()<cr>
nnoremap <leader>ti <cmd>lua require('rspec').run_current_example()<cr>
nnoremap <leader>t. <cmd>lua require('rspec').repeat_last_run()<cr>
nnoremap <leader>td <cmd>lua require('rspec').debug()<cr>
nnoremap <leader>tS <cmd>lua require('rspec').run_suite()<cr>

Configuration

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.

Credit

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.

About

Run RSpec tests in Neovim. View failures as diagnostic entries, quickfix list, or debug in terminal.

Topics

Resources

License

Stars

Watchers

Forks

Languages