Skip to content

Instantly share code, notes, and snippets.

@Droogans
Last active November 6, 2015 10:43
Show Gist options
  • Save Droogans/86a651ba99575bf1e8e4 to your computer and use it in GitHub Desktop.
Save Droogans/86a651ba99575bf1e8e4 to your computer and use it in GitHub Desktop.
Exercising the buffalo module.
var _ = require('lodash'); // gotta use lodash for everything
var bill = require('buffalo');
var events = bill.events;
var conditions;
var victim;
/**
* TODO -- stop mixing promises and events, this API is really messed up.
*/
describe('suit construction', function () {
before(function () {
events.on('target', function (target) {
var setup = new bill.ModusOperandi({ injuries: [] });
conditions = setup.defaults;
setup.location = target.getLocation();
setup.destination = conditions.WELL;
setup.initialize({ target: target, ploy: conditions.actions.HELP });
victim = target;
});
bill.emit('target');
});
it('puts the lotion on its skin'); // TODO
it('does this whenever it is told', function () {
bill.on('negotiate', function (response) {
expect(response).to.not.be.ok;
});
try {
victim.offers.ransom(Infinity);
} finally {
bill.emit('negotiate');
}
});
it('rubs the lotion on its skin or else it gets the hose again', function () {
bill.sendMessage(bill.companions.dog, conditions.messages.repeatLast());
victim.apply(conditions.LOTION);
expect(victim.currentState).to.be.ok;
});
it('places the lotion in the basket', function (done) {
bill.on(conditions.LOWER_BASKET, function (basket) {
victim.plead();
bill.sendMessage(victim, conditions.messages.repeatLast());
victim.plead({ target: victim.getParent({ mother: true }) }).then(function (response) {
try {
bill.receiveMessage(response);
} catch (e) {
if (e instanceOf bill.errors.MaternalMemoryException) {
bill.sendMessage(victim, conditions.messages.repeatLast({ force: true }));
expect(basket).to.not.be.empty;
} else {
done();
}
}
});
});
bill.emit(conditions.LOWER_BASKET);
bill.emit(conditions.RAISE_BASKET); // no testing needed, just closing up resources
});
after(function () {
var observedBehavior = _.deepClone(victim.currentState);
delete victim.currentState;
bill.emit(observedBehavior);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment