klen / nvim-test

A Neovim wrapper for running tests
MIT License
176 stars 25 forks source link

Error when setting up rspec runner command to be "bundle exec rspec" #24

Open Davidslv opened 1 year ago

Davidslv commented 1 year ago

Hello,

I'm having a bit of a problem when trying to use rspec runner.

I've noticed that your default setup is to just execute rspec.

Although this causes some problems when the project gem versions are not the same, for instance:

Gem::LoadError:
 You have already activated rspec-support 3.12.0, but your Gemfile requires rspec-support 3.11.1.
 Prepending `bundle exec` to your command may solve this

So I decided to look at replacing the command configuration to command = { "bundle exec rspec"} But this caused another error when attempting to use :TestFile

E5108: Error executing lua Vim:E475: Invalid value for argument cmd: 'bundle exec rspec' is not executable
stack traceback:
        [C]: in function 'exec'
        .../packer/start/nvim-test/lua/nvim-test/terms/terminal.lua:54: in function 'run'
        [string ":lua"]:1: in main chunk

My setup

local status_ok, nvim_test = pcall(require, "nvim-test")

if not status_ok then
  return
end

nvim_test.setup({
  run = true,                 -- run tests (using for debug)
  commands_create = true,     -- create commands (TestFile, TestLast, ...)
  filename_modifier = ":.",   -- modify filenames before tests run(:h filename-modifiers)
  silent = false,             -- less notifications
  term = "terminal",          -- a terminal to run ("terminal"|"toggleterm")
  termOpts = {
    direction = "vertical",   -- terminal's direction ("horizontal"|"vertical"|"float")
    width = 96,               -- terminal's width (for vertical|float)
    height = 24,              -- terminal's height (for horizontal|float)
    go_back = false,          -- return focus to original window after executing
    stopinsert = "auto",      -- exit from insert mode (true|false|"auto")
    keep_one = true,          -- keep only one terminal for testing
  },
  runners = {               -- setup tests runners
    ruby = "nvim-test.runners.rspec",
  }
})

local rspec_runner = require("nvim-test.runners.rspec")

rspec_runner:setup({
  command = { "bundle exec rspec" }
})

Would it be possible to have bundle exec rspec whenever there's a Gemfile present?

rzane commented 1 year ago

This does the trick for me:

require('nvim-test.runners.rspec'):setup({
  command = "bundle",
  args = { "exec", "rspec" },
})
ticklemynausea commented 3 months ago

The snippet above from @rzane does not work for me, but this did

 require('nvim-test.runners.rspec'):setup {
  command = "bundle",
 }

(figured it out from https://github.com/klen/nvim-test/blob/main/lua/nvim-test/runners/rspec.lua#L28)