Dynamic working directory based off of current file
rzane opened this issue · comments
Ray Zane commented
I've configured Rspec like this (which should probably be the default):
require('nvim-test.runners.rspec'):setup({
command = "bundle",
args = { "exec", "rspec" },
})
This works perfectly when I open neovim in the directory containing the Gemfile
. However, this doesn't work when I'm working on a project with multiple roots:
project/
a/
Gemfile
spec/a_spec.rb
b/
Gemfile
spec/b_spec.rb
If I'm editing a_spec.rb
, I'd want to execute bundle exec spec/a_spec.rb
with { cwd = "a" }
.
I propose the introduction of runner:find_working_directory(filename)
to dynamically infer the working directory. In the case of RSpec, that implementation might look something like this (adapted from here):
function rspec:find_working_directory(filename)
local gemfile = vim.fn.findfile("Gemfile", vim.fn.fnamemodify(filename, ":p") .. ";")
return vim.fn.fnamemodify(gemfile, ":p:h:t")
end