Skip to content

Instantly share code, notes, and snippets.

@ferclaverino
Created July 8, 2013 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ferclaverino/5948944 to your computer and use it in GitHub Desktop.
Save ferclaverino/5948944 to your computer and use it in GitHub Desktop.
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