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 all 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
34 changes: 34 additions & 0 deletions spec/reel/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,40 @@ 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)
example_request = ExampleRequest.new
client << example_request.to_s
request = connection.request

expect(request.inspect).to eq example_request.inspect_method
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
4 changes: 4 additions & 0 deletions spec/support/example_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ def to_s
@headers.map { |k, v| "#{k}: #{v}" }.join("\r\n") << "\r\n\r\n" <<
(@body ? @body : '')
end

def inspect_method
Copy link
Member Author

Choose a reason for hiding this comment

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

I think I could do better with naming this stub. Do you have any suggestions?

"#<Reel::Request #{@method} #{path} HTTP/#{version} @headers=#{@headers}>"
end
end