spec-utils.nvim is a Neovim plugin providing utilities to simplify the creation and execution of tests.
.
├── lua
│ └── spec-utils
│ ├── file.lua
│ ├── init.lua
│ ├── tests
│ │ ├── file_spec.lua
│ │ └── utils_spec.lua
│ └── utils.lua
└── plugin
└── spec-utils.lua
- Utils: General-purpose utility functions.
- File: General-purpose to handle the path functions.
- Test Support: Compatible with plenary.nvim.
Using Lazy.nvim:
{
'ally1002/spec-utils.nvim',
dependencies = {
{ 'nvim-lua/plenary.nvim', name = 'plenary' },
},
}Add the following configuration to your init.lua or init.vim:
{
'ally1002/spec-utils.nvim',
dependencies = {
{ 'nvim-lua/plenary.nvim', name = 'plenary' },
},
config = function()
require('spec-utils').setup()
local Utils = require 'spec-utils.utils'
local File = require 'spec-utils.file'
vim.keymap.set('n', '<leader><C-t>', function()
Utils.switch_between_test_and_implementation(vim.api.nvim_buf_get_name(0))
end)
vim.keymap.set('n', '<leader><C-y>', function()
File.copy_test_file(vim.api.nvim_buf_get_name(0))
end)
end,
}| Command | Description |
|---|---|
:SpecUtils copy_test_file |
Copy the test file path. |
:SpecUtils copy_implementation_file |
Copy the implementation file path. |
:SpecUtils copy_current_relative_path |
Copy the current relative path. |
Refer to the examples in the lua/spec-utils/tests directory to understand how to use each module.
Tests are executed using the plenary.nvim framework. Run the tests with:
:lua require('plenary.test_harness').test_directory('lua/spec-utils/tests')Tests are organized by module for easy expansion and maintenance:
- Utils tests:
utils_spec.lua - File tests:
file_spec.lua
Contributions are welcome! Follow these steps:
- Fork this repository.
- Create a new branch:
git checkout -b my-feature. - Commit your changes:
git commit -m 'Add my feature'. - Push to the branch:
git push origin my-feature. - Open a pull request.
This project is licensed under the GNU General Public License v3.0. See the LICENSE file for details.