Skip to content

Commit

Permalink
Fix running tests by directory (zidhuss#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhawthorn authored and ippachi committed Nov 8, 2024
1 parent b7a034f commit b89106d
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lua/neotest-minitest/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,33 @@ function NeotestAdapter.build_spec(args)
end

local function run_dir()
table.insert(script_args, position.path .. "/**/*_test.rb")
local tree = args.tree
local root = tree:root():data().path

-- This emulates an combination of Rake::TestTask with loader=:direct and
-- rake_test_loader
table.insert(script_args, "-e")
table.insert(script_args, "while (f = ARGV.shift) != '--'; require f; end")

-- Instruct Ruby to stop parsing options
table.insert(script_args, "--")

for _, node in tree:iter_nodes() do
if node:data().type == "file" then
local path = node:data().path
table.insert(script_args, path)
end
end

-- Mark the end of test files
table.insert(script_args, "--")
end

if position.type == "file" then run_by_filename() end

if position.type == "test" or position.type == "namespace" then run_by_name() end

if position.type == "dir" then return run_dir() end
if position.type == "dir" then run_dir() end

local command = vim.tbl_flatten({
config.get_test_cmd(),
Expand Down

0 comments on commit b89106d

Please sign in to comment.