small cleanup in type definitions and webmock testing

This commit is contained in:
HoneyryderChuck 2023-11-22 11:07:54 +00:00
parent 354bba3179
commit 79756e4ac4
2 changed files with 27 additions and 23 deletions

View File

@ -26,6 +26,7 @@ class WebmockTest < Minitest::Test
end
def teardown
super
WebMock.reset!
WebMock.allow_net_connect!
WebMock.disable!
@ -233,10 +234,11 @@ class WebmockTest < Minitest::Test
end
def test_webmock_with_stream_plugin_each
session = HTTPX.plugin(:stream)
request = stub_request(:get, MOCK_URL_HTTP).to_return(body: "body")
body = "".b
response = HTTPX.plugin(:stream).get(MOCK_URL_HTTP, stream: true)
response = session.get(MOCK_URL_HTTP, stream: true)
response.each do |chunk|
next if (300..399).cover?(response.status)

View File

@ -1,26 +1,4 @@
module HTTPX
class StreamResponse
include _ToS
@request: Request & RequestMethods
@session: sessionStream
@on_chunk: ^(String) -> void | nil
def each: () { (String) -> void } -> void
| () -> Enumerable[String]
def each_line: () { (String) -> void } -> void
| () -> Enumerable[String]
def on_chunk: (string) -> void
def initialize: (Request, Session) -> void
private
def response: () -> response
end
module Plugins
module Stream
module InstanceMethods
@ -42,4 +20,28 @@ module HTTPX
type sessionStream = Session & Stream::InstanceMethods
end
class StreamResponse
include _ToS
type streamRequest = Request & Plugins::Stream::RequestMethods
@request: streamRequest
@session: Plugins::sessionStream
@on_chunk: ^(String) -> void | nil
def each: () { (String) -> void } -> void
| () -> Enumerable[String]
def each_line: () { (String) -> void } -> void
| () -> Enumerable[String]
def on_chunk: (string) -> void
def initialize: (streamRequest, Plugins::sessionStream) -> void
private
def response: () -> response
end
end