Skip to content

Commit 92efe62

Browse files
thiagoaclaude
andcommitted
Add tests and mark internal classes as nodoc
Test that each differing method appears once in failure_message (the diff array contains a method twice when it differs between sides, and `.uniq` prevents duplicate blocks in the output). Also test that assert_interfaces_match passes for matching pairs even when another class in the list mismatches. Mark ParamsNormalizer, NullParamsNormalizer, and MethodInspector as :nodoc: since they are internal implementation details. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d73b40e commit 92efe62

5 files changed

Lines changed: 21 additions & 3 deletions

File tree

lib/duck_typer/method_inspector.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
module DuckTyper
4-
module MethodInspector
4+
module MethodInspector # :nodoc:
55
TYPES = %i[instance_methods class_methods].freeze
66

77
def self.for(object, type)

lib/duck_typer/null_params_normalizer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module DuckTyper
44
# A no-op params processor that returns params unchanged. Used when
55
# interface comparison should preserve original parameter names rather
66
# than normalizing them.
7-
class NullParamsNormalizer
7+
class NullParamsNormalizer # :nodoc:
88
def self.call(params)
99
params
1010
end

lib/duck_typer/params_normalizer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module DuckTyper
66
# are equivalent — so keywords are sorted alphabetically. Positional
77
# argument names are also replaced with sequential placeholders,
88
# focusing the comparison on parameter structure rather than naming.
9-
class ParamsNormalizer
9+
class ParamsNormalizer # :nodoc:
1010
KEYWORD_TYPES = %i[key keyreq].freeze
1111
SEQUENTIAL_TYPES = %i[req opt rest keyrest block].freeze
1212

test/duck_typer/interface_checker_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,15 @@ def test_failure_message_includes_differing_method_signatures
439439
assert_includes message, "foo()"
440440
end
441441

442+
def test_failure_message_shows_each_differing_method_once
443+
left = Class.new { def foo(a) = nil }
444+
right = Class.new { def foo = nil }
445+
446+
message = call_checker(left, right).failure_message
447+
448+
assert_equal 1, message.scan("foo(a)").size
449+
end
450+
442451
def test_failure_message_shows_not_defined_for_missing_method
443452
left = Class.new { def foo = nil; def bar = nil }
444453
right = Class.new { def foo = nil }

test/duck_typer/minitest_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ def test_passes_when_interfaces_match
1212
assert_interfaces_match [a, b, c]
1313
end
1414

15+
def test_passes_for_matching_pairs_even_when_another_class_mismatches
16+
a = Class.new { def foo(a) = nil }
17+
b = Class.new { def foo(a) = nil }
18+
c = Class.new { def foo = nil }
19+
20+
assert_interfaces_match [a, b]
21+
assert_raises(Minitest::Assertion) { assert_interfaces_match [a, b, c] }
22+
end
23+
1524
def test_fails_when_interfaces_do_not_match
1625
a = Class.new { def foo(a) = nil }
1726
b = Class.new { def foo(a) = nil }

0 commit comments

Comments
 (0)