diff --git a/nvimrc b/nvimrc index 7b76dc3..be9dd7d 100644 --- a/nvimrc +++ b/nvimrc @@ -150,6 +150,27 @@ end vim.api.nvim_set_keymap("n", "uu", [[:lua _G.insert_uuid()]], {noremap = true, silent = true}) vim.api.nvim_set_keymap("i", "", [[:lua _G.insert_uuid()a]], {noremap = true, silent = true}) + +_G.run_tests = function() + local bufnr = vim.call("bufnr", "%") + local filetype = vim.call("getbufvar", bufnr, "&filetype", "ERROR") + + if filetype == "" then + print("cannot run tests for filetype:", filetype) + return + end + + if filetype == "ruby" then + local path = vim.call("expand", "%:p") + local altpath = path:gsub("/app/", "/spec/"):gsub([[.rb$]], "_spec.rb") + vim.api.nvim_command([[10split +term\ bundle\ exec\ rspec\ ]] .. altpath) + vim.api.nvim_command([[normal! G]]) + vim.api.nvim_command([[wincmd p]]) + return + end +end + +vim.api.nvim_set_keymap("n", "rt", [[:lua _G.run_tests()]], {noremap = true, silent = true}) EOF " Git mappings