return pretend.robot.respond.should.have.calledOnce;
return pretend.robot.respond.getCall(0).should.have.calledWithMatch(sinon.match.regexp, sinon.match.func);
return pretend.robot.hear.should.have.calledTwice;
return pretend.robot.hear.getCall(1).should.have.calledWithMatch(sinon.match.regexp, sinon.match.func);
return pretend.robot.listeners.length.should.equal(2);
return pretend.responses.listen.length.should.equal(1);
return this.cb.should.have.calledWithMatch(sinon.match(matchRes));
return pretend.responses.listen.length.should.equal(1);
return this.cb.should.have.calledWithMatch(sinon.match(matchRes));
return co(function*() {
var cb;
pretend.start({
alias: 'buddy'
});
cb = sinon.spy(pretend.robot.listeners[0], 'callback');
yield pretend.user('jimbo').send('buddy which version');
return cb.should.have.calledWithMatch(sinon.match(matchRes));
});
return co(function*() {
yield pretend.user('jimbo').send('hubot which version are you on?');
return pretend.messages[1][1].should.match(/jimbo .*\d+.\d+.\d+/);
});
return co(function*() {
yield pretend.user('jimbo').send('Are any Hubots listening?');
yield pretend.user('jimbo').send('Is there a bot listening?');
return pretend.messages[1].should.eql(pretend.messages[3]);
});
return this.base.robot.should.eql(pretend.robot);
return this.base.configure.should.have.calledWith({
test: 'testing'
});
return this.base.key.should.equal('basey-mcbase');
return Base.prototype.error.should.have.calledOnce;
return Base.prototype.error.should.have.calledOnce;
var base;
base = new Base('test', pretend.robot);
base.id = 'test111';
base.log.debug('This is some debug');
base.log.info('This is info');
base.log.warning('This is a warning');
base.log.error('This is an error');
return pretend.logs.slice(-4).should.eql([['debug', 'This is some debug (id: test111)'], ['info', 'This is info (id: test111)'], ['warning', 'This is a warning (id: test111)'], ['error', 'This is an error (id: test111)']]);
var base;
base = new Base('test', pretend.robot, 'super-test');
base.id = 'test111';
base.log.debug('This is some debug');
return pretend.logs.slice(-1).should.eql([['debug', 'This is some debug (id: test111, key: super-test)']]);
return this.errLog[0].should.equal('error');
return pretend.robot.emit.should.have.calledWith('error', this.err);
return this.base.error.should["throw"];
return this.errLog[1].should.match(new RegExp(this.base.id + ".*something broke"));
return pretend.robot.emit.should.have.calledWith('error');
return this.base.error.should["throw"];
return Base.prototype.error.should.have.calledWith('Throw me an error');
return this.module.error.should["throw"];
var base;
base = new Base('module', pretend.robot);
base.configure({
foo: true
});
return base.config.foo.should.be["true"];
var base;
base = new Base('module', pretend.robot, {
setting: true
});
base.configure({
setting: false
});
return base.config.setting.should.be["false"];
var base;
base = new Base('module', pretend.robot);
try {
base.configure('not an object');
} catch (error) {}
return base.configure.should["throw"];
this.base = new Base('module', pretend.robot);
this.base.defaults({
setting: true
});
return this.base.config.should.eql({
setting: true
});
this.base = new Base('module', pretend.robot, {
setting: true
});
this.base.defaults({
setting: false
});
return this.base.config.should.eql({
setting: true
});
this.base = new Base('module', pretend.robot);
this.eventSpy = sinon.spy();
pretend.robot.on('mockEvent', this.eventSpy);
this.base.emit('mockEvent', {
foo: 'bar'
});
return this.eventSpy.should.have.calledWith(this.base, {
foo: 'bar'
});
this.base = new Base('module', pretend.robot);
this.mockEvent = sinon.spy();
this.base.on('mockEvent', this.mockEvent);
pretend.robot.emit('mockEvent', this.base, {
foo: 'bar'
});
return this.mockEvent.should.have.calledWith({
foo: 'bar'
});
var path;
sinon.spy(Path.prototype, 'addBranch');
path = new Path(pretend.robot, [[/left/, 'Ok, going left!'], [/right/, 'Ok, going right!']]);
path.addBranch.args.should.eql([[/left/, 'Ok, going left!'], [/right/, 'Ok, going right!']]);
return Path.prototype.addBranch.restore();
var path;
path = new Path(pretend.robot, [[/left/, 'Ok, going left!'], [/right/, 'Ok, going right!']]);
return path.closed.should.be["false"];
var path;
sinon.spy(Path.prototype, 'addBranch');
path = new Path(pretend.robot, [/ok/, 'OK, ok!']);
path.addBranch.args.should.eql([[/ok/, 'OK, ok!']]);
return Path.prototype.addBranch.restore();
var path;
path = new Path(pretend.robot, [/ok/, 'OK, ok!']);
return path.closed.should.be["false"];
var path;
sinon.spy(Path.prototype, 'addBranch');
path = new Path(pretend.robot);
return Path.prototype.addBranch.restore();
var path;
path = new Path(pretend.robot);
return path.closed.should.be["true"];
try {
this.path = new Path(pretend.robot, 'breakme.jpg');
} catch (error) {}
return Path.constructor.should["throw"];
var path;
path = new Path(pretend.robot);
path.addBranch(/.*/, 'foo', function() {});
return path.branches[0].should.be.an('object');
var path;
path = new Path(pretend.robot);
path.addBranch(/.*/, 'foo', function() {});
return path.branches[0].regex.should.be["instanceof"](RegExp);
var path;
path = new Path(pretend.robot);
path.addBranch('/.*/ig', 'foo', function() {});
return path.branches[0].regex.should.be["instanceof"](RegExp);
var callback, path;
path = new Path(pretend.robot);
callback = function() {};
sinon.stub(path, 'getHandler');
path.addBranch(/.*/, 'foo', callback);
return path.getHandler.should.have.calledWithExactly('foo', callback);
var path;
path = new Path(pretend.robot);
sinon.stub(path, 'getHandler');
path.addBranch(/.*/, ['foo', 'bar']);
return path.getHandler.should.have.calledWithExactly(['foo', 'bar'], void 0);
var callback, path;
path = new Path(pretend.robot);
callback = function() {};
sinon.stub(path, 'getHandler');
path.addBranch(/.*/, callback);
return path.getHandler.should.have.calledWithExactly(void 0, callback);
var lasthandler, path;
path = new Path(pretend.robot);
sinon.spy(path, 'getHandler');
path.addBranch(/.*/, 'foo', function() {});
lasthandler = path.getHandler.returnValues[0];
return path.branches[0].handler.should.eql(lasthandler);
var path;
path = new Path(pretend.robot);
path.addBranch(/.*/, 'foo', function() {});
return path.closed.should.be["false"];
var path;
path = new Path(pretend.robot);
try {
path.addBranch('derp');
} catch (error) {}
return path.addBranch.should["throw"];
var path;
path = new Path(pretend.robot);
try {
path.addBranch(/.*/);
} catch (error) {}
return path.addBranch.should["throw"];
var path;
path = new Path(pretend.robot);
try {
path.addBranch(/.*/, function() {});
} catch (error) {}
return path.addBranch.should["throw"];
var path;
path = new Path(pretend.robot);
try {
path.addBranch(/.*/, 'foo', 'bar');
} catch (error) {}
return path.addBranch.should["throw"];
var callback, handler, path;
path = new Path(pretend.robot);
callback = sinon.spy();
handler = path.getHandler(['foo', 'bar'], callback);
return handler.should.be.a('function');
var callback, handler, mockRes, path;
path = new Path(pretend.robot);
callback = sinon.spy();
handler = path.getHandler(['foo', 'bar'], callback);
mockRes = {
reply: sinon.spy()
};
handler(mockRes);
return callback.should.have.calledWithExactly(mockRes);
var handler, mockRes, path;
path = new Path(pretend.robot);
handler = path.getHandler(['foo', 'bar']);
mockRes = {
reply: sinon.spy(),
dialogue: {
send: sinon.spy()
}
};
handler(mockRes);
return mockRes.dialogue.send.should.have.calledWith('foo', 'bar');
var handler, mockRes, path;
path = new Path(pretend.robot);
handler = path.getHandler(['foo', 'bar']);
mockRes = {
reply: sinon.spy()
};
handler(mockRes);
return mockRes.reply.should.have.calledWith('foo', 'bar');
return co(function*() {
var handler, handlerSpy, mockRes, path;
path = new Path(pretend.robot);
handler = path.getHandler(['foo'], function() {
return {
bar: 'baz'
};
});
mockRes = {
reply: sinon.spy()
};
handlerSpy = sinon.spy(handler);
yield handler(mockRes);
return handlerSpy.returned(sinon.match(resMatch));
});
return co(function*() {
var handler, handlerSpy, mockRes, path;
path = new Path(pretend.robot);
handler = path.getHandler(['foo'], function() {
return {
bar: 'baz'
};
});
mockRes = {
reply: sinon.spy()
};
handlerSpy = sinon.spy(handler);
yield handler(mockRes);
return handlerSpy.returned(sinon.match({
bar: 'baz'
}));
});
return co((function(_this) {
return function*() {
var expectedMatch;
yield pretend.user('sam').send('door 1');
yield _this.path.match(pretend.lastListen());
expectedMatch = 'door 1'.match(_this.path.branches[0].regex);
return pretend.lastListen().match.should.eql(expectedMatch);
};
})(this));
return co((function(_this) {
return function*() {
yield pretend.user('sam').send('door 2');
yield _this.path.match(pretend.lastListen());
return _this.path.closed.should.be["true"];
};
})(this));
return co((function(_this) {
return function*() {
var res;
_this.path.branches[1].handler = sinon.stub();
yield pretend.user('sam').send('door 2');
res = pretend.lastListen();
yield _this.path.match(res);
return _this.path.branches[1].handler.should.have.calledWithExactly(res);
};
})(this));
return co((function(_this) {
return function*() {
yield pretend.user('sam').send('door 2');
yield _this.path.match(pretend.lastListen());
return _this.match.should.have.calledWith(sinon.match(resMatch));
};
})(this));
return co((function(_this) {
return function*() {
var expectedMatch;
yield pretend.user('sam').send('door 1 and door 2');
yield _this.path.match(pretend.lastListen());
expectedMatch = 'door 1 and door 2'.match(_this.path.branches[0].regex);
return pretend.lastListen().match.should.eql(expectedMatch);
};
})(this));
return co((function(_this) {
return function*() {
var result;
yield pretend.user('sam').send('door 1 and door 2');
result = (yield _this.path.match(pretend.lastListen()));
return result.should.have.property('winner', false);
};
})(this));
return co((function(_this) {
return function*() {
yield pretend.user('sam').send('door 1 and door 2');
yield _this.path.match(pretend.lastListen());
return _this.path.closed.should.be["true"];
};
})(this));
return co((function(_this) {
return function*() {
var result;
yield pretend.user('sam').send('door X');
result = (yield _this.path.match(pretend.lastListen()));
return chai.expect(result).to.be.undefined;
};
})(this));
return co((function(_this) {
return function*() {
yield pretend.user('sam').send('door X');
yield _this.path.match(pretend.lastListen());
return chai.expect(pretend.lastListen().match).to.be["null"];
};
})(this));
return co((function(_this) {
return function*() {
yield pretend.user('sam').send('door X');
yield _this.path.match(pretend.lastListen());
return _this.path.closed.should.be["false"];
};
})(this));
return co((function(_this) {
return function*() {
yield pretend.user('sam').send('door X');
yield _this.path.match(pretend.lastListen());
return _this.mismatch.should.have.calledWith(sinon.match(resMatch));
};
})(this));
return co((function(_this) {
return function*() {
var result;
_this.path.configure({
catchMessage: 'no, wrong door'
});
yield pretend.user('sam').send('door X');
result = (yield _this.path.match(pretend.lastListen()));
return result.strings.should.eql(['no, wrong door']);
};
})(this));
return co((function(_this) {
return function*() {
_this.path.configure({
catchMessage: 'no, wrong door'
});
yield pretend.user('sam').send('door X');
yield _this.path.match(pretend.lastListen());
return _this["catch"].should.have.calledWith(sinon.match(resMatch));
};
})(this));
return co((function(_this) {
return function*() {
var result;
_this.path.configure({
catchCallback: function() {
return {
other: 'door fail'
};
}
});
yield pretend.user('sam').send('door X');
result = (yield _this.path.match(pretend.lastListen()));
return result.should.have.property('other', 'door fail');
};
})(this));
return co((function(_this) {
return function*() {
_this.path.configure({
catchMessage: 'no, wrong door'
});
yield pretend.user('sam').send('door X');
yield _this.path.match(pretend.lastListen());
return _this["catch"].should.have.calledWith(sinon.match(resMatch));
};
})(this));
var dialogue;
dialogue = new Dialogue(testRes);
return should.equal(dialogue.path, null);
var dialogue;
dialogue = new Dialogue(testRes);
return dialogue.ended.should.be["false"];
var dialogue;
process.env.DIALOGUE_TIMEOUT = 500;
dialogue = new Dialogue(testRes);
dialogue.config.timeout.should.equal(500);
return delete process.env.DIALOGUE_TIMEOUT;
var dialogue, end;
dialogue = new Dialogue(testRes);
end = sinon.spy();
dialogue.on('end', end);
dialogue.end();
return end.should.have.calledWith(testRes);
var dialogue;
dialogue = new Dialogue(testRes);
dialogue.end();
return dialogue.ended.should.be["true"];
var dialogue;
dialogue = new Dialogue(testRes);
return dialogue.end().should.be["true"];
var dialogue, end;
dialogue = new Dialogue(testRes);
end = sinon.spy();
dialogue.on('end', end);
dialogue.receive(testRes);
dialogue.end();
return end.should.have.calledWith(sinon.match(matchRes));
var dialogue;
dialogue = new Dialogue(testRes, {
timeout: 10
});
dialogue.onTimeout = sinon.spy();
dialogue.startTimeout();
dialogue.end();
clock.tick(20);
dialogue.clearTimeout.should.have.calledOnce;
return dialogue.onTimeout.should.not.have.called;
var dialogue;
dialogue = new Dialogue(testRes);
dialogue.end();
return dialogue.end().should.be["false"];
var dialogue, end;
dialogue = new Dialogue(testRes);
end = sinon.spy();
dialogue.on('end', end);
dialogue.end();
dialogue.end();
return end.should.have.calledOnce;
return co(function*() {
var dialogue;
dialogue = new Dialogue(testRes);
yield dialogue.send('test');
return pretend.messages.pop().should.eql(['testing', 'hubot', 'test']);
});
return co(function*() {
var dialogue, sendSpy;
dialogue = new Dialogue(testRes);
sendSpy = sinon.spy();
dialogue.on('send', sendSpy);
yield dialogue.send('test');
return sendSpy.should.have.calledWith(sinon.match(matchRes));
});
return co(function*() {
var dialogue, sendSpy;
dialogue = new Dialogue(testRes);
sendSpy = sinon.spy();
dialogue.on('send', sendSpy);
yield dialogue.send('test');
return sendSpy.lastCall.args[1].should.eql({
strings: ['test'],
method: 'send',
received: testRes
});
});
return co(function*() {
var dialogue;
dialogue = new Dialogue(testRes, {
sendReplies: true
});
yield dialogue.send('test');
return pretend.messages.pop().should.eql(['testing', 'hubot', '@tester test']);
});
function* () {
var dialogue, nextMessage;
nextMessage = pretend.observer.next();
dialogue = new Dialogue(testRes, {
timeout: 10
});
dialogue.startTimeout();
clock.tick(20);
yield nextMessage;
return pretend.messages.pop().should.eql(['testing', 'hubot', dialogue.config.timeoutText]);
}
var dialogue, timeout;
dialogue = new Dialogue(testRes, {
timeout: 10
});
timeout = sinon.spy();
dialogue.onTimeout(timeout);
dialogue.startTimeout();
clock.tick(20);
return dialogue.onTimeout.should.have.calledOnce;
var dialogue, timeout;
dialogue = new Dialogue(testRes, {
timeout: 10
});
timeout = sinon.spy();
dialogue.onTimeout(timeout);
dialogue.startTimeout();
clock.tick(20);
return dialogue.send.should.not.have.called;
var dialogue;
dialogue = new Dialogue(testRes, {
timeout: 10
});
dialogue.onTimeout = sinon.spy();
dialogue.startTimeout();
clock.tick(20);
return dialogue.onTimeout.should.have.calledOnce;
var dialogue, override;
dialogue = new Dialogue(testRes, {
timeout: 10
});
dialogue.onTimeout(function() {
throw new Error("Test exception");
});
override = sinon.spy(dialogue, 'onTimeout');
dialogue.startTimeout();
try {
clock.tick(20);
} catch (error) {}
return override.should["throw"];
var dialogue, timeoutEvent, timeoutMethod;
dialogue = new Dialogue(testRes, {
timeout: 10
});
timeoutMethod = sinon.spy();
dialogue.onTimeout(timeoutMethod);
timeoutEvent = sinon.spy();
dialogue.on('timeout', timeoutEvent);
dialogue.startTimeout();
clock.tick(20);
return timeoutEvent.should.have.calledOnce;
var dialogue, end, timeoutMethod;
dialogue = new Dialogue(testRes, {
timeout: 10
});
end = sinon.spy();
dialogue.on('end', end);
timeoutMethod = sinon.spy();
dialogue.onTimeout(timeoutMethod);
dialogue.startTimeout();
clock.tick(20);
return end.should.have.calledOnce;
var dialogue;
dialogue = new Dialogue(testRes, {
timeout: 10
});
dialogue.onTimeout = sinon.spy();
dialogue.startTimeout();
dialogue.startTimeout();
clock.tick(20);
dialogue.clearTimeout.should.have.calledOnce;
return dialogue.onTimeout.should.have.calledOnce;
var dialogue;
dialogue = new Dialogue(testRes, {
timeout: 10
});
dialogue.onTimeout = sinon.spy();
dialogue.startTimeout();
clock.tick(20);
return dialogue.onTimeout.should.have.calledOnce;
var dialogue;
dialogue = new Dialogue(testRes, {
timeout: 10,
timeoutText: null
});
dialogue.startTimeout();
clock.tick(20);
return dialogue.end.should.have.calledOnce;
return co(function*() {
var dialogue, path;
dialogue = new Dialogue(testRes);
path = (yield dialogue.addPath('Turn left or right?', [[/left/, 'Ok, going left!'], [/right/, 'Ok, going right!']], 'which-way'));
return path.should.be["instanceof"](dialogue.Path);
});
return co(function*() {
var dialogue, path;
dialogue = new Dialogue(testRes);
path = (yield dialogue.addPath('Turn left or right?', [[/left/, 'Ok, going left!'], [/right/, 'Ok, going right!']], 'which-way'));
return path.key.should.eql('which-way');
});
return co(function*() {
var dialogue, path;
dialogue = new Dialogue(testRes);
path = (yield dialogue.addPath('Turn left or right?', [[/left/, 'Ok, going left!'], [/right/, 'Ok, going right!']], 'which-way'));
return dialogue.send.should.have.calledWith('Turn left or right?');
});
return co(function*() {
var dialogue, path;
dialogue = new Dialogue(testRes);
path = (yield dialogue.addPath('Turn left or right?', [[/left/, 'Ok, going left!'], [/right/, 'Ok, going right!']], 'which-way'));
return dialogue.startTimeout.should.have.calledOnce;
});
return co(function*() {
var dialogue, path;
dialogue = new Dialogue(testRes);
path = (yield dialogue.addPath([[/1/, 'You get cake!'], [/2/, 'You get cake!']]));
return path.should.be["instanceof"](dialogue.Path);
});
return co(function*() {
var dialogue, path;
dialogue = new Dialogue(testRes);
path = (yield dialogue.addPath([[/1/, 'You get cake!'], [/2/, 'You get cake!']]));
return dialogue.send.should.not.have.called;
});
return co(function*() {
var dialogue, path;
dialogue = new Dialogue(testRes);
path = (yield dialogue.addPath([[/1/, 'You get cake!'], [/2/, 'You get cake!']]));
return dialogue.startTimeout.should.have.calledOnce;
});
return co(function*() {
var dialogue, path;
dialogue = new Dialogue(testRes);
path = (yield dialogue.addPath("Don't say nothing."));
return path.should.be["instanceof"](dialogue.Path);
});
return co(function*() {
var dialogue, path;
dialogue = new Dialogue(testRes);
path = (yield dialogue.addPath("Don't say nothing."));
return dialogue.startTimeout.should.not.have.called;
});
var dialogue;
dialogue = new Dialogue(testRes);
dialogue.path = {
addBranch: sinon.spy()
};
dialogue.addBranch(/foo/, 'foo');
return dialogue.path.addBranch.should.have.calledWith(/foo/, 'foo');
var dialogue;
dialogue = new Dialogue(testRes);
dialogue.path = {
addBranch: sinon.spy()
};
dialogue.addBranch(/foo/, 'foo');
return dialogue.startTimeout.should.have.calledOnce;
var dialogue;
dialogue = new Dialogue(testRes);
dialogue.addBranch(/foo/, 'foo');
return dialogue.path.should.be["instanceof"](dialogue.Path);
var dialogue;
dialogue = new Dialogue(testRes);
sinon.spy(dialogue.Path.prototype, 'addBranch');
dialogue.addBranch(/foo/, 'foo');
return dialogue.path.addBranch.should.have.calledWith(/foo/, 'foo');
var dialogue;
dialogue = new Dialogue(testRes);
dialogue.addBranch(/foo/, 'foo');
return dialogue.startTimeout.should.have.calledOnce;
return co(function*() {
var dialogue;
dialogue = new Dialogue(testRes);
dialogue.addBranch(/.*/, function() {});
yield dialogue.receive(pretend.response('tester', 'new test'));
return dialogue.res.message.text.should.equal('new test');
});
return co(function*() {
var dialogue, newTestRes;
dialogue = new Dialogue(testRes);
dialogue.addBranch(/.*/, function() {});
newTestRes = pretend.response('tester', 'new test');
yield dialogue.receive(newTestRes);
return newTestRes.dialogue.should.eql(dialogue);
});
return co(function*() {
var dialogue, result;
dialogue = new Dialogue(testRes);
dialogue.end();
result = (yield dialogue.receive(testRes));
return result.should.be["false"];
});
return co(function*() {
var callback, dialogue;
dialogue = new Dialogue(testRes);
callback = sinon.spy();
dialogue.addBranch(/.*/, callback);
dialogue.end();
yield dialogue.receive(testRes);
return callback.should.not.have.called;
});
return co(function*() {
var dialogue;
dialogue = new Dialogue(testRes, {
timeout: 10
});
dialogue.addBranch(/foo/, function() {
return null;
});
dialogue.onTimeout = sinon.spy();
yield dialogue.receive(pretend.response('tester', 'foo'));
clock.tick(20);
dialogue.clearTimeout.should.have.calledOnce;
return dialogue.onTimeout.should.not.have.called;
});
return co(function*() {
var dialogue;
dialogue = new Dialogue(testRes);
dialogue.addBranch(/foo/, function() {
return null;
});
yield dialogue.receive(pretend.response('tester', 'foo'));
return dialogue.end.should.have.calledOnce;
});
return co(function*() {
var callback, dialogue;
dialogue = new Dialogue(testRes);
callback = sinon.spy();
dialogue.addBranch(/foo/, 'bar', callback);
yield dialogue.receive(pretend.response('tester', 'foo'));
return callback.should.have.calledOnce;
});
return co(function*() {
var callback, dialogue;
dialogue = new Dialogue(testRes);
callback = sinon.spy();
dialogue.addBranch(/foo/, 'bar', callback);
yield dialogue.receive(pretend.response('tester', 'foo'));
return dialogue.send.should.have.calledWith('bar');
});
return co(function*() {
var callback, dialogue;
dialogue = new Dialogue(testRes);
callback = sinon.spy();
dialogue.addBranch(/foo/, callback);
dialogue.addBranch(/bar/, callback);
yield dialogue.receive(pretend.response('tester', 'foo'));
yield dialogue.receive(pretend.response('tester', 'bar'));
return callback.should.have.calledOnce;
});
return co(function*() {
var dialogue;
dialogue = new Dialogue(testRes);
dialogue.addBranch(/foo/, function() {});
dialogue.path.config.catchMessage = 'huh?';
yield dialogue.receive(pretend.response('tester', '?'));
return dialogue.send.should.have.calledWith('huh?');
});
return co(function*() {
var dialogue;
dialogue = new Dialogue(testRes);
dialogue.addBranch(/foo/, function() {});
dialogue.path.config.catchMessage = 'huh?';
yield dialogue.receive(pretend.response('tester', '?'));
return dialogue.clearTimeout.should.not.have.called;
});
return co(function*() {
var dialogue;
dialogue = new Dialogue(testRes);
dialogue.addBranch(/foo/, function() {});
dialogue.path.config.catchMessage = 'huh?';
yield dialogue.receive(pretend.response('tester', '?'));
return dialogue.end.should.not.have.called;
});
return co(function*() {
var dialogue;
dialogue = new Dialogue(testRes);
dialogue.addBranch(/foo/, function() {});
yield dialogue.receive(pretend.response('tester', '?'));
return dialogue.clearTimeout.should.not.have.called;
});
return co(function*() {
var dialogue;
dialogue = new Dialogue(testRes);
dialogue.addBranch(/foo/, function() {});
yield dialogue.receive(pretend.response('tester', '?'));
return dialogue.end.should.not.have.called;
});
return co(function*() {
var dialogue;
dialogue = new Dialogue(testRes);
dialogue.addBranch(/more/, function() {
dialogue.addBranch(/1/, 'got 1');
return dialogue.addBranch(/2/, 'got 2');
});
yield dialogue.receive(pretend.response('tester', 'more'));
return _.map(dialogue.path.branches, function(branch) {
return branch.regex;
}).should.eql([/more/, /1/, /2/]);
});
return co(function*() {
var dialogue;
dialogue = new Dialogue(testRes);
dialogue.addBranch(/more/, function() {
dialogue.addBranch(/1/, 'got 1');
return dialogue.addBranch(/2/, 'got 2');
});
yield dialogue.receive(pretend.response('tester', 'more'));
return dialogue.end.should.not.have.called;
});
return co(function*() {
var dialogue;
dialogue = new Dialogue(testRes);
dialogue.addBranch(/new/, function() {
return dialogue.addPath([[/1/, 'got 1'], [/2/, 'got 2']]);
});
yield dialogue.receive(pretend.response('tester', 'new'));
return _.map(dialogue.path.branches, function(branch) {
return branch.regex;
}).should.eql([/1/, /2/]);
});
return co(function*() {
var dialogue;
dialogue = new Dialogue(testRes);
dialogue.addBranch(/new/, function() {
return dialogue.addPath([[/1/, 'got 1'], [/2/, 'got 2']]);
});
yield dialogue.receive(pretend.response('tester', 'new'));
return dialogue.end.should.not.have.called;
});
var scene;
scene = new Scene(pretend.robot);
return scene.config.scope.should.equal('user');
new Scene(pretend.robot);
return pretend.robot.receiveMiddleware.should.have.calledOnce;
var scene;
scene = new Scene(pretend.robot, {
sendReplies: true
});
return scene.config.sendReplies.should.be["true"];
var scene;
scene = new Scene(pretend.robot, {
scope: 'room'
});
return scene.config.scope.should.equal('room');
var scene;
scene = new Scene(pretend.robot, {
scope: 'room'
});
return scene.config.sendReplies.should.be["true"];
try {
new Scene(pretend.robot, {
scope: 'monkey'
});
} catch (error1) {}
return Scene.prototype.constructor.should["throw"];
var scene;
scene = new Scene(pretend.robot);
scene.listen('hear', '/test/i', function() {
return null;
});
return pretend.robot.listeners.pop().regex.should.eql(/test/i);
var scene;
scene = new Scene(pretend.robot);
scene.listen('hear', /test/, function() {
return null;
});
return pretend.robot.hear.should.have.calledWithMatch(sinon.match.regexp, sinon.match({
id: scene.id
}), sinon.match.func);
return co(function*() {
var callback, scene;
scene = new Scene(pretend.robot);
callback = sinon.spy();
scene.listen('hear', /test/, callback);
yield pretend.user('tester').send('test');
return callback.should.have.calledOnce;
});
var callback, scene;
scene = new Scene(pretend.robot);
callback = sinon.spy();
scene.listen('hear', /test/, callback);
return pretend.user('tester').send('test').then(function() {
return callback.should.have.calledWith(matchRes);
});
var callback, id, scene;
scene = new Scene(pretend.robot);
callback = sinon.spy();
id = scene.listen('respond', /test/, callback);
return pretend.user('tester').send('hubot test').then(function() {
return pretend.robot.respond.should.have.calledWithMatch(sinon.match.regexp, sinon.match({
id: scene.id
}), sinon.match.func);
});
return co(function*() {
var callback, id, scene;
scene = new Scene(pretend.robot);
callback = sinon.spy();
id = scene.listen('respond', /test/, callback);
yield pretend.user('tester').send('hubot test');
return callback.should.have.calledOnce;
});
return co(function*() {
var callback, id, scene;
scene = new Scene(pretend.robot);
callback = sinon.spy();
id = scene.listen('respond', /test/, callback);
yield pretend.user('tester').send('hubot test');
return callback.should.have.calledWith(matchRes);
});
var scene;
scene = new Scene(pretend.robot);
try {
scene.listen('smell', /test/, function() {
return null;
});
} catch (error1) {}
return scene.listen.should["throw"];
var scene;
scene = new Scene(pretend.robot);
try {
scene.listen('hear', 'test', function() {
return null;
});
} catch (error1) {}
return scene.listen.should["throw"];
var scene;
scene = new Scene(pretend.robot);
try {
scene.listen('hear', /test/, {
not: 'a function '
});
} catch (error1) {}
return scene.listen.should["throw"];
var expectedArgs, ref, scene;
scene = new Scene(pretend.robot);
scene.hear(/test/, function() {
return null;
});
expectedArgs = ['hear', /test/, sinon.match.func];
return (ref = scene.listen.getCall(0).should.have).calledWith.apply(ref, expectedArgs);
var expectedArgs, ref, scene;
scene = new Scene(pretend.robot);
scene.respond(/test/, function() {
return null;
});
expectedArgs = ['respond', /test/, sinon.match.func];
return (ref = scene.listen.getCall(0).should.have).calledWith.apply(ref, expectedArgs);
var scene;
scene = new Scene(pretend.robot, {
scope: 'user'
});
return scene.whoSpeaks(pretend.lastReceive()).should.equal('user_111');
var scene;
scene = new Scene(pretend.robot, {
scope: 'room'
});
return scene.whoSpeaks(pretend.lastReceive()).should.equal('testing');
var scene;
scene = new Scene(pretend.robot, {
scope: 'direct'
});
return scene.whoSpeaks(pretend.lastReceive()).should.equal('user_111_testing');
var piece, scene;
piece = function(context, next, done) {
return null;
};
scene = new Scene(pretend.robot);
scene.registerMiddleware(piece);
return scene.enterMiddleware.stack[0].should.eql(piece);
var piece, scene;
piece = function(notEnoughArgs) {
return null;
};
scene = new Scene(pretend.robot);
try {
scene.registerMiddleware(piece);
} catch (error1) {}
scene.registerMiddleware.should["throw"];
return scene.enterMiddleware.stack.length.should.equal(0);
var promise, scene;
scene = new Scene(pretend.robot);
promise = scene.enter(pretend.lastReceive());
return promise.then.should.be.a('function');
return co(function*() {
var scene;
scene = new Scene(pretend.robot);
yield scene.enter(pretend.lastReceive());
return scene.processEnter.should.have.calledOnce;
});
return co(function*() {
var callback, result, scene;
scene = new Scene(pretend.robot);
callback = sinon.spy();
result = (yield scene.enter(pretend.lastReceive(), callback));
return callback.should.have.calledOnce;
});
return co(function*() {
var scene;
scene = new Scene(pretend.robot);
yield scene.enter(pretend.lastReceive());
yield setImmediatePromise();
return scene.exit.should.have.calledWith(pretend.lastReceive(), 'no path');
});
return co(function*() {
var context, scene;
scene = new Scene(pretend.robot);
context = (yield scene.enter(pretend.lastReceive()));
context.dialogue.addBranch(matchAny, '');
yield setImmediatePromise();
return scene.exit.should.not.have.called;
});
var callback, keys, scene;
scene = new Scene(pretend.robot);
keys = ['response', 'participants', 'options', 'arguments', 'dialogue'];
callback = function(result) {
var ref;
(ref = result.should.have.all).keys.apply(ref, keys);
return done();
};
scene.enter(pretend.lastReceive(), callback);
return co(function*() {
var keys, ref, result, scene;
scene = new Scene(pretend.robot);
keys = ['response', 'participants', 'options', 'arguments', 'dialogue'];
scene.registerMiddleware(function(context, next, done) {
return next();
});
result = (yield scene.enter(pretend.lastReceive()));
return (ref = result.should.have.all).keys.apply(ref, keys);
});
var callback, keys, scene;
scene = new Scene(pretend.robot);
keys = ['response', 'participants', 'options', 'arguments', 'dialogue'];
callback = function(result) {
var ref;
(ref = result.should.have.all).keys.apply(ref, keys);
return done();
};
scene.registerMiddleware(function(context, next, done) {
return next();
});
scene.enter(pretend.lastReceive(), callback);
var scene;
scene = new Scene(pretend.robot);
scene.registerMiddleware(function(context, next, done) {
return done();
});
return scene.enter(pretend.lastReceive()).then(function() {
throw new Error('promise should have caught');
})["catch"](function(err) {
err.should.be["instanceof"](Error);
return err.should.have.property('message', 'Middleware piece called done');
});
return co(function*() {
var error, scene;
scene = new Scene(pretend.robot);
scene.registerMiddleware(function(context, next, done) {
return done();
});
try {
yield scene.enter(pretend.lastReceive());
} catch (error1) {
error = error1;
}
return scene.processEnter.should.not.have.called;
});
return co(function*() {
var custom, scene;
scene = new Scene(pretend.robot);
custom = sinon.spy();
scene.registerMiddleware(function(context, next, done) {
return next(function() {
custom();
return done();
});
});
yield scene.enter(pretend.lastReceive());
return custom.should.have.calledOnce;
});
var scene;
scene = new Scene(pretend.robot);
scene.registerMiddleware(function(context, next, done) {
context.trace = ['A'];
return next();
});
scene.registerMiddleware(function(context, next, done) {
context.trace.push('B');
return next();
});
scene.registerMiddleware(function(context, next, done) {
context.trace.push('C');
return next();
});
scene.enter(pretend.lastReceive(), function(result) {
result.trace.should.eql(['A', 'B', 'C']);
return done();
});
return co(function*() {
var error, scene;
scene = new Scene(pretend.robot);
scene.registerMiddleware(function(context, next, done) {
return next();
});
scene.registerMiddleware(function(context, next, done) {
return done();
});
scene.registerMiddleware(function(context, next, done) {
return next();
});
try {
yield scene.enter(pretend.lastReceive());
} catch (error1) {
error = error1;
}
return scene.processEnter.should.not.have.called;
});
return co(function*() {
var scene;
scene = new Scene(pretend.robot, {
scope: 'user'
});
yield scene.enter(pretend.lastReceive());
return scene.engaged['user_111'].should.be["instanceof"](Dialogue);
});
return co(function*() {
var scene;
scene = new Scene(pretend.robot, {
scope: 'room'
});
yield scene.enter(pretend.lastReceive());
return scene.engaged['testing'].should.be["instanceof"](Dialogue);
});
return co(function*() {
var scene;
scene = new Scene(pretend.robot, {
scope: 'direct'
});
yield scene.enter(pretend.lastReceive());
return scene.engaged['user_111_testing'].should.be["instanceof"](Dialogue);
});
function* () {
var dialogue, scene;
scene = new Scene(pretend.robot);
dialogue = (yield scene.enter(pretend.lastReceive(), {
timeout: 100,
timeoutText: 'foo'
})).dialogue;
dialogue.config.timeout.should.equal(100);
return dialogue.config.timeoutText.should.equal('foo');
}
var res, scene;
scene = new Scene(pretend.robot);
res = pretend.lastReceive();
scene.enter(res, {
timeout: 10,
timeoutText: null
}).then(function(context) {
context.dialogue.on('end', function() {
scene.exit.should.have.calledWith(res, 'timeout');
return done();
});
context.dialogue.addBranch(matchAny, '');
return wait(20);
});
var res, scene;
scene = new Scene(pretend.robot);
res = pretend.lastReceive();
scene.enter(res, {
timeout: 10,
timeoutText: null
}).then(function(context) {
context.dialogue.on('end', function() {
scene.exit.should.have.calledWith(res, 'incomplete');
return done();
});
context.dialogue.addBranch(matchAny, '');
return wait(20);
});
return co(function*() {
var context, scene;
scene = new Scene(pretend.robot);
context = (yield scene.enter(pretend.lastReceive()));
context.dialogue.addBranch(matchAny, '');
yield pretend.user('tester').send('test');
yield pretend.user('tester').send('testing again');
return scene.exit.should.have.calledOnce;
});
return co(function*() {
var context, scene;
scene = new Scene(pretend.robot);
context = (yield scene.enter(pretend.lastReceive()));
context.dialogue.addBranch(matchAny, '');
yield pretend.user('tester').send('test');
yield pretend.user('tester').send('testing again');
return scene.exit.should.have.calledWith(context.dialogue.res, 'complete');
});
return co(function*() {
var resultA, resultB, scene;
scene = new Scene(pretend.robot);
resultA = (yield scene.enter(pretend.lastReceive()));
try {
resultB = (yield scene.enter(pretend.lastReceive()));
} catch (error1) {}
return scene.enter.should["throw"];
});
var scene;
scene = new Scene(pretend.robot);
scene.enter(pretend.lastReceive()).then(function() {
return scene.enter(pretend.lastReceive())["catch"](function(err) {
err.should.be["instanceof"](Error);
return done();
});
});
return co(function*() {
var dialogue, scene;
scene = new Scene(pretend.robot);
yield scene.enter(pretend.lastReceive());
scene.exit(pretend.lastReceive());
dialogue = (yield scene.enter(pretend.lastReceive())).dialogue;
return dialogue.should.be["instanceof"](Dialogue);
});
return co(function*() {
var dialogue, scene, timeout;
scene = new Scene(pretend.robot);
dialogue = (yield scene.enter(pretend.lastReceive(), {
timeout: 10
})).dialogue;
dialogue.addBranch(matchAny, '');
timeout = sinon.spy();
dialogue.onTimeout(timeout);
scene.exit(pretend.lastReceive(), 'testing exits');
yield wait(20);
return timeout.should.not.have.called;
});
return co(function*() {
var dialogue, scene;
scene = new Scene(pretend.robot);
dialogue = (yield scene.enter(pretend.lastReceive(), {
timeout: 10
})).dialogue;
dialogue.addBranch(matchAny, '');
scene.exit(pretend.lastReceive(), 'testing exits');
return should.not.exist(scene.engaged['user_111']);
});
return co(function*() {
var dialogue, scene;
scene = new Scene(pretend.robot);
dialogue = (yield scene.enter(pretend.lastReceive(), {
timeout: 10
})).dialogue;
dialogue.addBranch(matchAny, '');
scene.exit(pretend.lastReceive(), 'testing exits');
yield wait(20);
return scene.exit.returnValues.pop().should.be["true"];
});
return co(function*() {
var dialogue, scene;
scene = new Scene(pretend.robot);
scene.id = 'scene_111';
dialogue = (yield scene.enter(pretend.lastReceive(), {
timeout: 10
})).dialogue;
dialogue.addBranch(matchAny, '');
scene.exit(pretend.lastReceive(), 'testing exits');
yield wait(20);
return pretend.logs.pop().should.eql(['info', 'Disengaged user user_111 (testing exits) (id: scene_111)']);
});
return co(function*() {
var dialogue, scene;
scene = new Scene(pretend.robot);
dialogue = (yield scene.enter(pretend.lastReceive(), {
timeout: 10
})).dialogue;
dialogue.addBranch(matchAny, '');
dialogue.receive = sinon.spy();
scene.exit(pretend.lastReceive(), 'tester');
pretend.user('tester').send('test');
yield wait(20);
return dialogue.receive.should.not.have.called;
});
var scene;
scene = new Scene(pretend.robot);
scene.enter(pretend.lastReceive(), {
timeout: 10
}).then(function(context) {
context.dialogue.on('end', function() {
scene.exit.should.have.calledTwice;
return done();
});
context.dialogue.addBranch(matchAny, '');
return wait(20);
});
var scene;
scene = new Scene(pretend.robot);
scene.enter(pretend.lastReceive(), {
timeout: 10
}).then(function(context) {
context.dialogue.on('end', function() {
scene.exit.getCall(0).should.have.returned(true);
return done();
});
context.dialogue.addBranch(matchAny, '');
return wait(20);
});
var scene;
scene = new Scene(pretend.robot);
scene.enter(pretend.lastReceive(), {
timeout: 10
}).then(function(context) {
context.dialogue.on('end', function() {
scene.exit.getCall(1).should.have.returned(false);
return done();
});
context.dialogue.addBranch(matchAny, '');
return wait(20);
});
var scene;
scene = new Scene(pretend.robot);
scene.exit(pretend.lastReceive(), 'testing exits');
return scene.exit.returnValues.pop().should.be["false"];
return co(function*() {
var A, B, scene;
scene = new Scene(pretend.robot);
A = (yield scene.enter(pretend.response('A', 'test')));
B = (yield scene.enter(pretend.response('B', 'test')));
scene.exitAll();
A.dialogue.should.be["instanceof"](Dialogue);
return B.dialogue.should.be["instanceof"](Dialogue);
});
return co(function*() {
var A, B, resA, resB, scene;
scene = new Scene(pretend.robot);
resA = pretend.response('A', 'test');
resB = pretend.response('B', 'test');
A = (yield scene.enter(resA));
A.dialogue.addBranch(matchAny, '');
B = (yield scene.enter(resB));
B.dialogue.addBranch(matchAny, '');
A.dialogue.clearTimeout = sinon.spy();
B.dialogue.clearTimeout = sinon.spy();
scene.exitAll();
A.dialogue.clearTimeout.should.have.calledOnce;
return B.dialogue.clearTimeout.should.have.calledOnce;
});
return co(function*() {
var scene;
scene = new Scene(pretend.robot);
yield scene.enter(pretend.response('A', 'test'));
yield scene.enter(pretend.response('B', 'test'));
scene.exitAll();
return scene.engaged.length.should.equal(0);
});
return co(function*() {
var dialogue, result, scene;
scene = new Scene(pretend.robot);
dialogue = (yield scene.enter(pretend.lastReceive())).dialogue;
result = scene.getDialogue('user_111');
return dialogue.should.eql(result);
});
var dialogue, scene;
scene = new Scene(pretend.robot);
dialogue = scene.getDialogue('user_111');
return should.not.exist(dialogue);
return co(function*() {
var scene;
scene = new Scene(pretend.robot);
yield scene.enter(pretend.lastReceive());
return scene.inDialogue('user_111').should.be["true"];
});
return co(function*() {
var scene;
scene = new Scene(pretend.robot);
yield scene.enter(pretend.lastReceive());
return scene.inDialogue('testing').should.be["false"];
});
return co(function*() {
var scene;
scene = new Scene(pretend.robot);
yield scene.enter(pretend.lastReceive());
return scene.inDialogue('user_222').should.be["false"];
});
return co(function*() {
var scene;
scene = new Scene(pretend.robot, {
scope: 'room'
});
yield scene.enter(pretend.lastReceive());
return scene.inDialogue('testing').should.be["true"];
});
return co(function*() {
var scene;
scene = new Scene(pretend.robot, {
scope: 'room'
});
yield scene.enter(pretend.lastReceive());
return scene.inDialogue('user_111').should.be["false"];
});
return co(function*() {
var scene;
scene = new Scene(pretend.robot, {
scope: 'direct'
});
yield scene.enter(pretend.lastReceive());
return scene.inDialogue('user_111_testing').should.be["true"];
});
return co(function*() {
var scene;
scene = new Scene(pretend.robot, {
scope: 'direct'
});
yield scene.enter(pretend.lastReceive());
return scene.inDialogue('testing').should.be["false"];
});
return co(function*() {
var scene;
scene = new Scene(pretend.robot, {
scope: 'direct'
});
yield scene.enter(pretend.lastReceive());
return scene.inDialogue('user_111').should.be["false"];
});
return this.director.names.should.eql([]);
return this.director.authorise = this.authorise;
return this.director.config.deniedReply.should.equal("DENIED!");
return this.director.config.should.eql({
type: 'whitelist',
scope: 'username',
deniedReply: "403 Sorry."
});
return this.director.names.should.eql(['Emmanuel']);
return this.director.names.should.eql(['Capital']);
return this.director.names.should.eql(['Winston', 'Julia', 'Syme']);
return this.director.names.should.eql(['Labour']);
return Director.prototype.constructor.should["throw"];
return Director.prototype.constructor.should["throw"];
return this.director.config.scope.should.equal('room');
return this.director.authorise.should.eql(this.authorise);
return this.director.names.should.eql(['pema', 'nima']);
return this.director.names.should.eql(['pema']);
return this.director.names.should.eql(['yeon', 'juan', 'pema']);
return this.director.names.should.eql(['yeon', 'juan']);
return this.director.names.should.eql(['yeon', 'juan', 'nima']);
return this.director.names.should.eql(['yeon']);
var director;
director = new Director(pretend.robot);
return director.isAllowed(pretend.response('tester', 'test')).should.be["false"];
var director;
director = new Director(pretend.robot);
director.names = ['tester'];
return director.isAllowed(pretend.response('tester', 'test')).should.be["true"];
var director;
director = new Director(pretend.robot);
director.names = ['nobody'];
return director.isAllowed(pretend.response('tester', 'test')).should.be["false"];
var director;
director = new Director(pretend.robot, {
type: 'blacklist'
});
return director.isAllowed(pretend.response('tester', 'test')).should.be["true"];
var director;
director = new Director(pretend.robot, {
type: 'blacklist'
});
director.names = ['tester'];
return director.isAllowed(pretend.response('tester', 'test')).should.be["false"];
var director;
director = new Director(pretend.robot, {
type: 'blacklist'
});
director.names = ['nobody'];
return director.isAllowed(pretend.response('tester', 'test')).should.be["true"];
var authorise, director, res;
authorise = sinon.spy(function() {
return 'AUTHORISE';
});
director = new Director(pretend.robot, authorise);
res = pretend.response('tester', 'test');
director.isAllowed(res);
return authorise.should.have.calledWith('tester', res);
var authorise, director;
authorise = sinon.spy(function() {
return 'AUTHORISE';
});
director = new Director(pretend.robot, authorise);
return director.isAllowed(pretend.response('tester', 'test')).should.equal('AUTHORISE');
var authorise, director;
authorise = sinon.spy(function() {
return 'AUTHORISE';
});
director = new Director(pretend.robot, authorise);
director.names = ['tester'];
return director.isAllowed(pretend.response('tester', 'test')).should.be["true"];
var authorise, director;
authorise = sinon.spy(function() {
return 'AUTHORISE';
});
director = new Director(pretend.robot, authorise);
director.names = ['tester'];
director.isAllowed(pretend.response('tester', 'test'));
return authorise.should.not.have.been.calledOnce;
var authorise, director;
authorise = sinon.spy(function() {
return 'AUTHORISE';
});
director = new Director(pretend.robot, authorise);
director.names = ['nobody'];
return director.isAllowed(pretend.response('tester', 'test')).should.equal('AUTHORISE');
var authorise, director, res;
authorise = sinon.spy(function() {
return 'AUTHORISE';
});
director = new Director(pretend.robot, authorise, {
type: 'blacklist'
});
res = pretend.response('tester', 'test');
director.isAllowed(res);
return authorise.should.have.calledWith('tester', res);
var authorise, director;
authorise = sinon.spy(function() {
return 'AUTHORISE';
});
director = new Director(pretend.robot, authorise, {
type: 'blacklist'
});
return director.isAllowed(pretend.response('tester', 'test')).should.equal('AUTHORISE');
var authorise, director;
authorise = sinon.spy(function() {
return 'AUTHORISE';
});
director = new Director(pretend.robot, authorise, {
type: 'blacklist'
});
director.names = ['tester'];
return director.isAllowed(pretend.response('tester', 'test')).should.be["false"];
var authorise, director;
authorise = sinon.spy(function() {
return 'AUTHORISE';
});
director = new Director(pretend.robot, authorise, {
type: 'blacklist'
});
director.names = ['tester'];
director.isAllowed(pretend.response('tester', 'test'));
return authorise.should.not.have.been.calledOnce;
var authorise, director;
authorise = sinon.spy(function() {
return 'AUTHORISE';
});
director = new Director(pretend.robot, authorise, {
type: 'blacklist'
});
director.names = ['nobody'];
return director.isAllowed(pretend.response('tester', 'test')).should.equal('AUTHORISE');
var director;
director = new Director(pretend.robot, {
type: 'blacklist',
scope: 'room'
});
director.names = ['testing'];
return director.isAllowed(pretend.response('tester', 'test', 'testing')).should.be["false"];
var director;
director = new Director(pretend.robot, {
type: 'whitelist',
scope: 'room'
});
director.names = ['testing'];
return director.isAllowed(pretend.response('tester', 'test', 'testing')).should.be["true"];
var director, res, scene;
director = new Director(pretend.robot);
scene = new Scene(pretend.robot);
res = pretend.response('tester', 'testing');
director.process(res);
return director.isAllowed.should.have.calledWith(res);
var director, scene;
director = new Director(pretend.robot);
scene = new Scene(pretend.robot);
return director.process(pretend.response('tester', 'testing')).then.should.be.a('function');
return co(function*() {
var director, result, scene;
director = new Director(pretend.robot);
scene = new Scene(pretend.robot);
result = (yield director.process(pretend.response('tester', 'testing')));
return result.should.equal(director.isAllowed.returnValues.pop());
});
return co(function*() {
var authorise, director, result;
authorise = function() {
return new Promise(function(resolve, reject) {
var done;
done = function() {
return resolve('AUTHORISE');
};
return setTimeout(done, 30);
});
};
director = new Director(pretend.robot, authorise);
result = (yield director.process(pretend.response('tester', 'test')));
return result.should.equal('AUTHORISE');
});
return co(function*() {
var director, res;
director = new Director(pretend.robot, {
deniedReply: 'DENIED'
});
res = pretend.response('tester', 'test');
yield director.process(res);
return res.reply.should.have.calledWith('DENIED');
});
return co(function*() {
var director, res;
director = new Director(pretend.robot);
res = pretend.response('tester', 'test');
yield director.process(res);
return res.reply.should.not.have.called;
});
return co(function*() {
var director, res;
director = new Director(pretend.robot);
director.names = ['tester'];
res = pretend.response('tester', 'test');
yield director.process(res);
return director.isAllowed.should.have.calledWith(res);
});
return co(function*() {
var director, result;
director = new Director(pretend.robot);
director.names = ['tester'];
result = (yield director.process(pretend.response('tester', 'test')));
return result.should.equal(director.isAllowed.returnValues.pop());
});
return co(function*() {
var director, res;
director = new Director(pretend.robot);
director.names = ['tester'];
res = pretend.response('tester', 'test');
yield director.process(res);
return res.reply.should.not.have.called;
});
return co(function*() {
var director;
director = new Director(pretend.robot);
pretend.robot.hear(/let me in/, function() {});
director.directMatch(/let me in/);
director.names = ['tester'];
yield pretend.user('tester').send('let me in');
return director.process.should.have.calledOnce;
});
return co(function*() {
var callback, director;
director = new Director(pretend.robot);
callback = sinon.spy();
pretend.robot.hear(/let me in/, callback);
director.directMatch(/let me in/);
director.names = ['tester'];
yield pretend.user('tester').send('let me in');
return callback.should.have.calledOnce;
});
return co(function*() {
var director;
director = new Director(pretend.robot);
pretend.robot.hear(/let me in/, function() {});
director.directMatch(/let me in/);
yield pretend.user('tester').send('let me in');
return director.process.should.have.calledOnce;
});
return co(function*() {
var callback, director;
director = new Director(pretend.robot);
callback = sinon.spy();
pretend.robot.hear(/let me in/, callback);
director.directMatch(/let me in/);
yield pretend.user('tester').send('let me in');
return callback.should.not.have.called;
});
return co(function*() {
var director;
director = new Director(pretend.robot);
pretend.robot.hear(/let me in/, function() {});
director.directMatch(/let me in/);
yield pretend.user('tester').send('foo');
return director.process.should.not.have.called;
});
return co(function*() {
var director;
director = new Director(pretend.robot);
pretend.robot.hear(/let me in/, {
id: 'entry-test'
}, function() {});
director.directListener('entry-test');
yield pretend.user('tester').send('let me in');
return director.process.should.have.calledOnce;
});
return co(function*() {
var callback, director;
director = new Director(pretend.robot);
callback = sinon.spy();
pretend.robot.hear(/let me in/, {
id: 'entry-test'
}, callback);
director.directListener('entry-test');
director.names = ['tester'];
yield pretend.user('tester').send('let me in');
return callback.should.have.calledOnce;
});
return co(function*() {
var callback, director;
director = new Director(pretend.robot);
callback = sinon.spy();
pretend.robot.hear(/let me in/, {
id: 'entry-test'
}, callback);
director.directListener('entry-test');
yield pretend.user('tester').send('let me in');
return callback.should.not.have.called;
});
return co(function*() {
var director;
director = new Director(pretend.robot);
pretend.robot.hear(/let me in/, {
id: 'entry-test'
}, function() {});
director.directListener('entry-test');
yield pretend.user('tester').send('foo');
return director.process.should.not.have.called;
});
var director, res, scene;
director = new Director(pretend.robot);
scene = new Scene(pretend.robot);
director.directScene(scene);
res = pretend.response('tester', 'test');
return scene.enter(res)["catch"](function() {
return director.process.should.have.calledWith(res);
});
var director, keys, scene;
director = new Director(pretend.robot);
scene = new Scene(pretend.robot);
keys = ['response', 'participants', 'options', 'arguments', 'dialogue'];
director.directScene(scene);
director.names = ['tester'];
return scene.enter(pretend.response('tester', 'test')).then(function(result) {
var ref;
return (ref = result.should.have.all).keys.apply(ref, keys);
});
var director, scene;
director = new Director(pretend.robot);
scene = new Scene(pretend.robot);
director.directScene(scene);
return scene.enter(pretend.response('tester', 'test')).then(function() {
throw new Error('promise should have caught');
})["catch"](function(err) {
return err.should.be["instanceof"](Error);
});
return co(function*() {
var director, resA, resB, sceneA, sceneB;
director = new Director(pretend.robot);
sceneA = new Scene(pretend.robot);
sceneB = new Scene(pretend.robot);
director.directScene(sceneA);
resA = pretend.response('tester', 'let me in A');
resB = pretend.response('tester', 'let me in A');
try {
yield sceneA.enter(resA);
yield sceneB.enter(resB);
} catch (error) {}
director.process.should.have.calledOnce;
return director.process.should.have.calledWithExactly(resA);
});
var callback, director, scene;
director = new Director(pretend.robot);
scene = new Scene(pretend.robot);
director.directScene(scene);
director.names = ['tester'];
callback = sinon.spy();
scene.hear(/let me in/, callback);
pretend.user('tester').send('let me in');
return setTimeout(function() {
scene.processEnter.should.have.calledOnce;
callback.should.have.calledOnce;
return done();
}, 35);
var callback, director, scene;
director = new Director(pretend.robot);
scene = new Scene(pretend.robot);
director.directScene(scene);
callback = sinon.spy();
scene.hear(/let me in/, callback);
pretend.user('tester').send('let me in');
return setTimeout(function() {
scene.processEnter.should.not.have.called;
callback.should.not.have.called;
return done();
}, 35);
return this.transcript.records.should.eql([
{
time: 0,
event: 'test'
}
]);
return this.transcript.records.should.eql([]);
return this.transcript.records.should.eql([
{
time: 0,
event: 'mockEvent',
other: [
{
test: 'data'
}
]
}
]);
this.transcript.on('record', (function(_this) {
return function() {
_this.transcript.records[0].should.containSubset({
instance: {
name: _this.module.name,
key: _this.module.key,
id: _this.module.id
}
});
return done();
};
})(this));
return this.module.emit('mockEvent', pretend.response('tester', 'test'));
var res;
res = pretend.response('tester', 'test');
this.transcript.on('record', (function(_this) {
return function() {
_this.transcript.records[0].should.containSubset({
response: {
match: res.match
}
});
return done();
};
})(this));
return this.module.emit('mockEvent', res);
var res;
res = pretend.response('tester', 'test', 'testing');
this.transcript.on('record', (function(_this) {
return function() {
_this.transcript.records[0].should.containSubset({
message: {
user: {
id: res.message.user.id,
name: res.message.user.name
},
room: res.message.room,
text: res.message.text
}
});
return done();
};
})(this));
return this.module.emit('mockEvent', pretend.response('tester', 'test'));
return this.transcript.records[0].should.have.property('key', 'test-key');
return this.transcript.records[0].should.containSubset({
instance: {
name: this.module.name,
config: {
scope: this.module.config.scope
}
}
});
return this.transcript.records[0].should.containSubset({
response: {
message: {
room: 'testing'
}
}
});
return this.transcript.records[0].should.containSubset({
message: {
room: 'testing'
}
});
return this.transcript.records.should.eql([
{
time: 0,
event: 'mockEvent',
instance: {
name: this.module.name,
key: this.module.key,
id: this.module.id
}
}
]);
return this.transcript.records.should.eql([
{
time: 0,
event: 'mockEvent',
instance: {
name: this.module.name,
key: this.module.key,
id: this.module.id
}
}
]);
return this.transcript.recordEvent.should.not["throw"];
return this.transcript.recordEvent.args.should.eql([['match'], ['mismatch'], ['catch'], ['send']]);
return this.transcript.recordEvent.args.should.eql([['foo'], ['bar']]);
var expectedEvents;
expectedEvents = this.transcript.config.events;
expectedEvents.push('path');
return _.keys(pretend.robot._events).should.have.members(expectedEvents);
return this.transcript.recordEvent.should.have.calledWith('match', this.dialogue.path);
return _.keys(pretend.robot._events).should.have.members(['match', 'mismatch', 'end', 'path']);
return this.transcript.recordEvent.should.have.calledWith('end', this.dialogue);
return this.transcript.recordEvent.should.have.calledWith('match', this.dialogue.path);
return this.transcript.recordEvent.should.not.have.calledWith('send', this.dialogue);
return co(function*() {
var dialogue, records, res, scene, transcript;
res = pretend.response('tester', 'test');
removeListeners(pretend.robot);
transcript = new Transcript(pretend.robot, {
save: false,
events: ['enter', 'match', 'send']
});
scene = new Scene(pretend.robot);
transcript.recordScene(scene);
dialogue = (yield scene.enter(res)).dialogue;
dialogue.addBranch(/test/, 'response');
yield dialogue.receive(res);
records = transcript.recordEvent.args.map(function(record) {
return _.take(record, 2);
});
return records.should.eql([['enter', scene], ['match', dialogue.path], ['send', dialogue]]);
});
var director, transcript;
removeListeners(pretend.robot);
transcript = new Transcript(pretend.robot, {
save: false
});
director = new Director(pretend.robot, {
type: 'blacklist'
});
transcript.recordDirector(director);
return _.keys(pretend.robot._events).should.eql(['allow', 'deny']);
return co(function*() {
var director, res, transcript;
removeListeners(pretend.robot);
transcript = new Transcript(pretend.robot, {
save: false
});
director = new Director(pretend.robot, {
type: 'blacklist'
});
res = pretend.response('tester', 'test');
transcript.recordDirector(director);
director.names = ['tester'];
yield director.process(res);
director.config.type = 'whitelist';
yield director.process(res);
return transcript.recordEvent.args.should.eql([['deny', director, res], ['allow', director, res]]);
});
return this.transcript.findRecords({
message: {
user: {
name: 'jon'
}
}
}).should.eql([
{
time: 0,
event: 'match',
instance: {
key: 'time'
},
message: {
user: {
name: 'jon'
},
text: 'now'
}
}, {
time: 0,
event: 'match',
instance: {
key: 'direction'
},
message: {
user: {
name: 'jon'
},
text: 'left'
}
}
]);
return this.transcript.findRecords({
message: {
user: {
name: 'jon'
}
}
}, 'message.text').should.eql(['now', 'left']);
return this.transcript.findKeyMatches('pick-a-color', 0).should.eql(['blue', 'orange', 'red']);
return this.transcript.findKeyMatches('pick-a-color', '111', 0).should.eql(['blue', 'orange']);
let outline = new Outline(pretend.robot, [
{ key: 'foo', condition: /foo/i, send: 'foo' },
{ key: 'bar', condition: /bar/i, send: 'bar', listen: 'hear' }
])
outline.setupScenes.should.have.calledWith()
let outline = new Outline(pretend.robot, [
{ key: 'foo', condition: /foo/i, send: 'foo' },
{ key: 'bar', condition: /bar/i, send: 'bar', listen: 'hear' }
], { setupScenes: false })
outline.setupScenes.should.not.have.calledWith()
let bits = [{ condition: /test/i, send: 'testing' }]
let outline, err
try {
outline = new Outline(pretend.robot, bits)
} catch (e) {
err = e
}
err.should.be.instanceof(Error)
err.message.should.match(/key/)
should.not.exist(outline)
let outline = new Outline(pretend.robot, [
{ key: 'foo', condition: /foo/i, send: 'foo' },
{ key: 'bar', condition: /bar/i, send: 'bar' }
], { setupScenes: false })
outline.getByKey('foo')
.should.eql({ key: 'foo', condition: /foo/i, send: 'foo' })
let outline = new Outline(pretend.robot, [
{ key: 'foo', condition: /foo/i, send: 'foo' },
{ key: 'bar', condition: /bar/i, send: 'bar' }
], { setupScenes: false })
let result, err
try {
result = outline.getByKey('baz')
} catch (e) {
err = e
}
err.should.be.instanceof(Error)
err.message.should.match(/invalid/)
should.not.exist(result)
let bits = [{ key: 'testing', condition: /test/i }]
let outline = new Outline(pretend.robot, bits, { setupScenes: false })
let testString = 'Test'
let testMatch = testString.match(/test/i)
_.isRegExp(outline.parseCondition(bits[0].condition)).should.equal(true)
testString.match(outline.parseCondition(bits[0].condition)).should.eql(testMatch)
// console.log(bits[0].condition, testString.match(outline.parseCondition(bits[0].condition)))
let bits = [{ key: 'testing', condition: '/test/i' }]
let outline = new Outline(pretend.robot, bits, { setupScenes: false })
let testString = 'Test'
let testMatch = testString.match(/test/i)
_.isRegExp(outline.parseCondition(bits[0].condition)).should.equal(true)
testString.match(outline.parseCondition(bits[0].condition)).should.eql(testMatch)
// console.log(bits[0].condition, testString.match(outline.parseCondition(bits[0].condition)))
let bits = [{ key: 'testing', condition: 'test' }]
let outline = new Outline(pretend.robot, bits, { setupScenes: false })
let testString = 'Test'
let testMatch = testString.match(/test/i)
_.isRegExp(outline.parseCondition(bits[0].condition)).should.equal(true)
testString.match(outline.parseCondition(bits[0].condition)).should.eql(testMatch)
// console.log(bits[0].condition, testString.match(outline.parseCondition(bits[0].condition)))
delete pretend.robot.playbook
let outline = new Outline(pretend.robot, [
{ key: 'foo', condition: /foo/i, send: 'foo' },
{ key: 'bar', condition: /bar/i, send: 'bar', listen: 'hear' }
], { setupScenes: false })
try { outline.setupScenes() } catch (e) {}
outline.setupScenes.should.have.thrown('Error')
sinon.spy(playbook, 'sceneListen')
let outline = new Outline(pretend.robot, [
{ key: 'foo', condition: /foo/i, send: 'foo' },
{
key: 'bar',
condition: /bar/i,
send: 'bar',
listen: 'hear',
options: { timeout: 100, scope: 'direct' }
},
{ key: 'baz', condition: /baz/i, send: 'baz' }
], { setupScenes: false })
outline.setupScenes()
playbook.sceneListen.should.have.calledOnce // eslint-disable-line
playbook.sceneListen.should.have.calledWithExactly(
'hear', /bar/i, { timeout: 100, scope: 'direct' }, 'bar', sinon.match.func
)
let outline = new Outline(pretend.robot, [
{ key: 'foo', condition: /foo/i, send: 'foo' },
{ key: 'bar', condition: /bar/i, send: 'bar' }
], { setupScenes: false })
outline.setupScenes()
.should.eql(outline)
let res = pretend.response('tester', 'test')
let outline = new Outline(pretend.robot)
let dialogue = new Dialogue(res)
res.dialogue = dialogue
res.bit = {
key: 'foo',
condition: /foo/i,
send: 'foo',
listen: 'hear',
options: { timeout: 100, scope: 'direct' }
}
outline.setupDialogue(res)
dialogue.config.should.containSubset({
timeout: 100, scope: 'direct'
})
let res = pretend.response('tester', 'test')
let outline = new Outline(pretend.robot)
res.dialogue = new Dialogue(res)
let bit = { key: 'foo', condition: /foo/i, send: 'foo' }
outline.bitCallback(bit, res)
.then.should.be.a('function')
let res = pretend.response('tester', 'test')
let outline = new Outline(pretend.robot)
res.dialogue = new Dialogue(res)
let bit = { key: 'foo', condition: /foo/i, send: 'foo' }
outline.bitCallback(bit, res)
res.bit.should.eql(bit)
async function () {
let res = pretend.response('tester', 'test')
let outline = new Outline(pretend.robot)
res.dialogue = new Dialogue(res)
let bit = { key: 'foo', condition: /foo/i, send: 'foo' }
await outline.bitCallback(bit, res)
outline.setupDialogue.should.have.calledWith(res)
}
async function () {
let res = pretend.response('tester', 'test')
let outline = new Outline(pretend.robot)
res.dialogue = new Dialogue(res)
let bit = { key: 'foo', condition: /foo/i, send: ['foo', 'bar'] }
await outline.bitCallback(bit, res)
pretend.messages.should.eql([
[ 'hubot', 'foo' ],
[ 'hubot', 'bar' ]
])
}
async function () {
let res = pretend.response('tester', 'test')
let bits = [
{ key: 'foo', condition: /foo/i, send: 'foo', next: ['bar'] },
{ key: 'bar', condition: /bar/i, send: 'bar' }
]
let outline = new Outline(pretend.robot, bits)
res.dialogue = new Dialogue(res)
await outline.bitCallback(bits[0], res)
outline.setupPath.should.have.calledWith(res)
}
async function () {
let res = pretend.response('tester', 'test')
let bits = [{ key: 'foo', condition: /foo/i, send: 'foo' }]
let outline = new Outline(pretend.robot, bits)
res.dialogue = new Dialogue(res)
outline.bitCallback(bits[0], res)
outline.setupPath.should.not.have.calledOnce // eslint-disable-line
}
let res = pretend.response('tester', 'test')
let bits = [
{ key: 'foo', condition: /foo/i, send: 'foo', next: ['bar', 'baz'] },
{ key: 'bar', condition: /bar/i, send: 'bar' },
{ key: 'baz', condition: /baz/i, send: 'baz' }
]
let outline = new Outline(pretend.robot, bits)
res.dialogue = new Dialogue(res)
res.dialogue.addPath = sinon.spy()
res.bit = bits[0]
outline.setupPath(res)
res.dialogue.addPath.should.have.calledWith([
[/bar/i, sinon.match.func],
[/baz/i, sinon.match.func]
]) // eslint-disable-line
async function () {
let res = pretend.response('tester', 'test')
let bits = [
{ key: 'foo', condition: /foo/i, send: 'foo', next: ['bar'], catch: 'foo?' },
{ key: 'bar', condition: /bar/i, send: 'bar' }
]
let outline = new Outline(pretend.robot, bits)
res.dialogue = new Dialogue(res)
res.bit = bits[0]
await outline.setupPath(res)
res.dialogue.path.config.catchMessage.should.equal(bits[0].catch)
}
async function () {
pretend.robot.playbook.outline([
{ key: 'foo', condition: /foo/i, send: 'foo!', next: ['bar', 'baz'], listen: 'hear' },
{ key: 'bar', condition: /bar/i, send: 'bar!', next: ['foo', 'baz'] },
{ key: 'baz', condition: /bar/i, send: 'bar!', next: ['foo', 'bar'] }
])
await pretend.user('tester').send('foo?')
await pretend.user('tester').send('bar?')
await pretend.user('tester').send('baz?')
await pretend.user('tester').send('foo?')
await pretend.user('tester').send('baz?')
await pretend.user('tester').send('bar?')
pretend.messages.should.eql([
[ 'tester', 'foo?' ],
[ 'hubot', 'foo!' ],
[ 'tester', 'bar?' ],
[ 'hubot', 'bar!' ],
[ 'tester', 'baz?' ],
[ 'tester', 'foo?' ],
[ 'hubot', 'foo!' ],
[ 'tester', 'baz?' ],
[ 'tester', 'bar?' ],
[ 'hubot', 'bar!' ]
])
}
let improvA = improv.use(pretend.robot)
let improvB = improv.use(pretend.robot)
improvA.should.eql(improvB)
should.exist(improv.instance)
let improvA = improv.use(pretend.robot)
improv.reset()
let improvB = improv.use(pretend.robot)
improvA.should.not.eql(improvB)
improv.use(pretend.robot).robot.should.eql(pretend.robot)
improv.configure({ foo: 'bar' })
improv.configure({ baz: 'qux' })
improv.instance.config.should.include({ foo: 'bar', baz: 'qux' })
pretend.robot.responseMiddleware.should.have.callCount(1)
let func = sinon.spy()
improv.extend(func)
improv.extensions.should.eql([{ 'function': func, path: void 0 }])
let func = sinon.spy()
improv.extend(func, 'a.path')
improv.extensions.should.eql([{ 'function': func, path: 'a.path' }])
improv.data.site = { name: 'Hub' }
improv.remember('site', { lang: 'en' })
improv.data.should.eql({ site: { lang: 'en' } })
improv.data.site = { name: 'Hub' }
improv.remember('site.lang', 'en')
improv.data.should.eql({ site: { name: 'Hub', lang: 'en' } })
let uid = pretend.lastListen().message.user.id
improv.data.site = { name: 'Hub' }
improv.rememberForUser(uid, 'site.nickname', 'Hubby')
improv.userData.should.eql({ [uid]: { site: { nickname: 'Hubby' } } })
improv.data.site = { name: 'Hub', lang: 'en' }
improv.remember('site.lang', 'en')
improv.data.should.eql({ site: { name: 'Hub', lang: 'en' } })
let uid = pretend.lastListen().message.user.id
improv.userData = { [uid]: { site: { nickname: 'Hubby' } } }
improv.forgetForUser(uid, 'site.nickname')
improv.userData.should.eql({ [uid]: { site: {} } })
improv.data.site = { name: 'Hub' }
improv.mergeData({ user: pretend.lastListen().message.user })
.should.eql({
user: pretend.lastListen().message.user,
site: { name: 'Hub' }
})
improv.data.site = { name: 'Hub' }
improv.mergeData({ response: pretend.lastListen() })
.should.eql({
response: pretend.lastListen(),
user: pretend.lastListen().message.user,
site: { name: 'Hub' }
})
let uid = pretend.lastListen().message.user.id
improv.data.site = { name: 'Hub' }
improv.userData = { [uid]: { site: { nickname: 'Hubby' } } }
improv.mergeData({ response: pretend.lastListen() })
.should.eql({
response: pretend.lastListen(),
user: pretend.lastListen().message.user,
site: { name: 'Hub', nickname: 'Hubby' }
})
let uid = pretend.lastListen().message.user.id
improv.data.site = { name: 'Hub' }
improv.userData = { [uid]: { site: { nickname: 'Hubby' } } }
improv.mergeData().should.eql({ site: { name: 'Hub' } })
improv.configure({ save: true })
pretend.robot.brain.set('improv', { site: { owner: 'Hubot' } })
improv.data.site = { name: 'Hub' }
improv.mergeData({ user: pretend.lastListen().message.user })
.should.eql({
user: pretend.lastListen().message.user,
site: { owner: 'Hubot', name: 'Hub' }
})
improv
.extend(() => { return { custom1: 'foo' } })
.extend(() => { return { custom2: 'bar' } })
.mergeData({ user: pretend.lastListen().message.user })
.should.eql({
user: pretend.lastListen().message.user,
custom1: 'foo',
custom2: 'bar'
})
improv
.extend(() => { return { user: { type: 'human' } } })
.mergeData({ user: { name: 'frendo' } })
.should.eql({ user: { name: 'frendo', type: 'human' } })
let func = () => { return { test: { foo: 'bar' } } }
improv
.extend(func, 'test.foo')
.mergeData({ test: { baz: 'qux' } }, ['test.foo'])
.should.eql({ test: { foo: 'bar', baz: 'qux' } })
let func = () => { return { test: { foo: 'bar' } } }
improv
.extend(func, 'test.foo')
.mergeData({ test: { baz: 'qux' } }, ['test'])
.should.eql({ test: { foo: 'bar', baz: 'qux' } })
let func = () => { return { test: { foo: 'bar' } } }
improv
.extend(func, 'test.foo')
.mergeData({ test: { baz: 'qux' } }, ['something.else'])
.should.eql({ test: { baz: 'qux' } })
improv.data = { site: 'The Hub' }
improv
.parse({ strings: ['welcome to ${ this.site }'] })
.should.eql(['welcome to The Hub'])
let string = 'hey ${this.user.name}, pay ${this.product.price}'
improv
.parse({ strings: [string] })
.should.eql(['hey unknown, pay unknown'])
let string = 'hey ${ this.user.name }, pay ${ this.product.price }'
improv.data = { product: { price: '$55' } }
improv
.parse({ strings: [string] })
.should.eql(['hey unknown, pay $55'])
let string = 'hey ${this.user.name}, pay ${this.product.price}'
improv.configure({ replacement: '¯\\_(ツ)_/¯' })
improv.data = { product: { price: '$55' } }
improv
.parse({ strings: [string] })
.should.eql(['¯\\_(ツ)_/¯'])
async () => {
improv.data.site = { name: 'The Hub' }
await pretend.lastListen().send('hello you')
await pretend.lastListen().send('hi ${ this.user.name }')
pretend.messages.should.eql([
['testing', 'tester', 'test'],
['testing', 'hubot', 'hello you'],
['testing', 'hubot', 'hi tester']
])
}
async () => {
improv.data.site = { name: 'The Hub' }
await pretend.lastListen().send(
'testing',
'hi ${ this.user.name }',
'welcome to ${ this.site.name }'
)
pretend.messages.should.eql([
['testing', 'tester', 'test'],
['testing', 'hubot', 'testing'],
['testing', 'hubot', 'hi tester'],
['testing', 'hubot', 'welcome to The Hub']
])
}
async () => {
pretend.robot.hear(/remember i like (.*)/, (res) => {
improv.rememberForUser(res.message.user.id, 'fav', res.match[1])
})
await pretend.user('blueboi').send('remember i like blue')
await pretend.lastListen().send('i know you like ${this.fav}')
pretend.messages.should.eql([
['testing', 'tester', 'test'],
['blueboi', 'remember i like blue'],
['hubot', 'i know you like blue']
])
}
async () => {
pretend.robot.hear(/remember i like (.*)/, (res) => {
improv.rememberForUser(res.message.user.id, 'fav', res.match[1])
})
await pretend.user('blueboi').send('remember i like blue')
let blueres = pretend.lastListen()
await pretend.user('redkid').send('remember i like red')
let redres = pretend.lastListen()
await blueres.reply('i know you like ${this.fav}')
await redres.reply('i know you like ${this.fav}')
pretend.messages.should.eql([
['testing', 'tester', 'test'],
['blueboi', 'remember i like blue'],
['redkid', 'remember i like red'],
['hubot', '@blueboi i know you like blue'],
['hubot', '@redkid i know you like red']
])
}
return playbook.constructor.name.should.equal('Playbook');
return playbook.should.containSubset({
Dialogue: require('../../lib/modules/dialogue'),
Scene: require('../../lib/modules/scene'),
Director: require('../../lib/modules/director'),
Transcript: require('../../lib/modules/transcript'),
Outline: require('../../lib/modules/outline'),
improv: require('../../lib/modules/improv')
});
playbook.foo = 'bar';
playbook = require('../../lib');
return playbook.foo.should.equal('bar');
playbook.foo = 'bar';
playbook = playbook.reset();
return should.not.exist(playbook.foo);
pretend.start();
return playbook.use(pretend.robot).should.have.property('robot', pretend.robot);
pretend.start();
return playbook.use(pretend.robot).should.have.property('log', pretend.log);
return playbook.dialogue(pretend.response('tester', 'test')).should.be["instanceof"](playbook.Dialogue);
var dialogue;
dialogue = playbook.dialogue(pretend.response('tester', 'test'));
return playbook.dialogues[0].should.eql(dialogue);
return playbook.scene().should.be["instanceof"](playbook.Scene);
var scene;
scene = playbook.scene();
return playbook.scenes[0].should.eql(scene);
return playbook.sceneEnter(pretend.response('tester', 'test', 'testing')).then(function() {
return playbook.scenes[0].should.be["instanceof"](playbook.Scene);
});
var keys;
keys = ['response', 'participants', 'options', 'arguments', 'dialogue'];
return playbook.sceneEnter(pretend.response('tester', 'test')).then(function(result) {
var ref;
return (ref = result.should.have.all).keys.apply(ref, keys);
});
return playbook.sceneEnter(pretend.response('tester', 'test')).then(function(context) {
return playbook.scenes[0].engaged[pretend.users.tester.id].should.eql(context.dialogue);
});
var res;
res = pretend.response('tester', 'test', 'testing');
return playbook.sceneEnter(res, {
scope: 'room',
sendReplies: false
}).then(function() {
return playbook.scenes[0].config.scope.should.equal('room');
});
var res;
res = pretend.response('tester', 'test', 'testing');
return playbook.sceneEnter(res, {
scope: 'room',
sendReplies: false
}).then(function(context) {
return context.dialogue.config.sendReplies.should.be["false"];
});
return this.scene.should.be["instanceof"](playbook.Scene);
return playbook.scene.should.have.calledWith({
sendReplies: false,
scope: 'room'
});
return this.listen.should.have.calledWith('hear', /test/, sinon.match.func);
return this.scene.should.be["instanceof"](playbook.Scene);
return playbook.scene.getCall(0).should.have.calledWith();
return this.listen.should.have.calledWith('hear', /test/, sinon.match.func);
var args, ref;
args = [
'hear', /test/, {
scope: 'room'
}, sinon.match.func
];
return (ref = playbook.sceneListen.lastCall.should.have).calledWith.apply(ref, args);
var args, ref;
args = [
'respond', /test/, {
scope: 'room'
}, sinon.match.func
];
return (ref = playbook.sceneListen.getCall(0).should.have).calledWith.apply(ref, args);
return this.director.should.be["instanceof"](playbook.Director);
return playbook.directors[0].should.eql(this.director);
return this.transcript.should.be["instanceof"](playbook.Transcript);
return playbook.transcripts[0].should.eql(this.transcript);
return playbook.transcript.should.have.calledThrice;
return pretend.robot.brain.get('transcripts').should.eql([
{
time: 0,
event: 'deny',
instance: {
name: 'director'
}
}, {
time: 0,
event: 'enter',
instance: {
name: 'scene'
}
}, {
time: 0,
event: 'send',
instance: {
name: 'dialogue'
},
strings: ['test']
}
]);
return playbook.improvise().should.eql(playbook.improv);
return co(function*() {
var res;
res = pretend.response('tester', 'test');
yield res.send('hello ${this.user.name}');
return pretend.messages.pop().should.eql(['hubot', 'hello ${this.user.name}']);
});
return co(function*() {
var res;
res = pretend.response('tester', 'test');
playbook.improvise();
yield res.send('hello ${ this.user.name }');
return pretend.messages.pop().should.eql(['hubot', 'hello tester']);
});
return co(function*() {
var res;
res = pretend.response('tester', 'test');
playbook.improv.extend(function(data) {
data.user.name = data.user.name.toUpperCase();
return data;
});
yield res.send('hello ${ this.user.name }');
return pretend.messages.pop().should.eql(['hubot', 'hello TESTER']);
});
return co(function*() {
var dialogue, transcript;
dialogue = (yield playbook.sceneEnter(pretend.response('tester', 'test'))).dialogue;
transcript = playbook.transcribe(dialogue, {
events: ['match']
});
playbook.improv.extend(function(data) {
var userColors, userId;
userId = data.user.id;
userColors = transcript.findKeyMatches('fav-color', data.user.id, 0);
if (userColors.length) {
return {
user: {
favColor: userColors.pop()
}
};
}
});
yield dialogue.addPath('what is your favourite colour?', [[/.*/, 'nice! mine is ${ this.user.favColor } too!']], 'fav-color');
yield pretend.user('tester').send('orange');
return pretend.messages.should.eql([['hubot', 'what is your favourite colour?'], ['tester', 'orange'], ['hubot', 'nice! mine is orange too!']]);
});
var exit, scene;
scene = playbook.scene();
exit = sinon.spy(scene, 'exitAll');
playbook.shutdown();
return exit.should.have.calledOnce;
var dialogue, end;
dialogue = playbook.dialogue(pretend.response('tester', 'test'));
end = sinon.spy(dialogue, 'end');
playbook.shutdown();
return end.should.have.calledOnce;
sinon.spy(playbook, 'shutdown');
playbook.reset();
return playbook.shutdown.should.have.calledOnce;
playbook.dialogues = [
{
name: 'foo'
}, {
name: 'bar'
}
];
playbook.scenes = [
{
name: 'foo'
}, {
name: 'bar'
}
];
playbook.directors = [
{
name: 'foo'
}, {
name: 'bar'
}
];
playbook.transcripts = [
{
name: 'foo'
}, {
name: 'bar'
}
];
playbook.outlines = [
{
name: 'foo'
}, {
name: 'bar'
}
];
playbook = playbook.reset();
playbook.dialogues.should.eql([]);
playbook.scenes.should.eql([]);
playbook.transcripts.should.eql([]);
return playbook.outlines.should.eql([]);
playbook = playbook.reset();
return should.not.exist(playbook.robot);