|
19 | 19 | expect(subject.parse_file(rackup_path)).to be_a(Proc) |
20 | 20 | end |
21 | 21 |
|
| 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 | + |
22 | 55 | AnApplication = Sus::Shared("an application") do |
23 | 56 | include Protocol::Rack::ServerContext |
24 | 57 |
|
|
0 commit comments