diff options
Diffstat (limited to 'reuse/features')
| -rw-r--r-- | reuse/features/reusable.feature | 5 | ||||
| -rw-r--r-- | reuse/features/steps/reusable.js | 28 |
2 files changed, 33 insertions, 0 deletions
diff --git a/reuse/features/reusable.feature b/reuse/features/reusable.feature new file mode 100644 index 0000000..98136ff --- /dev/null +++ b/reuse/features/reusable.feature @@ -0,0 +1,5 @@ +Feature: + Scenario: + Given a person with name + And a person named Jack + Then the same function is called for two distinct step definitions diff --git a/reuse/features/steps/reusable.js b/reuse/features/steps/reusable.js new file mode 100644 index 0000000..07ac8c5 --- /dev/null +++ b/reuse/features/steps/reusable.js @@ -0,0 +1,28 @@ +import { Before, Given, Then } from 'cucumber' +import { expect } from 'chai' + +Before(function () { + this.names = [] +}) + +function step (name) { + this.names.push(name) +} + +function decorator (f, ...args) { + if (args.length > 0) { + return function () { + f.call(this, args[0]) + } + } else { + return f + } +} + +Given('a person with name', decorator(step, 'John')) +Given('a person named {word}', decorator(step)) + +Then('the same function is called for two distinct step definitions', function () { + expect(this.names).to.have.lengthOf(2) + expect(this.names).to.include.members(['John', 'Jack']) +}) |
