Merge pull request #116 from koic/tweak_assert_equal_argument_order_in_tests

Tweak `assert_equal` argument order in tests
This commit is contained in:
Koichi ITO 2025-08-27 11:07:00 +09:00 • committed by GitHub
commit aec8fb8b00
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 35 deletions

View file

@ -7,3 +7,6 @@ plugins:
Gemspec/DevelopmentDependencies: Gemspec/DevelopmentDependencies:
Enabled: true Enabled: true
Minitest/LiteralAsActualArgument:
Enabled: true

View file

@ -413,14 +413,12 @@ module MCP
io1.rewind io1.rewind
output1 = io1.read output1 = io1.read
# Session 1 should have received two notifications (one from each request since we broadcast) # Session 1 should have received two notifications (one from each request since we broadcast)
assert_equal 2, assert_equal 2, output1.scan(/data: {"jsonrpc":"2.0","method":"test_notification","params":{"session":"current"}}/).count
output1.scan(/data: {"jsonrpc":"2.0","method":"test_notification","params":{"session":"current"}}/).count
io2.rewind io2.rewind
output2 = io2.read output2 = io2.read
# Session 2 should have received two notifications (one from each request since we broadcast) # Session 2 should have received two notifications (one from each request since we broadcast)
assert_equal 2, assert_equal 2, output2.scan(/data: {"jsonrpc":"2.0","method":"test_notification","params":{"session":"current"}}/).count
output2.scan(/data: {"jsonrpc":"2.0","method":"test_notification","params":{"session":"current"}}/).count
end end
test "send_notification to specific session" do test "send_notification to specific session" do

View file

