Example #1
0
function validateOpts (obj) {
  assert(isObject(obj), '"obj" should be an object')
  var self = this
  forEach(obj, function (val, key) {
    self.rvOpt(key, val)
  })
  return this
}
Example #2
0
      self.readyState = 'closed'
    }
  }
}
// Inherit ffrom EventEmitter
util.inherits(MockSocket, EventEmitter)
/**
 * socket methods to proxy to methods on primus
 */
var primusMethods = {
  'destroy': 'destroy',
  'write': 'write'
}
forEach(primusMethods, function (method) {
  MockSocket.prototype[method] = function () {
    var primus = this.primus
    return primus[method].apply(primus, arguments)
  }
})
/**
 * calling primus.end multiple times throws an error
 */
MockSocket.prototype.end = function () {
  var primus = this.primus
  try {
    return primus.end.apply(primus, arguments)
  } catch (err) {}
}
/**
 * connect mock is a noop that returns this, bc primus is already connected
 * TODO: may need some work, when disconnect and reconnect
 */