Permalink
Browse files

feat(reporting): AssertionError translated to a Test Failure, not a T…

…est Error

When a Task of Interaction throw or resolve to an AssertionError, the associated scenario step will

be marked as Failed. This helps to make reporting more accurate.
  • Loading branch information...
jan-molak committed Jan 18, 2017
1 parent afff421 commit f3b3066097312dbf3f0cdd177afb905c1ec626f1
Showing with 35 additions and 3 deletions.
  1. +25 −1 spec/api/serenity/recording/step_annotation.spec.ts
  2. +10 −2 src/serenity/recording/step_annotation.ts
@@ -83,7 +83,20 @@ describe('Notifiers', () => {
}
}
it('Notifies the Stage Manager when the Activity fails', () =>
class PayWithInvalidCreditCardThrowingAnAssertionError implements Task {
static number(creditCardNumber: string) {
return new PayWithInvalidCreditCardThrowingAnAssertionError(creditCardNumber);
}
constructor(private cardNumber: string) {}
@step('{0} pays with an invalid credit card number #cardNumber')
performAs(actor: PerformsTasks): PromiseLike<void> {
return expect(Promise.resolve(false)).to.eventually.equal(true);
}
}
it('Notifies the Stage Manager when the Activity throws an Error', () =>
expect(bruce.attemptsTo(PayWithInvalidCreditCardThrowingAnError.number('1234 1234 1234 1234')) ).
to.be.rejected.then(() => {
@@ -93,6 +106,17 @@ describe('Notifiers', () => {
expect(lastEntry.value.error.message).to.equal('Payment failed');
expect(lastEntry.value.result).to.equal(Result.ERROR);
}));
it('Notifies the Stage Manager when the Activity fails', () =>
expect(bruce.attemptsTo(PayWithInvalidCreditCardThrowingAnAssertionError.number('1234 1234 1234 1234'))).
to.be.rejected.then(() => {
let lastEntry = stageManager.readNewJournalEntriesAs('unit-test').pop();
expect(lastEntry.value.error.message).to.equal('expected false to equal true');
expect(Result[lastEntry.value.result]).to.equal(Result[Result.FAILURE]);
}));
});
describe('When things go wrong and the Activity throws an Error', () => {
@@ -45,11 +45,19 @@ export class Step {
}
private onFailure(activity: Activity, error: Error) {
// todo: sniff the exception to find out about the Result. Did the test fail, or was it compromised?
this.stageManager.notifyOf(new ActivityFinished(new Outcome(activity, Result.ERROR, error)));
this.stageManager.notifyOf(new ActivityFinished(new Outcome(activity, this.resultFrom(error), error)));
return Promise.reject(error);
}
private resultFrom(error: Error): Result {
const constructorOf = e => e && e.constructor ? e.constructor.name : '';
// todo: sniff the exception to find out about the Result. Did the test fail, or was it compromised?
return /AssertionError/.test(constructorOf(error))
? Result.FAILURE
: Result.ERROR;
}
}
export function step<T extends Performable>(stepDescriptionTemplate: string): StepAnnotation<T> {

0 comments on commit f3b3066

Please sign in to comment.