Permalink
Browse files

console output format changed

  • Loading branch information...
1 parent b87569e commit 5c6d30bc6edcd7874552a7af0306046c6bd38f6a @bartaz committed Aug 11, 2009
Showing with 59 additions and 9 deletions.
  1. +59 −9 lib/consoleReportForRake.js
  2. BIN spec/.DS_Store
  3. BIN spec/javascripts/.DS_Store
@@ -1,32 +1,82 @@
(function($) {
+ var failedSpecs = [],
+ ESC = String.fromCharCode(27),
+ GREEN = ESC + "[32m",
+ RED = ESC + "[31m",
+ RESET = ESC + "[0m",
+
+// change it to false if your text output doesn't support colouring
+ coloured = true;
+
+ function printGreen(message){
+ if(coloured) { message = GREEN + message + RESET; }
+ print(message);
+ }
+
+ function printRed(message){
+ if(coloured) { message = RED + message + RESET; }
+ print(message);
+ }
+
$(Screw).bind("before", function(){
+ var currentContext = "";
+
+ function context_name(element){
+ var context_name = "";
+ $(element).parents(".describe").children("h1").each(function(){
+ context_name = $(this).text() + " " + context_name;
+ });
+ return context_name.replace(/^\s+|\s+$/g, '');
+ }
+
function example_name(element){
- // TODO: handle nested describes!
- var context_name = $(element).parents(".describe").children("h1").text();
- var example_name = $(element).children("h2").text();
+ return $(element).children("h2").text();
+ }
- return context_name + " - " + example_name;
+ function updateContext(context){
+ if(context != currentContext){
+ currentContext = context;
+ print("\n" + context);
+ }
+ };
+
+ function report(example, failReason){
+ var failed = typeof failReason != 'undefined',
+ context = context_name(example),
+ example = example_name(example),
+ print = failed ? printRed : printGreen,
+ message = " - " + example;
+ if (failed) {
+ message += " (FAILED - " + (failedSpecs.length+1) + ")";
+ failedSpecs.push([context, example, failReason])
+ }
+ updateContext(context);
+ print(message);
}
$('.it')
.bind('passed', function(){
- java.lang.System.out.print(".");
+ report(this);
})
.bind('failed', function(e, reason){
- print("\nFAILED: " + example_name(this));
- print(" " + reason + "\n");
+ report(this, reason);
});
});
$(Screw).bind("after", function(){
var testCount = $('.passed').length + $('.failed').length;
var failures = $('.failed').length;
var elapsedTime = ((new Date() - Screw.suite_start_time)/1000.0);
-
+
print("\n")
+ $.each(failedSpecs, function(i, fail){
+ printRed((i+1) + ")");
+ printRed(fail[0] + " " + fail[1] + " FAILED:")
+ printRed(" " + fail[2] + "\n");
+ });
print(testCount + ' test(s), ' + failures + ' failure(s)');
print(elapsedTime.toString() + " seconds elapsed");
-
+
if(failures > 0) { java.lang.System.exit(1) };
});
})(jQuery);
View
Binary file not shown.
Binary file not shown.

0 comments on commit 5c6d30b

Please sign in to comment.