test/angelo/websocket_spec.rb in angelo-0.1.14 vs test/angelo/websocket_spec.rb in angelo-0.1.15
- old
+ new
@@ -1,8 +1,8 @@
require_relative '../spec_helper'
-describe Angelo::WebsocketResponder do
+describe Angelo::Responder::Websocket do
def websocket_wait_for path, latch, expectation, key = :swf, &block
Reactor.testers[key] = Array.new CONCURRENCY do
wsh = websocket_helper path
wsh.on_message = ->(e) {
@@ -223,13 +223,19 @@
end
end
describe 'helper contexts' do
- let(:obj){ {'foo' => 'bar'} }
- let(:wait_for_block){ ->(e){ assert_equal obj, JSON.parse(e.data) }}
+ def obj
+ { 'foo' => 'bar' }
+ end
+
+ def wait_for_block
+ ->(e){ assert_equal obj, JSON.parse(e.data) }
+ end
+
define_app do
post '/' do
websockets.each {|ws| ws.write params.to_json}
''
@@ -339,9 +345,38 @@
Reactor.stop!
[:hmc, :hmc_one, :hmc_other].each do |k|
Reactor.testers.delete k
end
Reactor.remove_action :go
+ end
+
+ end
+
+ describe 'params' do
+
+ def wait_for_block
+ ->(e){ assert_equal({'bar' => 'foo', 'baz' => 'bat'}, JSON.parse(e.data)) }
+ end
+
+ define_app do
+
+ websocket '/' do |ws|
+ websockets[params[:bar].to_sym] << ws
+ end
+
+ post '/' do
+ pj = params.to_json
+ websockets[params[:bar].to_sym].each {|ws| ws.write pj}
+ end
+
+ end
+
+ it 'uses params correctly' do
+ latch = CountDownLatch.new CONCURRENCY
+ websocket_wait_for '/?bar=foo', latch, wait_for_block do
+ post '/', bar: 'foo', baz: 'bat'
+ latch.wait
+ end
end
end
end