Skip to content

Commit ae5a415

Browse files
committed
Tweak assert_equal argument order in tests
The argument order for `assert_equal` is expected, actual: https://github.com/minitest/minitest/blob/v5.25.5/lib/minitest/assertions.rb#L214 This PR corrects the arguments that were reversed to the expected order. It also enables `Minitest/LiteralAsActualArgument`, which can detect and autocorrect some of these cases: https://docs.rubocop.org/rubocop-minitest/0.38/cops_minitest.html#minitestliteralasactualargument
1 parent 022b3ff commit ae5a415

File tree

3 files changed

+35
-35
lines changed

3 files changed

+35
-35
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ plugins:
77

88
Gemspec/DevelopmentDependencies:
99
Enabled: true
10+
11+
Minitest/LiteralAsActualArgument:
12+
Enabled: true

test/mcp/server/transports/streamable_http_transport_test.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,12 @@ class StreamableHTTPTransportTest < ActiveSupport::TestCase
413413
io1.rewind
414414
output1 = io1.read
415415
# Session 1 should have received two notifications (one from each request since we broadcast)
416-
assert_equal 2,
417-
output1.scan(/data: {"jsonrpc":"2.0","method":"test_notification","params":{"session":"current"}}/).count
416+
assert_equal 2, output1.scan(/data: {"jsonrpc":"2.0","method":"test_notification","params":{"session":"current"}}/).count
418417

419418
io2.rewind
420419
output2 = io2.read
421420
# Session 2 should have received two notifications (one from each request since we broadcast)
422-
assert_equal 2,
423-
output2.scan(/data: {"jsonrpc":"2.0","method":"test_notification","params":{"session":"current"}}/).count
421+
assert_equal 2, output2.scan(/data: {"jsonrpc":"2.0","method":"test_notification","params":{"session":"current"}}/).count
424422
end
425423

426424
test "send_notification to specific session" do

test/mcp/tool_test.rb

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def call(message:, server_context: nil)
3030
title: "Mock Tool",
3131
description: "a mock tool for testing",
3232
)
33-
assert_equal tool.to_h, { name: "mock_tool", title: "Mock Tool", description: "a mock tool for testing", inputSchema: { type: "object" } }
33+
assert_equal({ name: "mock_tool", title: "Mock Tool", description: "a mock tool for testing", inputSchema: { type: "object" } }, tool.to_h)
3434
end
3535

3636
test "#to_h includes annotations when present" do
@@ -42,13 +42,13 @@ def call(message:, server_context: nil)
4242
idempotentHint: true,
4343
openWorldHint: false,
4444
}
45-
assert_equal tool.to_h[:annotations], expected_annotations
45+
assert_equal expected_annotations, tool.to_h[:annotations]
4646
end
4747

4848
test "#call invokes the tool block and returns the response" do
4949
tool = TestTool
5050
response = tool.call(message: "test")
51-
assert_equal response.content, [{ type: "text", content: "OK" }]
51+
assert_equal [{ type: "text", content: "OK" }], response.content
5252
refute response.error?
5353
end
5454

@@ -60,10 +60,9 @@ class MockTool < Tool
6060
end
6161

6262
tool = MockTool
63-
assert_equal tool.name_value, "my_mock_tool"
64-
assert_equal tool.description, "a mock tool for testing"
65-
assert_equal tool.input_schema.to_h,
66-
{ type: "object", properties: { message: { type: "string" } }, required: [:message] }
63+
assert_equal "my_mock_tool", tool.name_value
64+
assert_equal "a mock tool for testing", tool.description
65+
assert_equal({ type: "object", properties: { message: { type: "string" } }, required: [:message] }, tool.input_schema.to_h)
6766
end
6867

6968
test "defaults to class name as tool name" do
@@ -72,7 +71,7 @@ class DefaultNameTool < Tool
7271

7372
tool = DefaultNameTool
7473

75-
assert_equal tool.tool_name, "default_name_tool"
74+
assert_equal "default_name_tool", tool.tool_name
7675
end
7776

7877
test "input schema defaults to an empty hash" do
@@ -121,9 +120,9 @@ class InputSchemaTool < Tool
121120
Tool::Response.new([{ type: "text", content: "OK" }])
122121
end
123122

124-
assert_equal tool.name_value, "mock_tool"
125-
assert_equal tool.description, "a mock tool for testing"
126-
assert_equal tool.input_schema, Tool::InputSchema.new
123+
assert_equal "mock_tool", tool.name_value
124+
assert_equal "a mock tool for testing", tool.description
125+
assert_equal Tool::InputSchema.new, tool.input_schema
127126
end
128127

129128
test ".define allows definition of tools with annotations" do
@@ -139,11 +138,11 @@ class InputSchemaTool < Tool
139138
Tool::Response.new([{ type: "text", content: "OK" }])
140139
end
141140

