Comparing version 0.0.7 to 0.0.8
@@ -1,10 +0,14 @@ | ||
function throwUnexpectedArguments() { | ||
var msg = 'Unexpected arguments:' | ||
function throwUnexpectedArguments() { | ||
var msg = 'Unexpected arguments:' | ||
for(var i = 0; i < arguments.length ; i++ ) | ||
{ | ||
msg = msg + ' ' + arguments[i]; | ||
} | ||
throw new Error(msg + '.'); | ||
} | ||
var e = new Error(); | ||
e.name = 'Mock Error'; | ||
e.message = msg + '.'; | ||
throw e; | ||
} | ||
module.exports = throwUnexpectedArguments; |
@@ -8,6 +8,7 @@ var assert = require('assert'); | ||
var thrownErrorMsg; | ||
var thrownName; | ||
(function(){ | ||
console.log('throwUnexpectedArguments'); | ||
var sut = require('../throwUnexpectedArguments'); | ||
var sut = require('../throwUnexpectedArguments'); | ||
try { | ||
@@ -18,2 +19,4 @@ sut(arg1,arg2,arg3); | ||
thrownErrorMsg = error.message; | ||
thrownName = error.name; | ||
thrownStack = error.stack; | ||
} | ||
@@ -24,2 +27,12 @@ | ||
}); | ||
test('it should throw correct name', function(){ | ||
assert.equal('Mock Error',thrownName); | ||
}); | ||
test('it should have stack', function(){ | ||
assert.ok(thrownStack); | ||
}); | ||
})(); |
@@ -9,5 +9,6 @@ var assert = require('assert'); | ||
console.log('mock'); | ||
(function(){ | ||
console.log('mock'); | ||
console.log('an object'); | ||
var realName = 'Alfonzo'; | ||
@@ -50,1 +51,54 @@ function newCustomer() { | ||
})(); | ||
(function foo(){ | ||
console.log('violating function throws with minium stack trace'); | ||
var sut = mock(); | ||
var lines; | ||
try { | ||
sut(); | ||
} | ||
catch(e) { | ||
lines = e.stack.split('\n'); | ||
} | ||
test('reports current function as first source',function() { | ||
assert.deepEqual(lines[1].indexOf('at foo') > 0,true); | ||
}); | ||
test('reports current file as first source',function() { | ||
assert.deepEqual(lines[1].indexOf('testIntegration') > 0,true); | ||
}); | ||
})(); | ||
(function bar(){ | ||
console.log('violating function throws with minium stack trace given two expectations'); | ||
var sut = mock(); | ||
var lines; | ||
try { | ||
sut.expect(1); | ||
sut.expect(2); | ||
sut(); | ||
} | ||
catch(e) { | ||
lines = e.stack.split('\n'); | ||
} | ||
test('reports current function as first source',function() { | ||
assert.deepEqual(lines[1].indexOf('at bar') > 0,true); | ||
}); | ||
test('reports current file as first source',function() { | ||
assert.deepEqual(lines[1].indexOf('testIntegration') > 0,true); | ||
}); | ||
})(); |
{ | ||
"name": "a_mock", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "title": "a_mock", |
@@ -46,3 +46,3 @@ function create(originalFunc) { | ||
mock.expectArray = function(array) { | ||
negotiateEnd();//todo negotiateEnd instead | ||
negotiateEnd(); | ||
mockContext.compositeAreCorrectArguments = newEmptyAnd(); | ||
@@ -49,0 +49,0 @@ var args = [0,mockContext,array]; |
@@ -0,1 +1,3 @@ | ||
var getStackTrace = require('./fallbackWrapper/getStackTrace'); | ||
function _new(originalFallback) { | ||
@@ -6,3 +8,16 @@ | ||
function execute() { | ||
return fallback.apply(null,arguments); | ||
Error.stackTraceLimit = Error.stackTraceLimit + 2; | ||
try { | ||
return fallback.apply(null,arguments); | ||
} | ||
catch (e) { | ||
if (e.name == 'Mock Error') { | ||
e.stack = e.name + ': ' + e.message + '\n' + getStackTrace(); | ||
} | ||
throw e; | ||
} | ||
finally { | ||
Error.stackTraceLimit = Error.stackTraceLimit - 2; | ||
} | ||
} | ||
@@ -9,0 +24,0 @@ |
@@ -5,3 +5,3 @@ var assert = require('assert'); | ||
var newRequireMock = require('../simple/newRequireMock'); | ||
var getStackTrace = newRequireMock('./fallbackWrapper/getStackTrace'); | ||
var newSut = require('../newFallbackWrapper'); | ||
@@ -11,4 +11,7 @@ | ||
console.log('newFallbackWrapper'); | ||
var originalFallback = newMock(); | ||
var sut = newSut(originalFallback); | ||
var didIncrementStackTrace | ||
var originalStackTraceLimit = Error.stackTraceLimit; | ||
@@ -19,5 +22,10 @@ (function() { | ||
var expected = {}; | ||
originalFallback.expect(arg).return(expected); | ||
originalFallback.expect(arg).whenCalled(onFallback).return(expected); | ||
var returned = sut(arg); | ||
test('it increments stack trace limit by two before executing fallback', function() { | ||
assert.ok(didIncrementStackTrace,expected); | ||
}); | ||
test('it should result from originalFallback',function() { | ||
@@ -27,2 +35,7 @@ assert.equal(returned,expected); | ||
test('it resets stack trace limit', function() { | ||
assert.equal(Error.stackTraceLimit,originalStackTraceLimit); | ||
}); | ||
(function() { | ||
@@ -35,9 +48,19 @@ console.log('setFallback'); | ||
console.log('execute'); | ||
didIncrementStackTrace = false; | ||
var expected = {}; | ||
fallback.expect(arg).return(expected); | ||
fallback.expect(arg).whenCalled(onFallback).return(expected); | ||
var returned = sut(arg); | ||
test('it increments stack trace limit by two before executing fallback', function() { | ||
assert.ok(didIncrementStackTrace); | ||
}); | ||
test('it should return result from new fallback',function() { | ||
assert.equal(returned,expected); | ||
}); | ||
test('it resets stack trace limit', function() { | ||
assert.equal(Error.stackTraceLimit,originalStackTraceLimit); | ||
}); | ||
})(); | ||
@@ -47,2 +70,7 @@ })(); | ||
function onFallback() { | ||
didIncrementStackTrace = (Error.stackTraceLimit == originalStackTraceLimit + 2); | ||
} | ||
})(); |
@@ -7,5 +7,5 @@ function throwUnexpectedArguments() { | ||
} | ||
throw msg + '.'; | ||
throw new Error(msg + '.'); | ||
} | ||
module.exports = throwUnexpectedArguments; |
117972
115
3812