Skip to content

Commit

Permalink
Update specs to remove warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
francois2metz committed Jul 24, 2020
1 parent 65fc1e6 commit f3a3c2d
Showing 1 changed file with 56 additions and 56 deletions.
112 changes: 56 additions & 56 deletions spec/em-eventsource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def create_response_headers(status, content_type="", other={})

it "connect to the good server" do
start_source do |source, req|
source.ready_state.must_equal EM::EventSource::CONNECTING
source.url.must_equal "http://example.com/streaming"
req.url.must_equal "http://example.com/streaming"
req.opts[:inactivity_timeout].must_equal 60
req.get_args[0].must_equal({ query: {},
_(source.ready_state).must_equal EM::EventSource::CONNECTING
_(source.url).must_equal "http://example.com/streaming"
_(req.url).must_equal "http://example.com/streaming"
_(req.opts[:inactivity_timeout]).must_equal 60
_(req.get_args[0]).must_equal({ query: {},
head: {"Cache-Control" => "no-cache",
"Accept" => "text/event-stream"},
keepalive: true })
Expand All @@ -39,21 +39,21 @@ def create_response_headers(status, content_type="", other={})

it "connect to the good server with query and headers" do
start_source "http://example.net/streaming", {:chuck => "norris"}, {"DNT" => 1} do |source, req|
req.url.must_equal "http://example.net/streaming"
req.get_args[0].must_equal({ query: {:chuck => "norris"},
head: {"DNT" => 1,
"Cache-Control" => "no-cache",
"Accept" => "text/event-stream"},
keepalive: true })
_(req.url).must_equal "http://example.net/streaming"
_(req.get_args[0]).must_equal({ query: {:chuck => "norris"},
head: {"DNT" => 1,
"Cache-Control" => "no-cache",
"Accept" => "text/event-stream"},
keepalive: true })
EM.stop
end
end

it "connect and error if status != 200" do
start_source do |source, req|
source.error do |error|
error.must_equal "Unexpected response status 400"
source.ready_state.must_equal EM::EventSource::CLOSED
_(error).must_equal "Unexpected response status 400"
_(source.ready_state).must_equal EM::EventSource::CLOSED
EM.stop
end
source.open { assert false }
Expand All @@ -64,8 +64,8 @@ def create_response_headers(status, content_type="", other={})
it "connect and error if the content-type doens't match text/event-stream" do
start_source do |source, req|
source.error do |error|
error.must_equal "The content-type 'text/plop' is not text/event-stream"
source.ready_state.must_equal EM::EventSource::CLOSED
_(error).must_equal "The content-type 'text/plop' is not text/event-stream"
_(source.ready_state).must_equal EM::EventSource::CLOSED
EM.stop
end
req.call_headers(create_response_headers "200", "text/plop")
Expand All @@ -75,7 +75,7 @@ def create_response_headers(status, content_type="", other={})
it "connect and error if the content-type is not set" do
start_source do |source, req|
source.error do |error|
error.must_equal "The content-type '' is not text/event-stream"
_(error).must_equal "The content-type '' is not text/event-stream"
EM.stop
end
req.call_headers(create_response_headers "200", "", "HEADER_NAME" => "BAD")
Expand All @@ -88,7 +88,7 @@ def create_response_headers(status, content_type="", other={})
assert false
end
source.open do
source.ready_state.must_equal EM::EventSource::OPEN
_(source.ready_state).must_equal EM::EventSource::OPEN
assert true
EM.stop
end
Expand All @@ -110,12 +110,12 @@ def create_response_headers(status, content_type="", other={})
req.call_callback
req2 = source.instance_variable_get "@req"
refute_same(req2, req)
req2.get_args[0].must_equal({ head: { "Accept" => "text/event-stream",
_(req2.get_args[0]).must_equal({ head: { "Accept" => "text/event-stream",
"Cache-Control" => "no-cache" },
query: {},
keepalive: true })
req.call_headers(create_response_headers "200", "text/event-stream; charset=utf-8")
source.url.must_equal "http://example.com/streaming2"
_(source.url).must_equal "http://example.com/streaming2"
end
end

Expand All @@ -124,7 +124,7 @@ def create_response_headers(status, content_type="", other={})
it "connect and handle message" do
start_source do |source, req|
source.message do |message|
message.must_equal "hello world"
_(message).must_equal "hello world"
source.close
EM.stop
end
Expand All @@ -135,7 +135,7 @@ def create_response_headers(status, content_type="", other={})
it "handle multiple messages" do
start_source do |source, req|
source.message do |message|
message.must_equal "hello world\nplop"
_(message).must_equal "hello world\nplop"
source.close
EM.stop
end
Expand All @@ -146,7 +146,7 @@ def create_response_headers(status, content_type="", other={})
it "ignore empty message" do
start_source do |source, req|
source.message do |message|
message.must_equal "hello world"
_(message).must_equal "hello world"
EM.stop
end
req.stream_data(":#{eol}#{eol}")
Expand All @@ -157,7 +157,7 @@ def create_response_headers(status, content_type="", other={})
it "removes characters that are not UTF-8" do
start_source do |source, req|
source.message do |message|
message.must_equal "foo?bar"
_(message).must_equal "foo?bar"
source.close
EM.stop
end
Expand All @@ -168,7 +168,7 @@ def create_response_headers(status, content_type="", other={})
it "handle event name" do
start_source do |source, req|
source.on "plop" do |message|
message.must_equal "hello world"
_(message).must_equal "hello world"
source.close
EM.stop
end
Expand All @@ -181,17 +181,17 @@ def create_response_headers(status, content_type="", other={})
req.call_headers(create_response_headers "200", "text/event-stream; charset=utf-8")
req.stream_data("id: roger#{eol}#{eol}")
source.error do |error|
error.must_equal "Connection lost. Reconnecting."
source.ready_state.must_equal EM::EventSource::CONNECTING
_(error).must_equal "Connection lost. Reconnecting."
_(source.ready_state).must_equal EM::EventSource::CONNECTING
EM.add_timer(4) do
req2 = source.instance_variable_get "@req"
refute_same(req2, req)
source.last_event_id.must_equal "roger"
req2.get_args[0].must_equal({ head: { "Last-Event-Id" => "roger",
"Accept" => "text/event-stream",
"Cache-Control" => "no-cache" },
query: {},
keepalive: true })
_(source.last_event_id).must_equal "roger"
_(req2.get_args[0]).must_equal({ head: { "Last-Event-Id" => "roger",
"Accept" => "text/event-stream",
"Cache-Control" => "no-cache" },
query: {},
keepalive: true })
EM.stop
end
end
Expand All @@ -204,17 +204,17 @@ def create_response_headers(status, content_type="", other={})
req.call_headers(create_response_headers "200", "text/event-stream; charset=utf-8")
req.stream_data("id: roger#{eol}#{eol}")
source.error do |error|
error.must_equal "Connection lost. Reconnecting."
source.ready_state.must_equal EM::EventSource::CONNECTING
_(error).must_equal "Connection lost. Reconnecting."
_(source.ready_state).must_equal EM::EventSource::CONNECTING
EM.add_timer(4) do
req2 = source.instance_variable_get "@req"
refute_same(req2, req)
source.last_event_id.must_equal "roger"
req2.get_args[0].must_equal({ head: { "Last-Event-Id" => "roger",
"Accept" => "text/event-stream",
"Cache-Control" => "no-cache" },
query: {},
keepalive: true })
_(source.last_event_id).must_equal "roger"
_(req2.get_args[0]).must_equal({ head: { "Last-Event-Id" => "roger",
"Accept" => "text/event-stream",
"Cache-Control" => "no-cache" },
query: {},
keepalive: true })
EM.stop
end
end
Expand All @@ -225,13 +225,13 @@ def create_response_headers(status, content_type="", other={})
it "handle retry event" do
start_source do |source ,req|
req.stream_data("retry: plop#{eol}#{eol}")
source.retry.must_equal 3
_(source.retry).must_equal 3
req.stream_data("retry: 45plop#{eol}#{eol}")
source.retry.must_equal 3
_(source.retry).must_equal 3
req.stream_data("retry: 1000#{eol}#{eol}")
source.retry.must_equal 1
_(source.retry).must_equal 1
req.stream_data("retry: 400#{eol}#{eol}")
source.retry.must_equal 0
_(source.retry).must_equal 0
EM.stop
end
end
Expand All @@ -245,7 +245,7 @@ def create_response_headers(status, content_type="", other={})
source.close
source.start
req2 = source.instance_variable_get "@req"
req2.middlewares.must_equal [["oup", "la", "boom", proc]]
_(req2.middlewares).must_equal [["oup", "la", "boom", proc]]
EM.stop
end

Expand All @@ -255,7 +255,7 @@ def create_response_headers(status, content_type="", other={})
source.close
source.start
req2 = source.instance_variable_get "@req"
req2.middlewares.must_equal [["oup", proc]]
_(req2.middlewares).must_equal [["oup", proc]]
EM.stop
end

Expand All @@ -265,7 +265,7 @@ def create_response_headers(status, content_type="", other={})
source.close
source.start
req2 = source.instance_variable_get "@req"
req2.middlewares.must_equal [["oup", nil, nil, proc]]
_(req2.middlewares).must_equal [["oup", nil, nil, proc]]
EM.stop
end

Expand All @@ -274,7 +274,7 @@ def create_response_headers(status, content_type="", other={})
source.close
source.start
req2 = source.instance_variable_get "@req"
req2.middlewares.must_equal [["oup", nil]]
_(req2.middlewares).must_equal [["oup", nil]]
EM.stop
end

Expand All @@ -283,7 +283,7 @@ def create_response_headers(status, content_type="", other={})
source.close
source.start
req2 = source.instance_variable_get "@req"
req2.middlewares.must_equal [["oup", "la", "boom", nil]]
_(req2.middlewares).must_equal [["oup", "la", "boom", nil]]
EM.stop
end

Expand All @@ -294,10 +294,10 @@ def create_response_headers(status, content_type="", other={})
source.close
source.start
req2 = source.instance_variable_get "@req"
req2.middlewares.size.must_equal 1
req2.middlewares[0].size.must_equal 4
req2.middlewares[0][0..2].must_equal ["oup", "la", "boom"]
req2.middlewares[0][3].class.must_equal Proc
_(req2.middlewares.size).must_equal 1
_(req2.middlewares[0].size).must_equal 4
_(req2.middlewares[0][0..2]).must_equal ["oup", "la", "boom"]
_(req2.middlewares[0][3].class).must_equal Proc
EM.stop
end
end
Expand All @@ -308,11 +308,11 @@ def create_response_headers(status, content_type="", other={})
source.close
source.start
req2 = source.instance_variable_get "@req"
req2.middlewares.must_equal [["Keep", "me", "equal", nil]]
_(req2.middlewares).must_equal [["Keep", "me", "equal", nil]]
source.close
source.start
req2 = source.instance_variable_get "@req"
req2.middlewares.must_equal [["Keep", "me", "equal", nil]]
_(req2.middlewares).must_equal [["Keep", "me", "equal", nil]]
EM.stop
end
end
Expand All @@ -323,7 +323,7 @@ def create_response_headers(status, content_type="", other={})
source.inactivity_timeout = 0
source.start
req = source.instance_variable_get "@req"
req.opts[:inactivity_timeout].must_equal 0
_(req.opts[:inactivity_timeout]).must_equal 0
EM.stop
end
end
Expand Down

0 comments on commit f3a3c2d

Please sign in to comment.