Skip to content

Instantly share code, notes, and snippets.

@fivetanley
Created August 29, 2012 23:49
Show Gist options
  • Save fivetanley/3520558 to your computer and use it in GitHub Desktop.
Save fivetanley/3520558 to your computer and use it in GitHub Desktop.
The worst dependency mock/stub api of all time
ChatController = module.isolate(__dirname + '/../../lib/controllers/chat_controller' )
validator = ChatController.dependencies.find( /validator\S+index\.js/ )
describe 'ChatController', ->
sockets =
foo: {}
baz: 'foo'
bar: 'baz'
on: sinon.stub()
for own key,socket of sockets
socket.emit = sinon.stub() unless key is 'on'
chatController = new ChatController( sockets )
describe 'when a client sends a message', ->
beforeEach ->
ChatController::handleMessage.call(
{ sockets: sockets }
, 'hello'
, sockets.foo
)
it 'sanitizes that message for xss', ->
expect( validator.sanitize ).to.have.been.calledWith( 'hello' )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment