Skip to content

Commit e3427c3

Browse files
Improve coverage for make_response.
1 parent 1e1341a commit e3427c3

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test/protocol/rack/adapter.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,39 @@
1919
expect(subject.parse_file(rackup_path)).to be_a(Proc)
2020
end
2121

22+
with ".make_response" do
23+
let(:env) {Rack::MockRequest.env_for("/")}
24+
25+
it "can make a response" do
26+
response = Protocol::HTTP::Response[200, headers: {}, body: ["Hello World!"]]
27+
status, headers, body = subject.make_response(env, response)
28+
29+
expect(status).to be == 200
30+
expect(headers).to be == {}
31+
expect(body.join).to be == "Hello World!"
32+
end
33+
34+
it "can make a streaming response" do
35+
stream_proc = lambda do |stream|
36+
stream.write("Hello Streaming World")
37+
stream.close
38+
end
39+
40+
body = Protocol::Rack::Body::Streaming.new(stream_proc)
41+
42+
response = Protocol::HTTP::Response[200, headers: {}, body: body]
43+
status, headers, body = subject.make_response(env, response)
44+
45+
expect(status).to be == 200
46+
if headers.include?(Protocol::Rack::RACK_HIJACK)
47+
hijack_proc = headers[Protocol::Rack::RACK_HIJACK]
48+
expect(hijack_proc).to be(:respond_to?, :call)
49+
else
50+
expect(body).to be(:respond_to?, :call)
51+
end
52+
end
53+
end
54+
2255
AnApplication = Sus::Shared("an application") do
2356
include Protocol::Rack::ServerContext
2457

0 commit comments

Comments
 (0)