Skip to content

Instantly share code, notes, and snippets.

@igorparrabastias
Last active August 29, 2015 14:02
Show Gist options
  • Save igorparrabastias/9b0fdc0d367fb44a4d40 to your computer and use it in GitHub Desktop.
Save igorparrabastias/9b0fdc0d367fb44a4d40 to your computer and use it in GitHub Desktop.
node.js: Stubbing with gently and assert modules
var gently = new (require('gently'))
, assert = require('assert')
function Dog() {
}
Dog.prototype.seeCat = function() {
console.log('seeing cat...');
this.bark('whuf, whuf');
this.run();
}
Dog.prototype.bark = function(bark) {
console.log('real: ' + bark)
}
var dog = new Dog();
gently.expect(dog, 'bark', function(bark) {
assert.equal(bark, 'whuf, whuf');
console.log('fake: ' + bark)
});
gently.expect(dog, 'run');
dog.seeCat(); // executing dog action
---
Both "expect" calls fake the real Dog methods. Even Dog.prototype.run() that does not exist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment