Created
July 8, 2013 13:52
-
-
Save ferclaverino/5948944 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('a listener', function(){ | |
describe('without nothing', function(){ | |
it('does nothing', function(){ | |
var userRepo = new UserRepo([]); | |
var listener = new listenerModule.Listener(userRepo); | |
listener.start(); | |
}); | |
}); | |
describe('with 1 user', function() { | |
var listener, userRepo, stream, twittRepo, blackListRepo; | |
beforeEach(function() { | |
userRepo = new UserRepo([1]); | |
stream = new Stream(); | |
twittRepo = new TwittRepo(); | |
blackListRepo = new BlackListRepo(function (text){ return false; }); | |
listener = new listenerModule.Listener(userRepo, twittRepo, blackListRepo, stream); | |
}); | |
it('starts to listen', function(){ | |
listener.start(); | |
stream.params.should.eql({ 'follow': '1' }); | |
}); | |
it('listen a twitt', function() { | |
listener.start(); | |
stream.callback({ id_str : '1'}); | |
twittRepo.twitt.should.eql({ id_str : '1'}); | |
}); | |
it('listen a black list twitt', function() { | |
blackListRepo.isBlocked = function(text) { | |
return (text == '1'); | |
}; | |
listener.start(); | |
stream.callback({ text : '1'}); | |
should.not.exist(twittRepo.twitt); | |
}); | |
}); | |
}); | |
var should = require('should'); | |
var listenerModule = require('../listener'); | |
var UserRepo = function(unMutedUsers) { | |
this.getUnMutedUsers = function(callback) { | |
callback(unMutedUsers); | |
}; | |
}; | |
var Stream = function() { | |
this.filter = function(params, callback) { | |
this.params = params; | |
this.callback = callback; | |
}; | |
}; | |
var TwittRepo = function() { | |
this.save = function(twitt) { | |
this.twitt = twitt; | |
}; | |
}; | |
var BlackListRepo = function(isBlocked) { | |
this.isBlocked = function(text) { | |
isBlocked(text); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment