Permalink
Browse files

further spec DRYed up with em_stream method call

  • Loading branch information...
markburns authored and stevegraham committed Apr 7, 2012
1 parent 4b1254f commit 206b434deb29adfc8459779f6755c72d59c08d6b
Showing with 22 additions and 39 deletions.
  1. +22 −39 spec/integration/integration_spec.rb
@@ -255,27 +255,19 @@ def stream websocket, messages
context 'subscribing with channel data' do
context 'and bogus authentication credentials' do
it 'sends back an error message' do
messages = []
em_thread do
websocket = new_websocket
stream(websocket, messages) do |message|
if messages.length < 2
websocket.send({
event: 'pusher:subscribe', data: {
channel: 'presence-channel', auth: 'bogus'
messages = em_stream do |websocket, messages|
if messages.length < 2
websocket.send({
event: 'pusher:subscribe', data: {
channel: 'presence-channel',
auth: 'bogus'
},
channel_data: {
channel_data: {
user_id: '0f177369a3b71275d25ab1b44db9f95f',
user_info: {
name: 'SG'
}
}
}.to_json)
else
EM.stop
end
name: 'SG' } } }.to_json)
else
EM.stop
end
end
# Slanger should send an object denoting connection was succesfully established
@@ -290,27 +282,18 @@ def stream websocket, messages
context 'with genuine authentication credentials' do
it 'sends back a success message' do
messages = []
em_thread do
websocket = new_websocket
stream(websocket, messages) do |message|
if messages.length < 2
auth = Pusher['presence-channel'].authenticate(messages.first['data']['socket_id'], {
user_id: '0f177369a3b71275d25ab1b44db9f95f',
user_info: {
name: 'SG'
}
})
websocket.send({
event: 'pusher:subscribe', data: {
channel: 'presence-channel'
}.merge(auth)
}.to_json)
else
EM.stop
end
messages = em_stream do |websocket, messages|
if messages.length < 2
auth = Pusher['presence-channel'].authenticate(messages.first['data']['socket_id'], {
user_id: '0f177369a3b71275d25ab1b44db9f95f',
user_info: {
name: 'SG' }})
websocket.send({ event: 'pusher:subscribe',
data: {channel: 'presence-channel'}.
merge(auth)}.to_json)
else
EM.stop
end
end

0 comments on commit 206b434

Please sign in to comment.