Comparing version 0.1.11 to 0.1.12
@@ -39,19 +39,34 @@ /* | ||
function checkArg(expected, values) { | ||
var foundArg = false; | ||
for (var valueIndex = 0; valueIndex < values.length; valueIndex++) { | ||
var actual = values[valueIndex]; | ||
try { | ||
assert.deepEqual(actual, expected); | ||
foundArg = true; | ||
break; | ||
} catch (err) {} | ||
} | ||
return foundArg; | ||
} | ||
function checkArgs(expectedArgs, callArgs) { | ||
var values = _.values(callArgs); | ||
var argResults = []; | ||
for (var argIndex = 0; argIndex < expectedArgs.length; argIndex++) { | ||
var expected = expectedArgs[argIndex]; | ||
var foundArg = checkArg(expected, values); | ||
argResults.push(foundArg); | ||
} | ||
return _.all(argResults); | ||
} | ||
function withArgs() { | ||
var args = arguments; | ||
var results = []; | ||
var args = _.values(arguments); | ||
var callResults = []; | ||
_.forEach(calledWithArgs, function(value) { | ||
var found = true; | ||
for (var i = 0; i < arguments.length; i++) { | ||
var actual = value[i]; | ||
var expected = args[i]; | ||
try{ | ||
assert.deepEqual(actual, expected); | ||
found = true; | ||
break; | ||
}catch(err){ } | ||
} | ||
results.push(found); | ||
var argResult = checkArgs(args, value); | ||
callResults.push(argResult); | ||
}); | ||
assert(_.any(results)); | ||
assert(_.any(callResults)); | ||
} | ||
@@ -225,2 +240,3 @@ | ||
var wrapped = wrap(objHarness); | ||
function createFunc() { | ||
@@ -227,0 +243,0 @@ var returnVal = wrapped.value.apply(objHarness, arguments); |
{ | ||
"name": "deride", | ||
"description": "Mocking library based on composition", | ||
"version": "0.1.11", | ||
"version": "0.1.12", | ||
"homepage": "https://github.com/REAANDREW/deride", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -62,2 +62,11 @@ /* | ||
it('throws exception when object not called withArgs', function(done){ | ||
var obj = deride.stub(['send']); | ||
obj.send(1,2,3); | ||
assert.throws(function(){ | ||
obj.expect.send.called.withArgs(4); | ||
}, Error); | ||
done(); | ||
}); | ||
it('handles comparison of withArgs when an argument is a function', function(done) { | ||
@@ -64,0 +73,0 @@ var obj = deride.stub(['send']); |
35801
687