@ -30,7 +30,7 @@ module MCP
title: "Mock Tool", title: "Mock Tool",
description: "a mock tool for testing", description: "a mock tool for testing",
) )
assert_equal tool.to_h, { name: "mock_tool", title: "Mock Tool", description: "a mock tool for testing", inputSchema: { type: "object" } } assert_equal({ name: "mock_tool", title: "Mock Tool", description: "a mock tool for testing", inputSchema: { type: "object" } }, tool.to_h)
end end
test "#to_h includes annotations when present" do test "#to_h includes annotations when present" do
@ -42,13 +42,13 @@ module MCP
idempotentHint: true, idempotentHint: true,
openWorldHint: false, openWorldHint: false,
} }
assert_equal tool.to_h[:annotations], expected_annotations assert_equal expected_annotations, tool.to_h[:annotations]
end end
test "#call invokes the tool block and returns the response" do test "#call invokes the tool block and returns the response" do
tool = TestTool tool = TestTool
response = tool.call(message: "test") response = tool.call(message: "test")
assert_equal response.content, [{ type: "text", content: "OK" }] assert_equal [{ type: "text", content: "OK" }], response.content
refute response.error? refute response.error?
end end
@ -60,10 +60,9 @@ module MCP
end end
tool = MockTool tool = MockTool
assert_equal tool.name_value, "my_mock_tool" assert_equal "my_mock_tool", tool.name_value
assert_equal tool.description, "a mock tool for testing" assert_equal "a mock tool for testing", tool.description
assert_equal tool.input_schema.to_h, assert_equal({ type: "object", properties: { message: { type: "string" } }, required: [:message] }, tool.input_schema.to_h)
{ type: "object", properties: { message: { type: "string" } }, required: [:message] }
end end
test "defaults to class name as tool name" do test "defaults to class name as tool name" do
@ -72,7 +71,7 @@ module MCP
tool = DefaultNameTool tool = DefaultNameTool
assert_equal tool.tool_name, "default_name_tool" assert_equal "default_name_tool", tool.tool_name
end end
test "input schema defaults to an empty hash" do test "input schema defaults to an empty hash" do
@ -121,9 +120,9 @@ module MCP
Tool::Response.new([{ type: "text", content: "OK" }]) Tool::Response.new([{ type: "text", content: "OK" }])
end end
assert_equal tool.name_value, "mock_tool" assert_equal "mock_tool", tool.name_value
assert_equal tool.description, "a mock tool for testing" assert_equal "a mock tool for testing", tool.description
assert_equal tool.input_schema, Tool::InputSchema.new assert_equal Tool::InputSchema.new, tool.input_schema
end end
test ".define allows definition of tools with annotations" do test ".define allows definition of tools with annotations" do
@ -139,11 +138,11 @@ module MCP
Tool::Response.new([{ type: "text", content: "OK" }]) Tool::Response.new([{ type: "text", content: "OK" }])
end end
assert_equal tool.name_value, "mock_tool" assert_equal "mock_tool", tool.name_value
assert_equal tool.title, "Mock Tool" assert_equal "Mock Tool", tool.title
assert_equal tool.description, "a mock tool for testing" assert_equal "a mock tool for testing", tool.description
assert_equal tool.input_schema, Tool::InputSchema.new assert_equal tool.input_schema, Tool::InputSchema.new
assert_equal tool.annotations_value.to_h, { readOnlyHint: true, title: "Mock Tool" } assert_equal({ readOnlyHint: true, title: "Mock Tool" }, tool.annotations_value.to_h)
end end
# Tests for Tool::Annotations class # Tests for Tool::Annotations class
@ -156,11 +155,11 @@ module MCP
open_world_hint: false, open_world_hint: false,
) )
assert_equal annotations.title, "Test Tool" assert_equal "Test Tool", annotations.title
assert_equal annotations.read_only_hint, true assert annotations.read_only_hint
assert_equal annotations.destructive_hint, false refute annotations.destructive_hint
assert_equal annotations.idempotent_hint, true assert annotations.idempotent_hint
assert_equal annotations.open_world_hint, false refute annotations.open_world_hint
end end
test "Tool::Annotations initializes with partial properties" do test "Tool::Annotations initializes with partial properties" do
@ -169,8 +168,8 @@ module MCP
read_only_hint: true, read_only_hint: true,
) )
assert_equal annotations.title, "Test Tool" assert_equal "Test Tool", annotations.title
assert_equal annotations.read_only_hint, true assert annotations.read_only_hint
assert_nil annotations.destructive_hint assert_nil annotations.destructive_hint
assert_nil annotations.idempotent_hint assert_nil annotations.idempotent_hint
assert_nil annotations.open_world_hint assert_nil annotations.open_world_hint
@ -186,7 +185,7 @@ module MCP
title: "Test Tool", title: "Test Tool",
readOnlyHint: true, readOnlyHint: true,
} }
assert_equal annotations.to_h, expected assert_equal expected, annotations.to_h
end end
test "Tool::Annotations#to_h handles all properties" do test "Tool::Annotations#to_h handles all properties" do
@ -205,7 +204,7 @@ module MCP
idempotentHint: true, idempotentHint: true,
openWorldHint: false, openWorldHint: false,
} }
assert_equal annotations.to_h, expected assert_equal expected, annotations.to_h
end end
test "Tool::Annotations#to_h returns empty hash when all values are nil" do test "Tool::Annotations#to_h returns empty hash when all values are nil" do
@ -224,8 +223,8 @@ module MCP
tool = AnnotationsTestTool tool = AnnotationsTestTool
assert_instance_of Tool::Annotations, tool.annotations_value assert_instance_of Tool::Annotations, tool.annotations_value
assert_equal tool.annotations_value.title, "Annotations Test" assert_equal "Annotations Test", tool.annotations_value.title
assert_equal tool.annotations_value.read_only_hint, true assert tool.annotations_value.read_only_hint
end end
test "Tool class method annotations can be updated" do test "Tool class method annotations can be updated" do
@ -235,10 +234,10 @@ module MCP
tool = UpdatableAnnotationsTool tool = UpdatableAnnotationsTool
tool.annotations(title: "Initial") tool.annotations(title: "Initial")
assert_equal tool.annotations_value.title, "Initial" assert_equal "Initial", tool.annotations_value.title
tool.annotations(title: "Updated") tool.annotations(title: "Updated")
assert_equal tool.annotations_value.title, "Updated" assert_equal "Updated", tool.annotations_value.title
end end
test "#call with Sorbet typed tools invokes the tool block and returns the response" do test "#call with Sorbet typed tools invokes the tool block and returns the response" do
@ -259,7 +258,7 @@ module MCP
tool = TypedTestTool tool = TypedTestTool
response = tool.call(message: "test") response = tool.call(message: "test")
assert_equal response.content, [{ type: "text", content: "OK" }] assert_equal [{ type: "text", content: "OK" }], response.content
refute response.error? refute response.error?
end end
@ -289,13 +288,13 @@ module MCP
test "tool call without server context" do test "tool call without server context" do
tool = TestToolWithoutServerContext tool = TestToolWithoutServerContext
response = tool.call(message: "test") response = tool.call(message: "test")
assert_equal response.content, [{ type: "text", content: "OK" }] assert_equal [{ type: "text", content: "OK" }], response.content
end end
test "tool call with server context and without required" do test "tool call with server context and without required" do
tool = TestToolWithoutRequired tool = TestToolWithoutRequired
response = tool.call("test", server_context: { foo: "bar" }) response = tool.call("test", server_context: { foo: "bar" })
assert_equal response.content, [{ type: "text", content: "OK" }] assert_equal [{ type: "text", content: "OK" }], response.content
end end
test "input_schema rejects any $ref in schema" do test "input_schema rejects any $ref in schema" do