Skip to content

Commit ec20997

Browse files
kouclaude
andauthored
test: don't override Fake::HTTP.new (#72)
GitHub: fix GH-70 `Fake::HTTP.new` used `Class.method(:new).unbind.bind(self)` to bypass `Net::HTTP.new`. It fails with Ruby 4.1 because `Class.method(:new)` is a singleton method of `Class` now: ```text TypeError: singleton method called for a different object ``` We don't need to bypass `Net::HTTP.new`. We can use the default `Net::HTTP#initialize` and set responses by an attribute writer instead. Reported by Mamoru TASAKA. Thanks!!! Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent dd451e0 commit ec20997

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

‎test/test_client.rb‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,7 @@ class ClientTest < Test::Unit::TestCase
1414

1515
module Fake
1616
class HTTP < Net::HTTP
17-
class << self
18-
def new(*args, &block)
19-
Class.method(:new).unbind.bind(self).call(*args, &block)
20-
end
21-
end
22-
23-
def initialize responses = {}
24-
super("127.0.0.1")
25-
@started = false
26-
@responses = responses
27-
end
17+
attr_writer :responses
2818

2919
def started?
3020
@started
@@ -57,7 +47,7 @@ def initialize(*args)
5747

5848
private
5949
def net_http host, port, proxy_host, proxy_port
60-
HTTP.new
50+
HTTP.new("127.0.0.1")
6151
end
6252
end
6353

@@ -353,7 +343,11 @@ def read filename
353343

354344
def fake_client(responses, uri)
355345
client_class = Class.new(Fake::Client) {
356-
define_method(:net_http) { |*_| Fake::HTTP.new(responses) }
346+
define_method(:net_http) do |*_|
347+
http = Fake::HTTP.new("127.0.0.1")
348+
http.responses = responses
349+
http
350+
end
357351
}
358352
client = client_class.new2(uri)
359353
client.set_parser(parser)

0 commit comments

Comments
 (0)