From 3b1332230624c02b9fcbc75db53cb2e1a5b2730a Mon Sep 17 00:00:00 2001 From: Thomas Marshall Date: Tue, 26 Nov 2024 19:08:42 +0000 Subject: [PATCH] Use File.fnmatch? to select test directory Co-authored-by: Vinicius Stock --- lib/ruby_lsp/listeners/code_lens.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/ruby_lsp/listeners/code_lens.rb b/lib/ruby_lsp/listeners/code_lens.rb index e9a6f4dd9..466af943d 100644 --- a/lib/ruby_lsp/listeners/code_lens.rb +++ b/lib/ruby_lsp/listeners/code_lens.rb @@ -229,10 +229,11 @@ def add_test_code_lens(node, name:, command:, kind:, id: name) ).returns(String) end def generate_test_command(group_stack: [], spec_name: nil, method_name: nil) + path = T.must(@path) command = BASE_COMMAND - command += " -Itest" if T.must(@path).include?("#{File::SEPARATOR}test#{File::SEPARATOR}") - command += " -Ispec" if T.must(@path).include?("#{File::SEPARATOR}spec#{File::SEPARATOR}") - command += " #{T.must(@path)}" + command += " -Itest" if File.fnmatch?("**/test/**/*", path, File::FNM_PATHNAME) + command += " -Ispec" if File.fnmatch?("**/spec/**/*", path, File::FNM_PATHNAME) + command += " #{path}" case @global_state.test_library when "minitest"