var http = require('http');
var assert = require('assert');
var Primus = require('primus');
var cb = require('assert-called');
var PrimusRedisRooms = require('../');
var PORT = 3457;

var server = http.createServer();
var clients = 0;
var primus0, primus1;

function getPrimus() {
  var server = http.createServer();
  var primus = new Primus(server, {
    redis: {
      host: 'localhost',
      port: 6379
    },
    transformer: 'websockets'
  });
  primus.use('redis', PrimusRedisRooms);

  primus.on('connection', function (spark) {
    spark.join('our-room');
  });

  primus.port = PORT;
  server.listen(PORT++);
  return primus;
}

function getClient(primus) {
  ++clients;
  var client = new (primus.Socket)('http://localhost:' + primus.port);

  client.on('open', cb(function () { }));

  client.on('data', cb(function (msg) {
    assert.deepEqual(msg, { room: 'our-room', data: { hello: 'world' } });
    clients--;
    console.log('clients left', clients);
    if (clients === 0) {
      process.exit();
    }
  }));
}

primus0 = getPrimus();
primus1 = getPrimus();

var client0 = getClient(primus0);
var client1 = getClient(primus1);

setTimeout(function () {
  primus0.room('our-room').write({ hello: 'world' });
  primus1.room('our-room').write({ hello: 'world' });
}, 100);

@@ -1,32 +1,4 @@
-var http = require('http');%0A
 var 
@@ -29,40 +29,8 @@
 ');%0A
-var Primus = require('primus');%0A
 var 
@@ -64,32 +64,25 @@
 ');%0Avar 
+get
 Primus
-RedisRooms
  = requi
@@ -90,14 +90,35 @@
 e('.
-.
 /
+helpers/get-primus.js
 ');%0A
+%0A
 var 
@@ -135,42 +135,8 @@
 7;%0A%0A
-var server = http.createServer();%0A
 var 
@@ -184,269 +184,20 @@
 ion 
-getPrimus() %7B%0A  var server = http.createServer();%0A  var primus = new Primus(server, %7B%0A    redis: %7B%0A      host: 'localhost',%0A      port: 6379%0A    %7D,%0A    transformer: 'websockets'%0A  %7D);%0A  primus.use('redis', PrimusRedisRooms);%0A%0A  primus.on('connection', function 
+onConnection
 (spa
@@ -202,18 +202,16 @@
 park) %7B%0A
-  
   spark.
@@ -232,79 +232,8 @@
 ');%0A
-  %7D);%0A%0A  primus.port = PORT;%0A  server.listen(PORT++);%0A  return primus;%0A
 %7D%0A%0Af
@@ -643,16 +643,22 @@
 tPrimus(
+PORT++
 );%0Aprimu
@@ -672,16 +672,111 @@
 tPrimus(
+PORT++);%0A%0Aprimus0.on('connection', cb(onConnection));%0Aprimus1.on('connection', cb(onConnection)
 );%0A%0Avar 

Refactor simple-test.js to use helpers