Permalink
Browse files

Made templates able to have a preset fake function

  • Loading branch information...
1 parent 21b3ab4 commit a2cf4559b95e95e5321898a090bfb1e5ea76cf36 unknown committed Jul 31, 2012
Showing with 22 additions and 3 deletions.
  1. +9 −2 lib/pretendr.js
  2. +13 −1 test/spec.js
View
@@ -56,6 +56,7 @@ module.exports = function (o) {
pretendrFunction = function () {
var fake,
pretendrObj,
+ templateFake,
templateReturnValue,
returnValue,
template;
@@ -71,8 +72,11 @@ module.exports = function (o) {
template : function (t) {
template = t;
return {
- returnValue : function (r) {
- templateReturnValue = r;
+ returnValue : function (val) {
+ templateReturnValue = val;
+ },
+ fake : function (fn) {
+ templateFake = fn;
}
};
},
@@ -101,6 +105,9 @@ module.exports = function (o) {
if (templateReturnValue) {
call.pretendr.returnValue(templateReturnValue);
}
+ if (templateFake) {
+ call.pretendr.fake(templateFake);
+ }
call.returned = call.pretendr.mock;
} else {
call.returned = returnValue;
View
@@ -192,7 +192,7 @@ describe("pretendr", function () {
});
});
describe("#template", function () {
- it("should be able to define returnValues", function () {
+ it("should be able to define return values", function () {
var m = this.pretendr(function () {}),
res,
t;
@@ -201,6 +201,18 @@ describe("pretendr", function () {
res = m.mock();
expect(res()).to.equal('a');
});
+ it("should be able to define a fake", function () {
+ var fake,
+ m = this.pretendr(function () {}),
+ res,
+ t;
+ t = m.template(function () {});
+ fake = this.pretendr(function () {});
+ t.fake(fake.mock);
+ res = m.mock();
+ res();
+ expect(fake.calls).to.have.length(1);
+ });
});
describe("with properties", function () {
it("should mock the properties", function () {

0 comments on commit a2cf455

Please sign in to comment.