Skip to content

Commit 65e821c

Browse files
committed
style: satisfy standardrb layout and rescue rules
1 parent a33ea71 commit 65e821c

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

test/test_helper.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ def run_transloadit_sig(payload, key:, secret:, algorithm: nil)
7575

7676
module SingletonMethodOverrideHelpers
7777
def with_singleton_method(target, name, implementation)
78-
eigenclass = class << target
79-
self
80-
end
78+
eigenclass = target.singleton_class
8179

8280
backup = "__orig_#{name}_for_test__"
8381
had_method = eigenclass.method_defined?(name) || eigenclass.private_method_defined?(name)
@@ -86,13 +84,15 @@ def with_singleton_method(target, name, implementation)
8684
target.define_singleton_method(name, &implementation)
8785
yield
8886
ensure
89-
eigenclass = class << target
90-
self
87+
eigenclass = target.singleton_class
88+
if eigenclass.method_defined?(name) || eigenclass.private_method_defined?(name)
89+
eigenclass.send(:remove_method, name)
9190
end
92-
eigenclass.send(:remove_method, name) rescue nil
9391
if had_method
9492
eigenclass.send(:alias_method, name, backup)
95-
eigenclass.send(:remove_method, backup) rescue nil
93+
if eigenclass.method_defined?(backup) || eigenclass.private_method_defined?(backup)
94+
eigenclass.send(:remove_method, backup)
95+
end
9696
end
9797
end
9898
end

0 commit comments

Comments
 (0)