Skip to content
This repository has been archived by the owner on Dec 7, 2018. It is now read-only.

Added tests for Reel::Request #227

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions spec/reel/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,39 @@ def test_chunked_response(request, client)
end
end

it "detaches a connection properly" do
with_socket_pair do |client, peer|
connection = Reel::Connection.new(peer)
client << ExampleRequest.new.to_s

expect(connection.detach).to be_a Reel::Connection
expect(connection.attached?).to eq(false)
end
end

it "returns friendlier inspect output" do
with_socket_pair do |client, peer|
connection = Reel::Connection.new(peer)
client << ExampleRequest.new.to_s
request = connection.request

expect(request.inspect).to eq '#<Reel::Request GET / HTTP/1.1 @headers={"Host"=>"www.example.com", "Connection"=>"keep-alive", "User-Agent"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.78 S", "Accept"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Encoding"=>"gzip,deflate,sdch", "Accept-Language"=>"en-US,en;q=0.8", "Accept-Charset"=>"ISO-8859-1,utf-8;q=0.7,*;q=0.3"}>'
Copy link
Member

@digitalextremist digitalextremist Aug 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would pull this user agent especially from a constant @prathmeshranaut. It seems like a good idea to move the ExampleRequest initialization values into a constant, then use the constant in initialize there -- but then also use the constant here in the test. This is a lot of hard-coded ultra-specific information :)

end
end

it "raises an exception if not in chunked body mode" do
with_socket_pair do |client, peer|
connection = Reel::Connection.new(peer)
client << ExampleRequest.new.tap{ |r|
r['Connection'] = 'keep-alive'
}.to_s
request = connection.request
request.respond :ok, :transfer_encoding => ''

expect {request << "Hello"}.to raise_error(Reel::StateError)
end
end

context "#readpartial" do
it "streams request bodies" do
with_socket_pair do |client, peer|
Expand Down
17 changes: 17 additions & 0 deletions spec/reel/websocket_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,23 @@ def initialize(websocket)
end
end

it "writes array messages" do
with_websocket_pair do |client, websocket|
websocket.write Array.new(2) { |e| e = e * 2}

parser = WebSocket::Parser.new

parser.append client.readpartial(4096) until first_message = parser.next_message
expect(first_message).to eq("\x00\x02")
end
end

it "it raises exception when trying to write besides string or array messages" do
with_websocket_pair do |client, websocket|
expect { websocket.write 1 }.to raise_exception('Can only send byte array or string over driver.')
end
end

it "closes" do
with_websocket_pair do |_, websocket|
expect(websocket).not_to be_closed
Expand Down