Commit 3b5ed009 3b5ed00912f36be9a8372264f477ac27feec544d by Nicolas Perriault

refs #46 - added value details to Tester 'fail' event

1 parent e8e17db0
...@@ -80,14 +80,14 @@ var Tester = function(casper, options) { ...@@ -80,14 +80,14 @@ var Tester = function(casper, options) {
80 80
81 // methods 81 // methods
82 /** 82 /**
83 * Asserts a condition resolves to true. 83 * Asserts that a condition strictly resolves to true.
84 * 84 *
85 * @param Boolean condition 85 * @param Boolean subject
86 * @param String message Test description 86 * @param String message Test description
87 */ 87 */
88 this.assert = function assert(condition, message) { 88 this.assert = function assert(subject, message) {
89 var status = this.options.passText, eventName; 89 var status = this.options.passText, eventName;
90 if (condition === true) { 90 if (subject === true) {
91 eventName = 'success'; 91 eventName = 'success';
92 style = 'INFO'; 92 style = 'INFO';
93 this.testResults.passed++; 93 this.testResults.passed++;
...@@ -101,7 +101,10 @@ var Tester = function(casper, options) { ...@@ -101,7 +101,10 @@ var Tester = function(casper, options) {
101 type: "assert", 101 type: "assert",
102 details: "test failed", 102 details: "test failed",
103 message: message, 103 message: message,
104 file: this.currentTestFile 104 file: this.currentTestFile,
105 values: {
106 subject: subject
107 }
105 }); 108 });
106 casper.echo([this.colorize(status, style), this.formatMessage(message)].join(' ')); 109 casper.echo([this.colorize(status, style), this.formatMessage(message)].join(' '));
107 }; 110 };
...@@ -109,28 +112,32 @@ var Tester = function(casper, options) { ...@@ -109,28 +112,32 @@ var Tester = function(casper, options) {
109 /** 112 /**
110 * Asserts that two values are strictly equals. 113 * Asserts that two values are strictly equals.
111 * 114 *
112 * @param Mixed testValue The value to test 115 * @param Mixed subject The value to test
113 * @param Mixed expected The expected value 116 * @param Mixed expected The expected value
114 * @param String message Test description 117 * @param String message Test description
115 */ 118 */
116 this.assertEquals = function assertEquals(testValue, expected, message) { 119 this.assertEquals = function assertEquals(subject, expected, message) {
117 var eventName; 120 var eventName;
118 if (this.testEquals(testValue, expected)) { 121 if (this.testEquals(subject, expected)) {
119 eventName = "success"; 122 eventName = "success";
120 casper.echo(this.colorize(this.options.passText, 'INFO') + ' ' + this.formatMessage(message)); 123 casper.echo(this.colorize(this.options.passText, 'INFO') + ' ' + this.formatMessage(message));
121 this.testResults.passed++; 124 this.testResults.passed++;
122 } else { 125 } else {
123 eventName = "fail"; 126 eventName = "fail";
124 casper.echo(this.colorize(this.options.failText, 'RED_BAR') + ' ' + this.formatMessage(message, 'WARNING')); 127 casper.echo(this.colorize(this.options.failText, 'RED_BAR') + ' ' + this.formatMessage(message, 'WARNING'));
125 this.comment(' got: ' + utils.serialize(testValue)); 128 this.comment(' got: ' + utils.serialize(subject));
126 this.comment(' expected: ' + utils.serialize(expected)); 129 this.comment(' expected: ' + utils.serialize(expected));
127 this.testResults.failed++; 130 this.testResults.failed++;
128 } 131 }
129 this.emit(eventName, { 132 this.emit(eventName, {
130 type: "assertEquals", 133 type: "assertEquals",
131 message: message, 134 message: message,
132 details: f("test failed; expected: %s; got: %s", expected, testValue), 135 details: f("test failed; expected: %s; got: %s", expected, subject),
133 file: this.currentTestFile 136 file: this.currentTestFile,
137 values: {
138 subject: subject,
139 expected: expected
140 }
134 }); 141 });
135 }; 142 };
136 143
...@@ -201,7 +208,11 @@ var Tester = function(casper, options) { ...@@ -201,7 +208,11 @@ var Tester = function(casper, options) {
201 type: "assertMatch", 208 type: "assertMatch",
202 message: message, 209 message: message,
203 details: f("test failed; subject: %s; pattern: %s", subject, pattern.toString()), 210 details: f("test failed; subject: %s; pattern: %s", subject, pattern.toString()),
204 file: this.currentTestFile 211 file: this.currentTestFile,
212 values: {
213 subject: subject,
214 pattern: pattern
215 }
205 }); 216 });
206 }; 217 };
207 218
......