Permalink
Browse files

formatting

  • Loading branch information...
markburns authored and stevegraham committed Apr 6, 2012
1 parent f0f2ab1 commit 6c8cd96164f9946890fb28c9540452b201132f21
Showing with 40 additions and 19 deletions.
  1. +40 −19 spec/integration/integration_spec.rb
@@ -6,6 +6,8 @@
require 'em-http-request'
require 'pusher'
require 'thin'
require 'ruby-debug'
require 'ap'
describe 'Integration' do
let(:errback) { Proc.new { fail 'cannot connect to slanger. your box might be too slow. try increasing sleep value in the before block' } }
@@ -18,28 +20,18 @@ def new_websocket
end
end
def em_thread
Thread.new do
EM.run do
yield
end
end.join
end
def stream websocket, messages
websocket.stream do |message|
messages << JSON.parse(message)
yield
end
end
before(:each) do
# Fork service. Our integration tests MUST block the main thread because we want to wait for i/o to finish.
@server_pid = EM.fork_reactor do
require File.expand_path(File.dirname(__FILE__) + '/../../slanger.rb')
Thin::Logging.silent = true
Slanger::Config.load host: '0.0.0.0', api_port: '4567', websocket_port: '8080', app_key: '765ec374ae0a69f4ce44', secret: 'your-pusher-secret'
Slanger::Config.load host: '0.0.0.0',
api_port: '4567',
websocket_port: '8080',
app_key: '765ec374ae0a69f4ce44',
secret: 'your-pusher-secret'
Slanger::Service.run
end
# Give Slanger a chance to start
@@ -64,7 +56,35 @@ def stream websocket, messages
def em_stream
messages = []
yield websocket, messages
websocket= nil
em_thread do
websocket = new_websocket
stream(websocket, messages) do |message|
messages << JSON.parse(message)
yield websocket, messages
end
end
return websocket, messages
end
def em_thread
Thread.new do
EM.run do
yield
end
end.join
end
def stream websocket, messages
websocket.stream do |message|
messages << JSON.parse(message)
yield message
end
end
describe 'regular channels:' do
@@ -94,6 +114,7 @@ def em_stream
# Slanger should send out the message
messages.last['event'].should == 'an_event'
messages.last['data'].should == { some: 'data' }.to_json
end
it 'avoids duplicate events' do
@@ -135,6 +156,7 @@ def em_stream
describe 'private channels' do
context 'with valid authentication credentials:' do
it 'accepts the subscription request' do
@@ -165,7 +187,6 @@ def em_stream
it 'sends back an error message' do
messages = []
em_thread do
websocket = new_websocket

0 comments on commit 6c8cd96

Please sign in to comment.