Easily switch between implementation and test files. What I was missing from similar plugins was the ability to automatically create the test/source file if one did not exist.
Most of the source code is written in Rust so in order to build the plugin Rust needs to be installed on the system.
Using lazy.nvim
{
"gmartsenkov/gotospec.nvim",
lazy = false,
build = "make",
dependencies = { 'jghauser/mkdir.nvim' }
config = function()
require("gotospec").setup({})
end
}
Assign to a keybinding
["<leader>tt"] = {
function()
require("gotospec").jump()
end,
"switch between test/implementation"
},
Custom configuration can set on a per project basis by creating a .gotospec
file in the root of the project.
Example:
{
"language_configs": {
"rb": {
"primary_source_dirs": ["apps", "lib"],
"test_file_suffix": "_spec",
"test_file_matcher": "_spec.rb",
"test_folder": "spec",
"omit_source_dir_from_test_dir": true
}
}
}
The plugin uses vim.fn.getcwd()
by default to determine the project root, however that won't always be accurate.
To fix this I've created root.nvim which providers a helper function that returns the project root.
The jump
method will take an optional cwd
path, if that returns nil it'll default to vim.fn.getcwd()
Example usage -
["<leader>tt"] = {
function()
require("gotospec").jump(
require("root").find()
)
end
}