Commit f818855f f818855f70264557a26411b4131db0d0d2e054dd by Nicolas Perriault

work in progress

1 parent f8d75e2c
...@@ -76,16 +76,25 @@ var Tester = function Tester(casper, options) { ...@@ -76,16 +76,25 @@ var Tester = function Tester(casper, options) {
76 }); 76 });
77 77
78 this.on('fail', function onFail(failure) { 78 this.on('fail', function onFail(failure) {
79 // export
79 this.exporter.addFailure(fs.absolute(failure.file), failure.message, failure.details || "test failed", failure.type || "unknown"); 80 this.exporter.addFailure(fs.absolute(failure.file), failure.message, failure.details || "test failed", failure.type || "unknown");
80 this.testResults.failures.push(failure); 81 this.testResults.failures.push(failure);
82 // special printing
83 switch (failure.type) {
84 case 'assertEquals':
85 this.comment(' got: ' + utils.serialize(failure.values.subject));
86 this.comment(' expected: ' + utils.serialize(failure.values.expected));
87 break;
88 }
81 }); 89 });
82 90
83 // methods 91 // methods
84 /** 92 /**
85 * Asserts that a condition strictly resolves to true. 93 * Asserts that a condition strictly resolves to true.
86 * 94 *
87 * @param Boolean subject 95 * @param Boolean subject
88 * @param String message Test description 96 * @param String message Test description
97 * @param Object|null context Assertion context object
89 */ 98 */
90 this.assert = this.assertTrue = function assert(subject, message, context) { 99 this.assert = this.assertTrue = function assert(subject, message, context) {
91 this.processAssertionResult(utils.mergeObjects({ 100 this.processAssertionResult(utils.mergeObjects({
...@@ -103,34 +112,23 @@ var Tester = function Tester(casper, options) { ...@@ -103,34 +112,23 @@ var Tester = function Tester(casper, options) {
103 /** 112 /**
104 * Asserts that two values are strictly equals. 113 * Asserts that two values are strictly equals.
105 * 114 *
106 * @param Mixed subject The value to test 115 * @param Mixed subject The value to test
107 * @param Mixed expected The expected value 116 * @param Mixed expected The expected value
108 * @param String message Test description 117 * @param String message Test description
118 * @param Object|null context Assertion context object
109 */ 119 */
110 this.assertEquals = this.assertEqual = function assertEquals(subject, expected, message) { 120 this.assertEquals = this.assertEqual = function assertEquals(subject, expected, message, context) {
111 var eventName; 121 this.processAssertionResult(utils.mergeObjects({
112 message = message || ""; 122 success: this.testEquals(subject, expected),
113 if (this.testEquals(subject, expected)) { 123 type: "assertEquals",
114 eventName = "success";
115 casper.echo(this.colorize(this.options.passText, 'INFO') + ' ' + this.formatMessage(message));
116 this.testResults.passed++;
117 } else {
118 eventName = "fail";
119 casper.echo(this.colorize(this.options.failText, 'RED_BAR') + ' ' + this.formatMessage(message, 'WARNING'));
120 this.comment(' got: ' + utils.serialize(subject));
121 this.comment(' expected: ' + utils.serialize(expected));
122 this.testResults.failed++;
123 }
124 this.emit(eventName, {
125 type: "assertEquals",
126 message: message,
127 details: f("test failed; expected: %s; got: %s", expected, subject), 124 details: f("test failed; expected: %s; got: %s", expected, subject),
125 message: message,
128 file: this.currentTestFile, 126 file: this.currentTestFile,
129 values: { 127 values: {
130 subject: subject, 128 subject: subject,
131 expected: expected 129 expected: expected
132 } 130 }
133 }); 131 }, context || {}));
134 }; 132 };
135 133
136 /** 134 /**
...@@ -169,22 +167,22 @@ var Tester = function Tester(casper, options) { ...@@ -169,22 +167,22 @@ var Tester = function Tester(casper, options) {
169 /** 167 /**
170 * Asserts that a code evaluation in remote DOM resolves to true. 168 * Asserts that a code evaluation in remote DOM resolves to true.
171 * 169 *
172 * @param Function fn A function to be evaluated in remote DOM 170 * @param Function fn A function to be evaluated in remote DOM
173 * @param String message Test description 171 * @param String message Test description
174 * @param Object context Object containing the parameters to inject into the function (optional) 172 * @param Object params Object containing the parameters to inject into the function (optional)
175 */ 173 */
176 this.assertEval = function assertEval(fn, message, context) { 174 this.assertEval = function assertEval(fn, message, params, context) {
177 return this.assert(casper.evaluate(fn, context), message); 175 return this.assert(casper.evaluate(fn, params), message, context);
178 }; 176 };
179 177
180 /** 178 /**
181 * Asserts that the result of a code evaluation in remote DOM equals 179 * Asserts that the result of a code evaluation in remote DOM equals
182 * an expected value. 180 * an expected value.
183 * 181 *
184 * @param Function fn The function to be evaluated in remote DOM 182 * @param Function fn The function to be evaluated in remote DOM
185 * @param Boolean expected The expected value 183 * @param Boolean expected The expected value
186 * @param String message Test description 184 * @param String message Test description
187 * @param Object context Object containing the parameters to inject into the function (optional) 185 * @param Object params Object containing the parameters to inject into the function (optional)
188 */ 186 */
189 this.assertEvalEquals = this.assertEvalEqual = function assertEvalEquals(fn, expected, message, context) { 187 this.assertEvalEquals = this.assertEvalEqual = function assertEvalEquals(fn, expected, message, context) {
190 return this.assertEquals(casper.evaluate(fn, context), expected, message); 188 return this.assertEquals(casper.evaluate(fn, context), expected, message);
...@@ -414,7 +412,13 @@ var Tester = function Tester(casper, options) { ...@@ -414,7 +412,13 @@ var Tester = function Tester(casper, options) {
414 * @param String message 412 * @param String message
415 */ 413 */
416 this.fail = function fail(message, context) { 414 this.fail = function fail(message, context) {
417 this.assert(false, message, context); 415 this.processAssertionResult(utils.mergeObjects({
416 success: false,
417 type: "fail",
418 details: "explicit call to fail()",
419 message: message,
420 file: this.currentTestFile
421 }, context || {}));
418 }; 422 };
419 423
420 /** 424 /**
...@@ -470,8 +474,14 @@ var Tester = function Tester(casper, options) { ...@@ -470,8 +474,14 @@ var Tester = function Tester(casper, options) {
470 * 474 *
471 * @param String message 475 * @param String message
472 */ 476 */
473 this.pass = function pass(message) { 477 this.pass = function pass(message, context) {
474 this.assert(true, message); 478 this.processAssertionResult(utils.mergeObjects({
479 success: true,
480 type: "pass",
481 details: "explicit call to pass()",
482 message: message,
483 file: this.currentTestFile
484 }, context || {}));
475 }; 485 };
476 486
477 /** 487 /**
......
...@@ -42,7 +42,7 @@ var expected = [ ...@@ -42,7 +42,7 @@ var expected = [
42 ].map(function(entry) { 42 ].map(function(entry) {
43 return fs.pathJoin.apply(fs, [testDirRoot].concat(entry.split('/'))); 43 return fs.pathJoin.apply(fs, [testDirRoot].concat(entry.split('/')));
44 }); 44 });
45 t.assertEquals(files, expected, 'findTestFiles() find test files and sort them'); 45 t.assertEquals(files, [], 'findTestFiles() find test files and sort them');
46 46
47 t.comment('Tester.assertTextExists()'); 47 t.comment('Tester.assertTextExists()');
48 casper.start('tests/site/index.html', function() { 48 casper.start('tests/site/index.html', function() {
......