Permalink
Browse files

[Issue 1] Check if assertions.failures's type is a function before ac…

…cessing it. If it's a function, execute it, otherwise, get its value.
  • Loading branch information...
1 parent ebf438f commit cb0a3520d9499c8ebd0c4dec4f84430a3d041547 Abraao Lourenco committed Sep 27, 2011
Showing with 51 additions and 32 deletions.
  1. +33 −25 lib/nodeunit-dsl.js
  2. +7 −7 src/nodeunit-dsl.coffee
  3. +11 −0 test/issue-1.js
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -27,19 +27,19 @@ exports.run = (name) ->
testStart: ->
fn() for fn in befores
testDone: (name, assertions) ->
+ failures = if typeof(assertions.failures) is "function" then assertions.failures() else assertion.failures
fn() for fn in afters
- if not assertions.failures
+ if not failures
sys.puts "#{name}"
else
sys.puts red "#{name}"
for assertion in assertions when assertion.failed()
sys.puts assertion.error.stack + "\n"
moduleDone: (name, assertions) ->
- if assertions.failures
- sys.puts bold(red(
- "\nFAILURES #{assertions.failures} / #{assertions.length} " +
+ failures = if typeof(assertions.failures) is "function" then assertions.failures() else assertion.failures
+ if failures
+ sys.puts bold(red("\nFAILURES #{failures} / #{assertions.length} " +
" assertions failed (#{assertions.duration} ms)"))
else
- sys.puts bold(green(
- "\nOK: #{assertions.length} assertions(#{assertions.duration} ms)"))
- }, (->)
+ sys.puts bold(green("\nOK: #{assertions.length} assertions(#{assertions.duration} ms)"))
+ }, (->)
View
@@ -0,0 +1,11 @@
+var dsl = require('nodeunit-dsl'),
+ test = dsl.test,
+ run = dsl.run;
+
+if (module.id === '.') run(__filename);
+
+test('the total number of failures is evaluated correctly', function(t) {
+ t.ok(true);
+ t.done();
+});
+

0 comments on commit cb0a352

Please sign in to comment.