Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed methods from templates when they are objects, as they don't w…

…ork.

Also, "refactored", which I think introduced a bug not covered by the
tests.
  • Loading branch information...
commit 12f174fdf56e24c7707a5a51580de9b15c573826 1 parent 5144b6c
@nathanmacinnes authored
Showing with 27 additions and 13 deletions.
  1. +19 −13 lib/pretendr.js
  2. +8 −0 test/spec.js
View
32 lib/pretendr.js
@@ -10,25 +10,27 @@ makeTemplate = function (t) {
i,
ownTemplate,
returnValue,
+ setFake,
+ setReturnValue,
+ setTemplate,
subTemplate,
templateObj;
+ setReturnValue = function (val) {
+ returnValue = val;
+ };
+ setFake = function (fn) {
+ fake = fn;
+ };
+ setTemplate = function (tem) {
+ ownTemplate = tem;
+ };
templateObj = {
- returnValue : function (val) {
- returnValue = val;
- },
- fake : function (fn) {
- fake = fn;
- },
- template : function (tem) {
- ownTemplate = tem;
- },
generate : function (o) {
var i,
p;
p = this.apply(pretendr(t, o));
for (i in t) {
- if (t.hasOwnProperty(i) && (typeof t[i] === 'object' ||
- typeof t[i] === 'function')) {
+ if (t.hasOwnProperty(i) && typeof t[i] === 'function') {
this[i].apply(p[i]);
}
}
@@ -47,9 +49,13 @@ makeTemplate = function (t) {
return p;
}
};
+ if (typeof t === 'function') {
+ templateObj.returnValue = setReturnValue;
+ templateObj.fake = setFake;
+ templateObj.template = setTemplate;
+ }
for (i in t) {
- if (t.hasOwnProperty(i) && (typeof t[i] === 'object' ||
- typeof t[i] === 'function')) {
+ if (t.hasOwnProperty(i) && typeof t[i] === 'function') {
subTemplate = makeTemplate(t[i]);
templateObj[i] = subTemplate;
}
View
8 test/spec.js
@@ -334,6 +334,14 @@ describe("pretendr", function () {
res = m.mock();
expect(res.method()).to.equal(4);
});
+ it("shouldn't have meaningless methods for objects", function () {
+ var m = this.pretendr(function () {}),
+ t;
+ t = m.template({});
+ expect(t).to.not.have.property('returnValue')
+ .and.not.have.property('fake')
+ .and.not.have.property('template');
+ });
});
describe("array", function () {
beforeEach(function () {
Please sign in to comment.
Something went wrong with that request. Please try again.