Closed higgsboz-beam closed 1 year ago
I'm not 100% confident your lazy config is correct. I can't see that you're requiring the adapter. Whilst I use Lazy, my config is a bit different:
config = function()
require("neotest").setup({
adapters = {
require("neotest-plenary"),
require("neotest-rspec"),
require("neotest-phpunit"),
}
}
end
Finally, if you're not going to change the plugin's defaults, it's easiest to not include any options.
Hopefully this works.
Ah I see what you mean about not changing the defaults. And this might end up being a question for the LazyVim maintainer as it looks like the syntax just recently change see here.
I ended up changing my config to this, but am still running into the same issue. Based on that comment, this should be requiring the adapter
return {
{
"nvim-neotest/neotest",
dependencies = {
"olimorris/neotest-rspec",
},
optional = true,
opts = {
adapters = {
["neotest-rspec"] = {},
},
},
},
}
I also attempted the config that you included, but the same issue persisted.
return {
{
"nvim-neotest/neotest",
dependencies = {
"olimorris/neotest-rspec",
},
config = function()
require("neotest").setup({
adapters = {
require("neotest-rspec"),
},
})
end,
},
}
I probably should be clearer in the readme too...but do you have a spec
folder with tests that end in _spec.rb
? Also, does your main root folder have a a "Gemfile", ".rspec", ".gitignore" file?
So there is a top level spec folder, but our project is split into different microservices which have a spec file within those as well. So for example, the test I was trying to run was in a file that looks like this vendor/mobile_api/spec/services/domain/model_spec.rb. Does the spec folder have to be at the root level?
Yes I have all of those files in my root folder
edit: I did attempt to run a test in the root spec folder and that did in fact work. So it looks like the nested spec folders are not currently supported?
Wow. GitHub allowed me to edit your comment, accidentally...
vendor/mobile_api/spec/services/domain/model_spec.rb
. Does thespec
folder have to be at the root level?
Currently it does. I think I'll fix this via a configurable option where a user chooses to search within directories beyond just the spec
folder.
I'll leave this open for now and hopefully fix in the next week.
@higgsboz-beam - This should be fixed in the latest commit. Can you check and let me know?
Closing this but please reopen if still an issue
Validated this is actually finding the spec files and running them now. All are failing at the moment however. It might just be a configuration issue that I need to resolve
@olimorris So I think I figured out what my problem is and was wondering if you could add a configuration option for it. When running the rspec test, it will always run from the relative spec file. This causes an issue for me because we require a spec_helper
from our top level spec folder. But because the test is run relatively, this file cannot be found.
In this example scenario below, if I run the test file my_app/microservice_a/spec/test_spec.rb
, it will run bundle exec rspec ./spec/test_spec.rb
from the microservice_a
directory.
I want to be able to run the spec file from the root my_app
directory so that it would run bundle exec rspec ./microservice_a/spec/test_spec.rb
my_app
|__ spec
|__ spec_helper.rb
|__ microservice_a
|__ spec
|__ test_spec.rb
No, that's not true. If you check your logs you should see something like this:
DEBUG | 2023-05-30T19:12:09Z+0100 | ...nvim/lazy/neotest/lua/neotest/client/strategies/init.lua:35 | Strategy spec {
command = { "bundle", "exec", "rspec", "-f", "json", "-o", "/var/folders/v2/78qsgrqj3c19g1z0vlsxjb3c0000gn/T/nvim.Oli/FQV7In/0", "-f", "progress", "/Users/Oli/Code/Neovim/neotest-rspec/vendor/mobile_api/spec/services/domain/model_spec.rb:2" },
context = {
engine_name = "vendor/mobile_api",
results_path = "/var/folders/v2/78qsgrqj3c19g1z0vlsxjb3c0000gn/T/nvim.Oli/FQV7In/0"
},
cwd = "vendor/mobile_api",
strategy = {}
}
The full command we run with in the adapter is quite extensive...
So the full path and line number are sent to Rspec. In the example above /Users/Oli/Code/Neovim/neotest-rspec/vendor/mobile_api/spec/services/domain/model_spec.rb:2
which works as expected:
I'd advise checking the logs and seeing what comes back
I took a look at the logs and this was the only thing I was seeing. No breakdown on the command run like you showed.
WARN | 2023-05-30T16:13:30Z-0400 | ...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:24 | Position already running: ./vendor/mobile_api/spec/services/mobile_api/plans_service_spec.rb::5
WARN | 2023-05-30T16:25:13Z-0400 | ...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:24 | Position already running: /Users/<name>/repos/myapp/vendor/mobile_api/spec/services/mobile_api/plans_service_spec.rb
However, when I tried to debug the file using
require("neotest").run.run({ vim.fn.expand("%"), strategy = "dap" })
I had two messages displayed through the LazyVim interface (not sure where these come from).
One had a trace like below:
neotest-rspec: ...onminner/.local/share/nvim/lazy/neotest/lua/nio/init.lua:105: The coroutine failed with this message:
...nvim/lazy/neotest/lua/neotest/client/strategies/init.lua:55: attempt to index local 'instance' (a nil value)
stack traceback:
...nvim/lazy/neotest/lua/neotest/client/strategies/init.lua: in function 'run'
...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:129: in function '_run_spec'
...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:89: in function <...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:88>
The other said:
Adapter doesn't support chosen strategy
Just for clarity, this is my neotest.lua
config with nvim-dap
as a dependency
return {
{
"nvim-neotest/neotest",
dependencies = {
"olimorris/neotest-rspec",
"mfussenegger/nvim-dap",
},
config = function()
require("neotest").setup({
adapters = {
require("neotest-rspec")({
root_files = { "Blueprintfile.js", "Blueprintfile.rb" },
}),
},
})
end,
},
}
Yep this adapter doesn't support nvim-dap so the command you should be using is require("neotest").run.run()
, as per the readme. If you run that next to your tests that should work.
Got it. Unfortunately when I run it normally, I don't have any additional logs output to the ~/.local/state/nvim/neotest.log
file. The reason why I thought it was running rspec with a relative path instead of absolute was because of the test output.
An error occurred while loading ./spec/services/mobile_api/plans_service_spec.rb. - Did you mean?
^^^^^^^^^^^ Relative path
<other files here>
Failure/Error: require_relative 'spec_helper'
LoadError:
cannot load such file -- /Users/<name>/repos/myapp/vendor/mobile_api/spec/spec_helper
^^^^^^^^^^^^^ This file doesn't exist, but running from a relative path makes it think it does
I tried to run the test with a relative path just from the normal command line and I had the exact same output. But it wasn't so if I ran it with the absolute path. How are you seeing your logs that you included in your previous message?
Okay, so you'll need to set the log_level
in Neotest to something like 1
to get the logs generated.
If you run bundle exec rspec [path_to_test_file:[line_number]]
does it actually work? I ask because the adapter doesn't do anything too clever; it detects a test file, uses Treesitter to "read" the file and identify tests, then passes the filename and position from Treesitter to the Rspec command.
Also, if you open up the Neotest summary, can you see all of the Rspec tests?
I can see the neotest summary with all of the rspec tests.
My logs look very similar to yours and definitely appear to be running the rspec with the absolute path. The part that I think is causing the issue is the cwd
.
INFO | 2023-05-31T09:48:49Z-0400 | ...nvim/lazy/neotest/lua/neotest/client/strategies/init.lua:34 | Starting process neotest-rspec:/Users/<name>/repos/beam-api-/Users/<name>/repos/beam-api/vendor/mobile_api/spec/services/mobile_api/plans_service_spec.rb with strategy integrated
DEBUG | 2023-05-31T09:48:49Z-0400 | ...nvim/lazy/neotest/lua/neotest/client/strategies/init.lua:35 | Strategy spec {
command = { "bundle", "exec", "rspec", "-f", "json", "-o", "/var/folders/yt/hmhbk7rn08bft4jvbz86fvf80000gq/T/nvim.<name>/ykmHGY/0", "-f", "progress", "/Users/<name>/repos/myapp/vendor/mobile_api/spec/services/mobile_api/plans_service_spec.rb" },
context = {
engine_name = "vendor/mobile_api",
results_path = "/var/folders/yt/hmhbk7rn08bft4jvbz86fvf80000gq/T/nvim.<name>/ykmHGY/0"
},
cwd = "vendor/mobile_api",
strategy = {
height = 40,
width = 120
}
}
If I'm in my project root running bundle exec rspec [path_to_test_file:[line_number]]
it works perfectly. However, if I make my current working directory vendor/mobile_api
and run the same thing, I'll get an error. So it seems like the cwd
is causing the problem. I'm wondering if it's because the bundle exec
relies on the directory that it's executed in? TBH my knowledge of rspec/rails isn't the best so I don't know if this is more of a problem with how my project is set up, or if this is a valid use case. Either way, definitely appreciate you taking the time to help figure this out
I'm wondering if the new root_files
isn't working as intended right now. Instead of doing a vim.list_extend
here, should it be local root_files = config.get_root_files() or { "Gemfile", ".rspec", ".gitignore" }
? I do have a Gemfile
in the vendor/mobile_api
directory which is why it could be using that as the cwd
.
Just to confirm, this works on any test that is in your app's root? It's just once you start trying to run it from the vendor/mobile_api
directory?
Could you share your updated config?
Correct. I actually just realized I could test this out by running a top level spec. When running neotest from a spec in the root spec directory the tests pass. But when running on the nested test, it fails.
Similarly, if I run bundle exec rspec <absolute_path>
from the root directory it works. But if I run it from a nested directory with a Gemfile, it fails.
This is my current config. The two root files only exist at the root which is why I chose them.
return {
{
"nvim-neotest/neotest",
dependencies = {
"olimorris/neotest-rspec",
},
config = function()
require("neotest").setup({
adapters = {
require("neotest-rspec")({
root_files = { "Blueprintfile.js", "Blueprintfile.rb" },
}),
},
})
end,
},
}
Got it! Yep it looks like the presence of the Gemfile in the vendor/mobile_api
dir is scuppering it. I've pushed some config changes as part of 5fe7d86. So now it takes your config OR uses the defaults.
You could set root_files
using a function and some conditionals if required. Let me know how you get on.
From an initial test, it looks like my cwd
is still the vendor/mobile_api
instead of the root, but I haven't had much time to mess around with it. I'll let you know when I get some time to debug it a little more
Hey @higgsboz-beam. Thought I'd check in and see how you're getting on.
I'm attempting to get this set up with LazyVim. I've confirmed that
neotest-rspec
is installed and that the rubynvim-treesitter
parser installed. However, I'm getting an "No Tests Found" message when attempting to run a spec file. Any ideas on what would be going wrong?Neotest.lua config
treesitter.lua config
Pop up error in editor
Log from neotest.log
TSModuleInfo output