Skip to content

Commit

Permalink
Expand .with message to include actual results
Browse files Browse the repository at this point in the history
  • Loading branch information
robcolburn committed Apr 22, 2016
1 parent eb493cf commit 3293a5e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
17 changes: 13 additions & 4 deletions chai-spies.js
Expand Up @@ -299,8 +299,10 @@

this.assert(
passed === calls.length
, 'expected ' + this._obj + ' to have been always called with #{exp} but got ' + passed + ' out of ' + calls.length
, 'expected ' + this._his + ' to have not always been called with #{exp}'
, 'expected ' + this._obj + ' to have been always called with ' + _.inspect(args, false, 2)
+ ', but it was actually called ' + passed + ' times with those arguments out of ' + calls.length + ' total calls'
, 'expected ' + this._his + ' to have not always been called with ' + _.inspect(args, false, 2)
+ ', but it was actually called ' + passed + ' times with those arguments out of ' + calls.length + ' total calls'
, args
);
} else {
Expand All @@ -317,8 +319,15 @@

this.assert(
passed > 0
, 'expected ' + this._obj + ' to have been called with #{exp}'
, 'expected ' + this._his + ' to have not been called with #{exp} but got ' + passed + ' times'
, 'expected ' + this._obj + ' to have been called with ' + _.inspect(args, false, 2)
+ (calls.length
? ', but it was actually called ' + calls.length + ' times with:' + calls.map(function (call, i) {
return '\ncall #' + (i + 1) + ': ' + _.inspect(call, false, 2);
}).join('')
: ', but it was actually not called'
)
, 'expected ' + this._his + ' to have not been called with ' + _.inspect(args, false, 2)
+ ', but it actually was called ' + passed + ' times with those arguments, out of ' + calls.length + ' total calls'
, args
);
}
Expand Down
17 changes: 13 additions & 4 deletions lib/spy.js
Expand Up @@ -283,8 +283,10 @@ module.exports = function (chai, _) {

this.assert(
passed === calls.length
, 'expected ' + this._obj + ' to have been always called with #{exp} but got ' + passed + ' out of ' + calls.length
, 'expected ' + this._his + ' to have not always been called with #{exp}'
, 'expected ' + this._obj + ' to have been always called with ' + _.inspect(args, false, 2)
+ ', but it was actually called ' + passed + ' times with those arguments out of ' + calls.length + ' total calls'
, 'expected ' + this._his + ' to have not always been called with ' + _.inspect(args, false, 2)
+ ', but it was actually called ' + passed + ' times with those arguments out of ' + calls.length + ' total calls'
, args
);
} else {
Expand All @@ -301,8 +303,15 @@ module.exports = function (chai, _) {

this.assert(
passed > 0
, 'expected ' + this._obj + ' to have been called with #{exp}'
, 'expected ' + this._his + ' to have not been called with #{exp} but got ' + passed + ' times'
, 'expected ' + this._obj + ' to have been called with ' + _.inspect(args, false, 2) + ' at least once'
+ (calls.length
? ', but it was actually called ' + calls.length + ' times with:' + calls.map(function (call, i) {
return '\ncall #' + (i + 1) + ': ' + _.inspect(call, false, 2);
}).join('')
: ', but it was actually not called'
)
, 'expected ' + this._his + ' to have not been called with ' + _.inspect(args, false, 2)
+ ', but it actually was called ' + passed + ' times with those arguments, out of ' + calls.length + ' total calls'
, args
);
}
Expand Down

0 comments on commit 3293a5e

Please sign in to comment.