Skip to content

Commit

Permalink
Confirm the correct error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jhs committed Nov 16, 2011
1 parent b1c2e35 commit 0102450
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/diffs.js
Expand Up @@ -202,7 +202,7 @@ function assert_atmost() {
var first = bad_changes[0];

if(first) {
var msg = 'Invalid change: "' + first.key + '" may not change: ' + lib.I(first.from) + ' -> ' + lib.I(first.to);
var msg = 'Invalid: "' + first.key + '" may not change: ' + lib.I(first.from) + ' -> ' + lib.I(first.to);

var err = new Error(msg);
err.diff = self;
Expand Down
14 changes: 13 additions & 1 deletion t/policy.js
Expand Up @@ -249,7 +249,19 @@ function make_tester(method, assertion, t, diff_mod) {

function assert_with_method() {
var assert_method = 'assert_' + method;
diff[assert_method].apply(diff, asserting_policy);
try {
diff[assert_method].apply(diff, asserting_policy)
} catch(er) {
t.ok(er.diff, 'Diff error occurs: ' + assert_method+'('+util.inspect(asserting_policy)+')');
if(method == 'atmost')
t.ok(er.message.match(/^Invalid:/), 'Correct atmost error message');
else if(method == 'atleast')
t.ok(er.message.match(/^Required:/), 'Correct atmost error message');
else
t.fail('Unknown method for message testing: ' + assert_method);

throw er;
}
}

function assert_with_module() {
Expand Down

0 comments on commit 0102450

Please sign in to comment.