Skip to content

Commit

Permalink
Add support for system test cases (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
igillis authored Apr 19, 2024
1 parent 714abf8 commit f56e5a8
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lua/neotest-minitest/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,30 @@ function NeotestAdapter.discover_positions(file_path)
(superclass (scope_resolution) @superclass (#match? @superclass "^Minitest::Test"))
)) @namespace.definition
; System tests that inherit from ApplicationSystemTestCase
((
class
name: (constant) @namespace.name (superclass) @superclass (#match? @superclass "(ApplicationSystemTestCase)$" )
)) @namespace.definition
; Methods that begin with test_
((
method
name: (identifier) @test.name (#match? @test.name "^test_")
)) @test.definition
; rails unit test classes
; rails unit classes
((
class
name: (constant) @namespace.name
(superclass (scope_resolution) @superclass (#match? @superclass "(::IntegrationTest|::TestCase)$"))
(superclass (scope_resolution) @superclass (#match? @superclass "(::IntegrationTest|::TestCase|::SystemTestCase)$"))
)) @namespace.definition
((
call
method: (identifier) @func_name (#match? @func_name "^(test)$")
arguments: (argument_list (string (string_content) @test.name))
)) @test.definition
]]

return lib.treesitter.parse_positions(file_path, query, {
Expand Down
75 changes: 75 additions & 0 deletions tests/adapter/rails_system_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
local plugin = require("neotest-minitest")
local async = require("nio.tests")

describe("Rails System Test", function()
assert:set_parameter("TableFormatLevel", -1)
describe("discover_positions SystemTestCase", function()
async.it("should discover the position for the tests", function()
local test_path = vim.loop.cwd() .. "/tests/minitest_examples/system_test_case.rb"
local positions = plugin.discover_positions(test_path):to_list()
local expected_positions = {
{
id = test_path,
name = "system_test_case.rb",
path = test_path,
range = { 0, 0, 6, 0 },
type = "file",
},
{
{
id = "./tests/minitest_examples/system_test_case.rb::3",
name = "RailsSystemTest",
path = test_path,
range = { 2, 0, 5, 3 },
type = "namespace",
},
{
{
id = "./tests/minitest_examples/system_test_case.rb::4",
name = "should pass",
path = test_path,
range = { 3, 2, 4, 5 },
type = "test",
},
},
},
}
assert.are.same(positions, expected_positions)
end)
end)

describe("discover_positions ApplicationSystemTestCase", function()
async.it("should discover the position for the tests", function()
local test_path = vim.loop.cwd() .. "/tests/minitest_examples/rails_system_test.rb"
local positions = plugin.discover_positions(test_path):to_list()
local expected_positions = {
{
id = test_path,
name = "rails_system_test.rb",
path = test_path,
range = { 0, 0, 6, 0 },
type = "file",
},
{
{
id = "./tests/minitest_examples/rails_system_test.rb::3",
name = "RailsSystemTest",
path = test_path,
range = { 2, 0, 5, 3 },
type = "namespace",
},
{
{
id = "./tests/minitest_examples/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)
15 changes: 15 additions & 0 deletions tests/minitest_examples/application_system_test_case.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'minitest/autorun'
require 'active_support/message_encryptor'
require 'active_support/dependencies/autoload'
require 'active_support/test_case'
require 'action_controller/template_assertions'
require 'action_dispatch/http/mime_type'
require 'action_dispatch/testing/assertions'
require 'action_dispatch/testing/test_process'
require 'action_dispatch/testing/request_encoder'
require 'action_dispatch/routing'
require 'action_dispatch/system_test_case'

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
end

6 changes: 6 additions & 0 deletions tests/minitest_examples/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 RailsSystemTest < ApplicationSystemTestCase
test "should pass" do
end
end
6 changes: 6 additions & 0 deletions tests/minitest_examples/system_test_case.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require_relative "../application_system_test_case"

class RailsSystemTest < ActionDispatch::SystemTestCase
test "should pass" do
end
end

0 comments on commit f56e5a8

Please sign in to comment.