/**
* @class ExtMVC.test.JSpecFormatter
* @extends Object
* A JSpec formatter which can be used to extract failure data from JSpec
*/
ExtMVC.test.JSpecFormatter = Ext.extend(Object, {
constructor: function(results, options) {
this.suites = results.suites;
},
/**
* Returns an array of all failing Spec objects for all suites
*/
getFailingSpecs: function(suites) {
var suites = suites || this.suites;
var failures = [];
Ext.each(suites, function(suite) {
failures = failures.concat(this.getFailuresForSuite(suite));
if (suite.hasSuites()) {
failures = failures.concat(this.getFailingSpecs(suite.suites));
}
}, this);
return failures;
},
/**
* Returns an array of failing Spec objects for a given suite
*/
getFailuresForSuite: function(suite) {
if (suite.ran && suite.passed()) {
return [];
} else {
var failures = [];
Ext.each(suite.specs, function(spec) {
if (!spec.passed()) {
Ext.apply(spec, {
code: this.bodyContents(spec.body)
});
failures.push(spec);
}
}, this);
return failures;
}
},
bodyContents: function(body) {
return JSpec.
escape(JSpec.contentsOf(body)).
replace(/^ */gm, function(a){
return (new Array(Math.round(a.length / 3))).join(' ');
}).
replace("\n", '
');
}
});
// DOM : function(results, options) {
// var id = option('reportToId') || 'jspec'
// var report = document.getElementById(id)
// var failuresOnly = option('failuresOnly')
// var classes = results.stats.failures ? 'has-failures' : ''
// if (!report) throw 'JSpec requires the element #' + id + ' to output its reports'
//
// var markup =
// '
' + escape(suite.description) + ' | |||||
' + escape(spec.description) + ' | ' // else if (spec.passed() && !failuresOnly) // markup += '' + escape(spec.description)+ ' | ' + spec.assertionsGraph() + ' | ' // else if(!spec.passed()) // markup += '' + escape(spec.description) + ' ' + spec.failure().message + '' + ' | ' + spec.assertionsGraph() + ' | ' // markup += '|
' + bodyContents(spec.body) + ' |