142-
assert_equal tool.name_value, "mock_tool"
143-
assert_equal tool.title, "Mock Tool"
144-
assert_equal tool.description, "a mock tool for testing"
141+
assert_equal "mock_tool", tool.name_value
142+
assert_equal "Mock Tool", tool.title
143+
assert_equal "a mock tool for testing", tool.description
145144
assert_equal tool.input_schema, Tool::InputSchema.new
146-
assert_equal tool.annotations_value.to_h, { readOnlyHint: true, title: "Mock Tool" }
145+
assert_equal({ readOnlyHint: true, title: "Mock Tool" }, tool.annotations_value.to_h)
147146
end
148147

149148
# Tests for Tool::Annotations class
@@ -156,11 +155,11 @@ class InputSchemaTool < Tool
156155
open_world_hint: false,
157156
)
158157

159-
assert_equal annotations.title, "Test Tool"
160-
assert_equal annotations.read_only_hint, true
161-
assert_equal annotations.destructive_hint, false
162-
assert_equal annotations.idempotent_hint, true
163-
assert_equal annotations.open_world_hint, false
158+
assert_equal "Test Tool", annotations.title
159+
assert annotations.read_only_hint
160+
refute annotations.destructive_hint
161+
assert annotations.idempotent_hint
162+
refute annotations.open_world_hint
164163
end
165164

166165
test "Tool::Annotations initializes with partial properties" do
@@ -169,8 +168,8 @@ class InputSchemaTool < Tool
169168
read_only_hint: true,
170169
)
171170

172-
assert_equal annotations.title, "Test Tool"
173-
assert_equal annotations.read_only_hint, true
171+
assert_equal "Test Tool", annotations.title
172+
assert annotations.read_only_hint
174173
assert_nil annotations.destructive_hint
175174
assert_nil annotations.idempotent_hint
176175
assert_nil annotations.open_world_hint
@@ -186,7 +185,7 @@ class InputSchemaTool < Tool
186185
title: "Test Tool",
187186
readOnlyHint: true,
188187
}
189-
assert_equal annotations.to_h, expected
188+
assert_equal expected, annotations.to_h
190189
end
191190

192191
test "Tool::Annotations#to_h handles all properties" do
@@ -205,7 +204,7 @@ class InputSchemaTool < Tool
205204
idempotentHint: true,
206205
openWorldHint: false,
207206
}
208-
assert_equal annotations.to_h, expected
207+
assert_equal expected, annotations.to_h
209208
end
210209

211210
test "Tool::Annotations#to_h returns empty hash when all values are nil" do
@@ -224,8 +223,8 @@ class AnnotationsTestTool < Tool
224223

225224
tool = AnnotationsTestTool
226225
assert_instance_of Tool::Annotations, tool.annotations_value
227-
assert_equal tool.annotations_value.title, "Annotations Test"
228-
assert_equal tool.annotations_value.read_only_hint, true
226+
assert_equal "Annotations Test", tool.annotations_value.title
227+
assert tool.annotations_value.read_only_hint
229228
end
230229

231230
test "Tool class method annotations can be updated" do
@@ -235,10 +234,10 @@ class UpdatableAnnotationsTool < Tool
235234

236235
tool = UpdatableAnnotationsTool
237236
tool.annotations(title: "Initial")
238-
assert_equal tool.annotations_value.title, "Initial"
237+
assert_equal "Initial", tool.annotations_value.title
239238

240239
tool.annotations(title: "Updated")
241-
assert_equal tool.annotations_value.title, "Updated"
240+
assert_equal "Updated", tool.annotations_value.title
242241
end
243242

244243
test "#call with Sorbet typed tools invokes the tool block and returns the response" do
@@ -259,7 +258,7 @@ def call(message:, server_context: nil)
259258

260259
tool = TypedTestTool
261260
response = tool.call(message: "test")
262-
assert_equal response.content, [{ type: "text", content: "OK" }]
261+
assert_equal [{ type: "text", content: "OK" }], response.content
263262
refute response.error?
264263
end
265264

@@ -289,13 +288,13 @@ def call(message, server_context: nil)
289288
test "tool call without server context" do
290289
tool = TestToolWithoutServerContext
291290
response = tool.call(message: "test")
292-
assert_equal response.content, [{ type: "text", content: "OK" }]
291+
assert_equal [{ type: "text", content: "OK" }], response.content
293292
end
294293

295294
test "tool call with server context and without required" do
296295
tool = TestToolWithoutRequired
297296
response = tool.call("test", server_context: { foo: "bar" })
298-
assert_equal response.content, [{ type: "text", content: "OK" }]
297+
assert_equal [{ type: "text", content: "OK" }], response.content
299298
end
300299

301300
test "input_schema rejects any $ref in schema" do

0 commit comments

Comments
 (0)