Skip to content

Commit

Permalink
fix(core): step annotation calls the method referenced in the templat…
Browse files Browse the repository at this point in the history
…e in a correct context

affects: @serenity-js/core
  • Loading branch information
jan-molak committed May 20, 2017
1 parent 2fdb59b commit d5f76fd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 8 additions & 4 deletions packages/core/spec/recording/step_annotation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ describe('Notifiers', () => {
constructor(private cardNumber: string) {
}

@step('{0} pays with a credit card number #cardNumber')
@step('{0} pays with a credit card number #obfuscatedCardNumber')
performAs(actor: PerformsTasks): PromiseLike<void> {
return actor.attemptsTo( /*...*/ );
}

private obfuscatedCardNumber() {
return [this.cardNumber.slice(0, 4), 'XXXX', 'XXXX', 'XXXX'].join(' ');
}
}

it('Notifies the Stage Manager when the Activity starts', () => {
Expand All @@ -45,7 +49,7 @@ describe('Notifiers', () => {

expect(newJournalEntries[ 0 ]).to.be.instanceOf(ActivityStarts);
expect(newJournalEntries[ 0 ].value).to.be.instanceOf(RecordedActivity);
expect(newJournalEntries[ 0 ].value.name).to.equal('Bruce pays with a credit card number 4111 1111 1111 1111');
expect(newJournalEntries[ 0 ].value.name).to.equal('Bruce pays with a credit card number 4111 XXXX XXXX XXXX');
});
});

Expand All @@ -61,7 +65,7 @@ describe('Notifiers', () => {
expect(newJournalEntries[ 1 ].value).to.be.instanceOf(Outcome);

expect(newJournalEntries[ 1 ].value.subject).to.be.instanceOf(RecordedActivity);
expect(newJournalEntries[ 1 ].value.subject.name).to.equal('Bruce pays with a credit card number 4111 1111 1111 1111');
expect(newJournalEntries[ 1 ].value.subject.name).to.equal('Bruce pays with a credit card number 4111 XXXX XXXX XXXX');
});
});

Expand All @@ -74,7 +78,7 @@ describe('Notifiers', () => {

expect(start.value).to.be.recorded.calledAt({
path: '/step_annotation.spec.ts',
line: 69,
line: 73,
column: 34,
});
});
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/recording/activity_description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { Actor } from '../screenplay/actor';

const isActor = (candidate: any) => candidate instanceof Actor;

const using = (source: any) => (token: string, field: string|number) => stringify(token, source[field]);
const using = (source: any) => (token: string, field: string|number) => typeof source[field] === 'function'
? stringify(token, source[field].bind(source))
: stringify(token, source[field]);

const includeActorName = (template: string, actor: Actor) => template.replace('#actor', actor.toString());
const interpolateArguments = (template: string, parameters: any[]) => template.replace(/{(\d+)}/g, using(parameters));
Expand Down

0 comments on commit d5f76fd

Please sign in to comment.