Skip to content

Commit

Permalink
Recognise namespaced Rails system tests
Browse files Browse the repository at this point in the history
Closes #23
  • Loading branch information
zidhuss committed Aug 5, 2024
1 parent 0543bf4 commit bec6bb2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lua/neotest-minitest/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ function NeotestAdapter.discover_positions(file_path)
; System tests that inherit from ApplicationSystemTestCase
((
class
name: (constant) @namespace.name (superclass) @superclass (#match? @superclass "(ApplicationSystemTestCase)$" )
name: [
(constant) @namespace.name
(scope_resolution scope: (constant) name: (constant) @namespace.name)
]
(superclass) @superclass (#match? @superclass "(ApplicationSystemTestCase)$" )
)) @namespace.definition
; Methods that begin with test_
Expand Down
35 changes: 35 additions & 0 deletions tests/adapter/rails_system_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,39 @@ describe("Rails System Test", function()
assert.are.same(positions, expected_positions)
end)
end)

describe("discover_positions namespaced ApplicationSystemTestCase", function()
async.it("should discover the position for the tests", function()
local test_path = vim.loop.cwd() .. "/tests/minitest_examples/namespaced_rails_system_test.rb"
local positions = plugin.discover_positions(test_path):to_list()
local expected_positions = {
{
id = test_path,
name = "namespaced_rails_system_test.rb",
path = test_path,
range = { 0, 0, 6, 0 },
type = "file",
},
{
{
id = "./tests/minitest_examples/namespaced_rails_system_test.rb::3",
name = "EmailsTest",
path = test_path,
range = { 2, 0, 5, 3 },
type = "namespace",
},
{
{
id = "./tests/minitest_examples/namespaced_rails_system_test.rb::4",
name = "should pass",
path = test_path,
range = { 3, 2, 4, 5 },
type = "test",
},
},
},
}
assert.are.same(positions, expected_positions)
end)
end)
end)
6 changes: 6 additions & 0 deletions tests/minitest_examples/namespaced_rails_system_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require_relative '../application_system_test_case'

class Identity::EmailsTest < ApplicationSystemTestCase
test 'should pass' do
end
end

0 comments on commit bec6bb2

Please sign in to comment.