From 0e8f395f7a9c422860f3f4c161788aca009d9889 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Mon, 24 Dec 2018 20:19:20 +0100 Subject: Create a branch with custom parameters --- type-parser/features/custom-type.feature | 14 +++++++++ type-parser/features/steps/custom-type.js | 48 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 type-parser/features/custom-type.feature create mode 100644 type-parser/features/steps/custom-type.js (limited to 'type-parser/features') diff --git a/type-parser/features/custom-type.feature b/type-parser/features/custom-type.feature new file mode 100644 index 0000000..8b74a0f --- /dev/null +++ b/type-parser/features/custom-type.feature @@ -0,0 +1,14 @@ +Feature: Custom parameter types + Scenario: + When I interpret "to be" as a type + Then true is true + And false is not true + + Scenario: + When a date 24.12.2018 is given + Then it gets converted to a Date object + + Scenario: + Given a regular expression matches this pattern + And it matches that pattern + Then the step definition should be called twice diff --git a/type-parser/features/steps/custom-type.js b/type-parser/features/steps/custom-type.js new file mode 100644 index 0000000..a200a9c --- /dev/null +++ b/type-parser/features/steps/custom-type.js @@ -0,0 +1,48 @@ +const { Before, Given, When, Then, defineParameterType } = require('cucumber') +const { expect } = require('chai') + +defineParameterType({ + name: 'tobe', + regexp: [ + /is/, + /is not/ + ], + transformer: x => x === 'is' +}) + +When('I interpret "to be" as a type', function () { +}) + +Then('true {tobe} true', function (predicate) { + expect(predicate).to.be.true +}) + +Then('false {tobe} true', function (predicate) { + expect(predicate).to.be.false +}) + +defineParameterType({ + name: 'date', + regexp: /\d{2}\.\d{2}\.\d{4}/ +}) + +When('a date {date} is given', function (dateString) { + const parts = dateString.split('.').reverse() + this.date = new Date(...parts) +}) + +Then('it gets converted to a Date object', function () { + expect(this.date).to.be.an.instanceof(Date) +}) + +Before(function () { + this.count = 0 +}) + +Given(/(a regular expression|it) matches (this|that) pattern/, function (_, _) { + ++this.count +}) + +Then('the step definition should be called twice', function () { + expect(this.count).to.equal(2) +}) -- cgit v1.2.3