Comparing version 0.5.2 to 0.5.3
@@ -42,2 +42,6 @@ /* | ||
function checkArg(expected, values) { | ||
if (_.isArray(expected)) { | ||
var jsonExpected = JSON.stringify(expected); | ||
return _.some(_.filter(values, function (v) { return JSON.stringify(v) === jsonExpected; })); | ||
} | ||
if (_.isObject(expected)) { | ||
@@ -44,0 +48,0 @@ return _.some(_.filter(values, expected)); |
{ | ||
"name": "deride", | ||
"description": "Mocking library based on composition", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"homepage": "https://github.com/guzzlerio/deride", | ||
@@ -40,3 +40,3 @@ "author": { | ||
"mocha": "^2.2.5", | ||
"should": "^7.0.1" | ||
"should": "^8.3.0" | ||
}, | ||
@@ -43,0 +43,0 @@ "keywords": [ |
@@ -84,12 +84,17 @@ /* | ||
describe('Expectations', function() { | ||
describe.only('Expectations', function() { | ||
var bob; | ||
beforeEach(function () { | ||
bob = deride.stub(['greet']); | ||
bob.setup.greet.toReturn('talula'); | ||
}); | ||
it('does not invoke original method when override method body', function() { | ||
var obj = deride.stub(['send']); | ||
obj.setup.send.toThrow('bang'); | ||
bob.setup.greet.toThrow('bang'); | ||
obj = deride.wrap(obj); | ||
obj.setup.send.toDoThis(function() { | ||
bob = deride.wrap(bob); | ||
bob.setup.greet.toDoThis(function() { | ||
return 'hello'; | ||
}); | ||
var result = obj.send(); | ||
var result = bob.greet(); | ||
assert.equal(result, 'hello'); | ||
@@ -99,4 +104,3 @@ }); | ||
it('ignores the order of an object properties when comparing equality', function(done) { | ||
var obj = deride.stub(['send']); | ||
obj.send({ | ||
bob.greet({ | ||
c: 3, | ||
@@ -106,3 +110,3 @@ b: 2, | ||
}); | ||
obj.expect.send.called.withArgs({ | ||
bob.expect.greet.called.withArgs({ | ||
a: 1, | ||
@@ -116,6 +120,5 @@ b: 2, | ||
it('throws exception when object not called withArgs', function(done) { | ||
var obj = deride.stub(['send']); | ||
obj.send('1', '2', '3'); | ||
bob.greet('1', '2', '3'); | ||
assert.throws(function() { | ||
obj.expect.send.called.withArgs('4'); | ||
bob.expect.greet.called.withArgs('4'); | ||
}, Error); | ||
@@ -125,15 +128,45 @@ done(); | ||
it('handles comparison of withArgs when an argument is a function', function(done) { | ||
var obj = deride.stub(['send']); | ||
obj.send({ | ||
describe('withArg called with an array', function () { | ||
_.forEach([{ | ||
name: 'string', input: 'talula', expectPass: false | ||
}, { | ||
name: 'non match array', input: ['d', 'e'], expectPass: false | ||
}, { | ||
name: 'partial match array', input: ['a', 'd'], expectPass: false | ||
}, { | ||
name: 'match but wrong order', input: ['b', 'a'], expectPass: false | ||
}, { | ||
name: 'match', input: ['a', 'b'], expectPass: true | ||
}], function (test) { | ||
if (test.expectPass) { | ||
it('object called with ' + test.name + ' should pass', function() { | ||
bob.greet(test.input); | ||
bob.expect.greet.called.withArg(['a', 'b']); | ||
}); | ||
} else { | ||
it('object called with ' + test.name + ' should fail', function() { | ||
bob.greet(test.input); | ||
assert.throws(function() { | ||
bob.expect.greet.called.withArg(['a', 'b']); | ||
}, Error); | ||
}); | ||
} | ||
}); | ||
}); | ||
it('handles withArg called with object', function () { | ||
bob.greet(new Error('booom')); | ||
bob.expect.greet.called.withArgs(new Error('booom')); | ||
}); | ||
it('handles comparison of withArgs when an argument is a function', function() { | ||
bob.greet({ | ||
a: 1 | ||
}, function() {}); | ||
obj.expect.send.called.withArgs({ | ||
bob.expect.greet.called.withArgs({ | ||
a: 1 | ||
}); | ||
done(); | ||
}); | ||
it('allows matching call args with regex', function() { | ||
var bob = deride.stub(['greet']); | ||
bob.greet('The inspiration for this was that my colleague was having a'); | ||
@@ -149,3 +182,2 @@ bob.greet({ | ||
it('allows matching call args with regex', function() { | ||
var bob = deride.stub(['greet']); | ||
bob.greet('The inspiration for this was that my colleague was having a'); | ||
@@ -159,3 +191,2 @@ | ||
it('allows matching call args with regex in objects', function() { | ||
var bob = deride.stub(['greet']); | ||
bob.greet('The inspiration for this was that my colleague was having a'); | ||
@@ -171,3 +202,2 @@ bob.greet({ | ||
it('allows matching call args with regex in deep objects', function() { | ||
var bob = deride.stub(['greet']); | ||
bob.greet('The inspiration for this was that my colleague was having a'); | ||
@@ -553,18 +583,8 @@ bob.greet({ | ||
it('enables resolving a promise', function(done) { | ||
bob.greet('alice').then(function(result) { | ||
assert.equal(result, 'foobar'); | ||
done(); | ||
}); | ||
it('enables resolving a promise', function() { | ||
bob.greet('alice').should.be.fulfilledWith('foobar'); | ||
}); | ||
it('enables rejecting a promise', function(done) { | ||
bob.greet('norman') | ||
.then(function() { | ||
done('should not have resolved'); | ||
}) | ||
.catch(function(result) { | ||
assert.equal(result.message, 'foobar'); | ||
done(); | ||
}); | ||
it('enables rejecting a promise', function() { | ||
bob.greet('norman').should.be.rejectedWith('foobar'); | ||
}); | ||
@@ -571,0 +591,0 @@ }); |
70867
1417