new processAssertionResult now processes things in the right order
Showing
1 changed file
with
20 additions
and
24 deletions
... | @@ -85,6 +85,10 @@ var Tester = function Tester(casper, options) { | ... | @@ -85,6 +85,10 @@ var Tester = function Tester(casper, options) { |
85 | this.comment(' got: ' + utils.serialize(failure.values.subject)); | 85 | this.comment(' got: ' + utils.serialize(failure.values.subject)); |
86 | this.comment(' expected: ' + utils.serialize(failure.values.expected)); | 86 | this.comment(' expected: ' + utils.serialize(failure.values.expected)); |
87 | break; | 87 | break; |
88 | case 'assertNotEquals': | ||
89 | this.comment(' got: ' + utils.serialize(failure.values.subject)); | ||
90 | this.comment(' shouldnt: ' + utils.serialize(failure.values.shouldnt)); | ||
91 | break; | ||
88 | } | 92 | } |
89 | }); | 93 | }); |
90 | 94 | ||
... | @@ -114,11 +118,11 @@ var Tester = function Tester(casper, options) { | ... | @@ -114,11 +118,11 @@ var Tester = function Tester(casper, options) { |
114 | * | 118 | * |
115 | * @param Mixed subject The value to test | 119 | * @param Mixed subject The value to test |
116 | * @param Mixed expected The expected value | 120 | * @param Mixed expected The expected value |
117 | * @param String message Test description | 121 | * @param String message Test description (Optional) |
118 | * @param Object|null context Assertion context object | 122 | * @param Object|null context Assertion context object (Optional) |
119 | */ | 123 | */ |
120 | this.assertEquals = this.assertEqual = function assertEquals(subject, expected, message, context) { | 124 | this.assertEquals = this.assertEqual = function assertEquals(subject, expected, message, context) { |
121 | this.processAssertionResult(utils.mergeObjects({ | 125 | return this.processAssertionResult(utils.mergeObjects({ |
122 | success: this.testEquals(subject, expected), | 126 | success: this.testEquals(subject, expected), |
123 | type: "assertEquals", | 127 | type: "assertEquals", |
124 | details: f("test failed; expected: %s; got: %s", expected, subject), | 128 | details: f("test failed; expected: %s; got: %s", expected, subject), |
... | @@ -136,32 +140,21 @@ var Tester = function Tester(casper, options) { | ... | @@ -136,32 +140,21 @@ var Tester = function Tester(casper, options) { |
136 | * | 140 | * |
137 | * @param Mixed subject The value to test | 141 | * @param Mixed subject The value to test |
138 | * @param Mixed expected The unwanted value | 142 | * @param Mixed expected The unwanted value |
139 | * @param String message Test description | 143 | * @param String|null message Test description (Optional) |
144 | * @param Object|null context Assertion context object (Optional) | ||
140 | */ | 145 | */ |
141 | this.assertNotEquals = function assertNotEquals(subject, shouldnt, message) { | 146 | this.assertNotEquals = function assertNotEquals(subject, shouldnt, message, context) { |
142 | var eventName; | 147 | return this.processAssertionResult(utils.mergeObjects({ |
143 | message = message || ""; | 148 | success: !this.testEquals(subject, shouldnt), |
144 | if (!this.testEquals(subject, shouldnt)) { | ||
145 | eventName = "success"; | ||
146 | casper.echo(this.colorize(this.options.passText, 'INFO') + ' ' + this.formatMessage(message)); | ||
147 | this.testResults.passed++; | ||
148 | } else { | ||
149 | eventName = "fail"; | ||
150 | casper.echo(this.colorize(this.options.failText, 'RED_BAR') + ' ' + this.formatMessage(message, 'WARNING')); | ||
151 | this.comment(' got: ' + utils.serialize(subject)); | ||
152 | this.comment(' shouldnt: ' + utils.serialize(shouldnt)); | ||
153 | this.testResults.failed++; | ||
154 | } | ||
155 | this.emit(eventName, { | ||
156 | type: "assertNotEquals", | 149 | type: "assertNotEquals", |
150 | details: f("test failed; shouldn't be %s, but was.", shouldnt), | ||
157 | message: message, | 151 | message: message, |
158 | details: f("test failed; shouldnt: %s; got: %s", shouldnt, subject), | ||
159 | file: this.currentTestFile, | 152 | file: this.currentTestFile, |
160 | values: { | 153 | values: { |
161 | subject: subject, | 154 | subject: subject, |
162 | shouldnt: shouldnt | 155 | shouldnt: shouldnt |
163 | } | 156 | } |
164 | }); | 157 | }, context || {})); |
165 | }; | 158 | }; |
166 | 159 | ||
167 | /** | 160 | /** |
... | @@ -412,7 +405,7 @@ var Tester = function Tester(casper, options) { | ... | @@ -412,7 +405,7 @@ var Tester = function Tester(casper, options) { |
412 | * @param String message | 405 | * @param String message |
413 | */ | 406 | */ |
414 | this.fail = function fail(message, context) { | 407 | this.fail = function fail(message, context) { |
415 | this.processAssertionResult(utils.mergeObjects({ | 408 | return this.processAssertionResult(utils.mergeObjects({ |
416 | success: false, | 409 | success: false, |
417 | type: "fail", | 410 | type: "fail", |
418 | details: "explicit call to fail()", | 411 | details: "explicit call to fail()", |
... | @@ -485,9 +478,11 @@ var Tester = function Tester(casper, options) { | ... | @@ -485,9 +478,11 @@ var Tester = function Tester(casper, options) { |
485 | }; | 478 | }; |
486 | 479 | ||
487 | /** | 480 | /** |
488 | * Processes an assertion result. | 481 | * Processes an assertion result by emitting the appropriate event and |
482 | * printing result onto the console. | ||
489 | * | 483 | * |
490 | * @param Object result An assertion result object | 484 | * @param Object result An assertion result object |
485 | * @return Object The passed assertion result Object | ||
491 | */ | 486 | */ |
492 | this.processAssertionResult = function processAssertionResult(result) { | 487 | this.processAssertionResult = function processAssertionResult(result) { |
493 | var eventName, style, status; | 488 | var eventName, style, status; |
... | @@ -502,8 +497,9 @@ var Tester = function Tester(casper, options) { | ... | @@ -502,8 +497,9 @@ var Tester = function Tester(casper, options) { |
502 | status = this.options.failText; | 497 | status = this.options.failText; |
503 | this.testResults.failed++; | 498 | this.testResults.failed++; |
504 | } | 499 | } |
505 | this.emit(eventName, result); | ||
506 | casper.echo([this.colorize(status, style), this.formatMessage(result.message)].join(' ')); | 500 | casper.echo([this.colorize(status, style), this.formatMessage(result.message)].join(' ')); |
501 | this.emit(eventName, result); | ||
502 | return result; | ||
507 | }; | 503 | }; |
508 | 504 | ||
509 | /** | 505 | /** | ... | ... |
-
Please register or sign in to post a comment