Comparing version 1.2.0 to 1.3.0
/* | ||
Copyright (c) 2014 Andrew Rea | ||
Copyright (c) 2014 James Allen | ||
Copyright (c) 2014 Andrew Rea | ||
Copyright (c) 2014 James Allen | ||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
@@ -266,2 +266,3 @@ 'use strict'; | ||
/*jshint maxstatements:false*/ | ||
//jshint maxcomplexity:8 | ||
var debug = require('debug')(PREFIX + ':setup:' + method); | ||
@@ -277,3 +278,3 @@ var self = this; | ||
var functionPredicates = []; | ||
var someFlag = false; | ||
var useCallQueue = false; | ||
@@ -289,3 +290,2 @@ self.toIntercept = function(func) { | ||
debug('call'); | ||
//jshint maxcomplexity:8 | ||
if (_.isFunction(beforeFunc)) { | ||
@@ -332,3 +332,4 @@ debug('before call'); | ||
self.times = function(count) { | ||
debug('times', count); | ||
debug('times', count, callQueue); | ||
useCallQueue = true; | ||
var queue = callQueue; | ||
@@ -338,2 +339,5 @@ if (key) { | ||
} | ||
if (_.isEmpty(queue)) { | ||
queue.push(callToInvoke); | ||
} | ||
var last = queue.pop(); | ||
@@ -474,13 +478,15 @@ if (last) { | ||
debug('callQueueBasedOnArgs', callQueueBasedOnArgs); | ||
} else { | ||
if (_.isFunction(lastPredicate)) { | ||
functionPredicates.push([lastPredicate, func]); | ||
} else { | ||
debug('no predicate function'); | ||
callToInvoke = func; | ||
callQueue.unshift(func); | ||
someFlag = true; | ||
} | ||
argumentsPredicate = null; | ||
return; | ||
} | ||
argumentsPredicate = null; | ||
if (_.isFunction(lastPredicate)) { | ||
functionPredicates.push([lastPredicate, func]); | ||
return; | ||
} | ||
debug('no predicate function', { callQueue }); | ||
callToInvoke = func; | ||
if (useCallQueue) { | ||
debug('using the callQueue'); | ||
callQueue.unshift(func); | ||
} | ||
} | ||
@@ -487,0 +493,0 @@ |
@@ -30,3 +30,2 @@ 'use strict'; | ||
})); | ||
} | ||
@@ -33,0 +32,0 @@ |
{ | ||
"name": "deride", | ||
"description": "Mocking library based on composition", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"homepage": "https://github.com/guzzlerio/deride", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -524,3 +524,3 @@ /* | ||
setup: function() { | ||
var Person = class { | ||
class Person { | ||
constructor(name) { | ||
@@ -538,3 +538,3 @@ this.name = name; | ||
} | ||
}; | ||
} | ||
@@ -787,2 +787,3 @@ return deride.wrap(new Person('bob proto')); | ||
//jshint maxstatements:31 | ||
describe(test.name, function() { | ||
@@ -1196,3 +1197,32 @@ beforeEach(function(done) { | ||
describe('checking issue #80', () => { | ||
beforeEach(() => { | ||
bob.setup.chuckle.toReturn(1); | ||
}); | ||
it('callsback with the expected result', () => { | ||
bob.chuckle(1).should.eql(1); | ||
}); | ||
describe('overriding the setup', () => { | ||
it('callsback with the expected result', () => { | ||
bob.setup.chuckle.toReturn(2); | ||
bob.chuckle(1).should.eql(2); | ||
}); | ||
}); | ||
describe('using times', () => { | ||
it('does something', () => { | ||
bob.setup.chuckle | ||
.toReturn(2) | ||
.twice() | ||
.and.then | ||
.toReturn(33); | ||
bob.chuckle().should.eql(2); | ||
bob.chuckle().should.eql(2); | ||
bob.chuckle().should.eql(33); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
103692
13
1774