Skip to content

Commit 205f42c

Browse files
committed
cleanup of assert_visibility
1 parent 8008f35 commit 205f42c

File tree

3 files changed

+24
-35
lines changed

3 files changed

+24
-35
lines changed

lib/rbs/unit_test/type_assertions.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,12 @@ def assert_const_type(type, constant_name)
323323
assert typecheck.value(constant, definition_type), "`#{constant_name}` (#{constant.inspect}) must be compatible with RBS type definition `#{definition_type}`"
324324
end
325325

326-
def assert_visibility(visibility, receiver, method)
326+
def assert_visibility(visibility, method)
327327
_, definition = target
328328
method_entry = definition.methods[method]
329329

330330
assert method_entry, "Method `#{method}` not found in RBS definition"
331-
assert_equal visibility, method_entry.accessibility,
331+
assert visibility == method_entry.accessibility,
332332
"Expected `#{method}` to be #{visibility}, but was #{method_entry.accessibility}"
333333
end
334334

sig/unit_test/type_assertions.rbs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ module RBS
179179
#
180180
def assert_type: (String | Types::t value_type, untyped value) -> void
181181

182+
# Asserts if given `value` has a type of `value_type`
183+
#
184+
def assert_visibility: (:private | :public visibility, Symbol method_name) -> void
185+
182186
# Allow non _simple-type_ method types given to `assert_send_type` and `refute_send_type`
183187
#
184188
# ```ruby

test/stdlib/Module_test.rb

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,10 @@ def test_prepend
133133
end
134134

135135
def test_refine
136+
assert_visibility :private, :refine
137+
136138
assert_send_type "(Module) { () -> void } -> Refinement",
137139
RefinedModule, :refine, Integer do nil end
138-
139-
assert_visibility :private,
140-
RefinedModule, :refine
141140
end
142141

143142
def test_refinements
@@ -212,8 +211,7 @@ def foo; end
212211
def bar; end
213212
end
214213

215-
assert_visibility :private,
216-
mod, :module_function
214+
assert_visibility :private, :module_function
217215

218216
# No arguments
219217
assert_send_type '() -> nil',
@@ -281,8 +279,8 @@ def foo; end
281279
def bar; end
282280
end
283281

284-
assert_visibility :private,
285-
mod, visibility
282+
assert_visibility :private, visibility
283+
286284
# No arguments
287285
assert_send_type '() -> nil',
288286
mod, visibility
@@ -471,8 +469,7 @@ def foo(*x) = 3
471469
def bar(*x) = 3
472470
end
473471

474-
assert_visibility :private,
475-
mod, :ruby2_keywords
472+
assert_visibility :private, :ruby2_keywords
476473

477474
with_interned :foo do |foo|
478475
assert_send_type '(interned) -> nil',
@@ -1101,16 +1098,14 @@ def foo = 4
11011098
end
11021099

11031100
def test_append_features
1104-
assert_visibility :private,
1105-
Module.new, :append_features
1101+
assert_visibility :private, :append_features
11061102

11071103
assert_send_type '(Module) -> Module',
11081104
Module.new, :append_features, Module.new
11091105
end
11101106

11111107
def test_const_added
1112-
assert_visibility :private,
1113-
Module.new, :const_added
1108+
assert_visibility :private, :const_added
11141109

11151110
# const_added directly works
11161111
assert_send_type '(Symbol) -> void',
@@ -1138,8 +1133,7 @@ def test_const_added
11381133
end
11391134

11401135
def test_extend_object
1141-
assert_visibility :private,
1142-
Module.new, :extend_object
1136+
assert_visibility :private, :extend_object
11431137

11441138
with_untyped_singleton_possible do |untyped|
11451139
assert_send_type '[T] (T) -> T',
@@ -1152,8 +1146,7 @@ def test_extend_object
11521146
end
11531147

11541148
def test_extended
1155-
assert_visibility :private,
1156-
Module.new, :extended
1149+
assert_visibility :private, :extended
11571150

11581151
with_untyped_singleton_possible do |untyped|
11591152
assert_send_type '(untyped) -> void',
@@ -1166,8 +1159,7 @@ def test_extended
11661159
end
11671160

11681161
def test_included
1169-
assert_visibility :private,
1170-
Module.new, :included
1162+
assert_visibility :private, :included
11711163

11721164
assert_send_type '(Module) -> void',
11731165
Module.new, :included, Module.new
@@ -1177,8 +1169,7 @@ def test_included
11771169
end
11781170

11791171
def test_method_added
1180-
assert_visibility :private,
1181-
Module.new, :method_added
1172+
assert_visibility :private, :method_added
11821173

11831174

11841175
# method_added directly works
@@ -1200,8 +1191,7 @@ def test_method_added
12001191
end
12011192

12021193
def test_method_removed
1203-
assert_visibility :private,
1204-
Module.new, :method_removed
1194+
assert_visibility :private, :method_removed
12051195

12061196
# method_removed directly works
12071197
assert_send_type '(Symbol) -> void',
@@ -1222,8 +1212,7 @@ def test_method_removed
12221212
end
12231213

12241214
def test_method_undefined
1225-
assert_visibility :private,
1226-
Module.new, :method_undefined
1215+
assert_visibility :private, :method_undefined
12271216

12281217
# method_undefined directly works
12291218
assert_send_type '(Symbol) -> void',
@@ -1244,8 +1233,7 @@ def test_method_undefined
12441233
end
12451234

12461235
def test_prepend_features
1247-
assert_visibility :private,
1248-
Module.new, :prepend_features
1236+
assert_visibility :private, :prepend_features
12491237

12501238
assert_send_type '(Module) -> Module',
12511239
Module.new, :prepend_features, Module.new
@@ -1255,8 +1243,7 @@ def test_prepend_features
12551243
end
12561244

12571245
def test_prepended
1258-
assert_visibility :private,
1259-
Module.new, :prepended
1246+
assert_visibility :private, :prepended
12601247

12611248
assert_send_type '(Module) -> void',
12621249
Module.new, :prepended, Module.new
@@ -1266,8 +1253,7 @@ def test_prepended
12661253
end
12671254

12681255
def test_remove_const
1269-
assert_visibility :private,
1270-
Module.new, :remove_const
1256+
assert_visibility :private, :remove_const
12711257

12721258
with_interned :Foo do |name|
12731259
mod = Module.new
@@ -1284,8 +1270,7 @@ module UsingModule
12841270
end
12851271

12861272
def test_using
1287-
assert_visibility :private,
1288-
Module.new, :using
1273+
assert_visibility :private, :using
12891274

12901275
# Cant actually test `using` in modules, so this is the best we got
12911276
assert_type 'Module', UsingModule::UsingReturnValue

0 commit comments

Comments
 (0)