From 96def3ae5363f7567f85fd439a43e6ce12c94f74 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Sat, 9 Dec 2023 22:30:37 +1300 Subject: [PATCH] Add better specs for `HTTP_UPGRADE` and `rack.protocol`. --- test/protocol/rack/request.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/test/protocol/rack/request.rb b/test/protocol/rack/request.rb index ba73127..ee29244 100644 --- a/test/protocol/rack/request.rb +++ b/test/protocol/rack/request.rb @@ -19,16 +19,14 @@ let(:env) {adapter.make_environment(request)} + let(:wrapped_request) {subject.new(env)} + with 'incoming rack env' do it "can restore request from original request" do expect(subject[env]).to be == request end it "can regenerate request from generic env" do - env.delete(Protocol::Rack::PROTOCOL_HTTP_REQUEST) - - wrapped_request = subject[env] - expect(wrapped_request.scheme).to be == request.scheme expect(wrapped_request.authority).to be == request.authority expect(wrapped_request.method).to be == request.method @@ -44,10 +42,18 @@ let(:headers) {Protocol::HTTP::Headers[{'upgrade' => 'websocket'}]} it "can extract upgrade request" do - env.delete(Protocol::Rack::PROTOCOL_HTTP_REQUEST) - - wrapped_request = subject[env] - + expect(wrapped_request).to have_attributes( + protocol: be == ["websocket"] + ) + end + end + + with 'incoming rack env which includes rack.protocol' do + let(:request) {Protocol::HTTP::Request.new( + 'https', 'example.com', 'GET', '/', 'http/1.1', headers, body, ["websocket"] + )} + + it "can extract upgrade request" do expect(wrapped_request).to have_attributes( protocol: be == ["websocket"] )