|
| 1 | +Feature: Parameter types |
| 2 | + |
| 3 | + Users can define their own parameter types to be used in Cucumber expressions. |
| 4 | + Custom parameter types can be used to match certain patterns, and optionally to |
| 5 | + transform the matched value into a custom type. |
| 6 | + |
| 7 | + Background: |
| 8 | + Given a file named "features/particular_steps.feature" with: |
| 9 | + """ |
| 10 | + Feature: a feature |
| 11 | + Scenario: a scenario |
| 12 | + Given a particular step |
| 13 | + """ |
| 14 | + Given a file named "features/step_definitions/my_steps.js" with: |
| 15 | + """ |
| 16 | + import assert from 'assert' |
| 17 | + import {defineSupportCode} from 'cucumber' |
| 18 | +
|
| 19 | + defineSupportCode(({Given}) => { |
| 20 | + Given('a {param} step', function(param) { |
| 21 | + assert.equal(param, 'PARTICULAR') |
| 22 | + }) |
| 23 | + }) |
| 24 | + """ |
| 25 | + |
| 26 | + Scenario: sync transform (success) |
| 27 | + Given a file named "features/support/transforms.js" with: |
| 28 | + """ |
| 29 | + import {defineSupportCode} from 'cucumber' |
| 30 | +
|
| 31 | + defineSupportCode(({defineParameterType}) => { |
| 32 | + defineParameterType({ |
| 33 | + regexp: /particular/, |
| 34 | + transformer: s => s.toUpperCase(), |
| 35 | + typeName: 'param' |
| 36 | + }) |
| 37 | + }) |
| 38 | + """ |
| 39 | + When I run cucumber.js |
| 40 | + Then the step "a particular step" has status "passed" |
| 41 | + |
| 42 | + Scenario: sync transform (success) using deprecated addTransform API |
| 43 | + Given a file named "features/support/transforms.js" with: |
| 44 | + """ |
| 45 | + import {defineSupportCode} from 'cucumber' |
| 46 | +
|
| 47 | + defineSupportCode(({addTransform}) => { |
| 48 | + addTransform({ |
| 49 | + captureGroupRegexps: /particular/, |
| 50 | + transformer: s => s.toUpperCase(), |
| 51 | + typeName: 'param' |
| 52 | + }) |
| 53 | + }) |
| 54 | + """ |
| 55 | + When I run cucumber.js |
| 56 | + Then the step "a particular step" has status "passed" |
| 57 | + |
| 58 | + Scenario: sync transform (error) |
| 59 | + Given a file named "features/support/transforms.js" with: |
| 60 | + """ |
| 61 | + import {defineSupportCode} from 'cucumber' |
| 62 | +
|
| 63 | + defineSupportCode(({defineParameterType}) => { |
| 64 | + defineParameterType({ |
| 65 | + regexp: /particular/, |
| 66 | + transformer: s => { |
| 67 | + throw new Error('transform error') |
| 68 | + }, |
| 69 | + typeName: 'param' |
| 70 | + }) |
| 71 | + }) |
| 72 | + """ |
| 73 | + When I run cucumber.js |
| 74 | + Then it fails |
| 75 | + And the step "a particular step" failed with: |
| 76 | + """ |
| 77 | + transform error |
| 78 | + """ |
| 79 | + |
| 80 | + Scenario: no transform (error) |
| 81 | + Given a file named "features/support/transforms.js" with: |
| 82 | + """ |
| 83 | + import {defineSupportCode} from 'cucumber' |
| 84 | +
|
| 85 | + defineSupportCode(({defineParameterType}) => { |
| 86 | + defineParameterType({ |
| 87 | + regexp: /particular/, |
| 88 | + typeName: 'param' |
| 89 | + }) |
| 90 | + }) |
| 91 | + """ |
| 92 | + When I run cucumber.js |
| 93 | + Then it fails |
| 94 | + And the step "a particular step" failed with: |
| 95 | + """ |
| 96 | + AssertionError: 'particular' == 'PARTICULAR' |
| 97 | + """ |
| 98 | + |
| 99 | + Scenario: async transform (success) |
| 100 | + Given a file named "features/step_definitions/particular_steps.js" with: |
| 101 | + """ |
| 102 | + import {defineSupportCode} from 'cucumber' |
| 103 | + import Promise from 'bluebird' |
| 104 | +
|
| 105 | + defineSupportCode(({defineParameterType}) => { |
| 106 | + defineParameterType({ |
| 107 | + regexp: /particular/, |
| 108 | + transformer: s => Promise.resolve(s.toUpperCase()), |
| 109 | + typeName: 'param' |
| 110 | + }) |
| 111 | + }) |
| 112 | + """ |
| 113 | + When I run cucumber.js |
| 114 | + Then the step "a particular step" has status "passed" |
| 115 | + |
| 116 | + Scenario: async transform (error) |
| 117 | + Given a file named "features/step_definitions/particular_steps.js" with: |
| 118 | + """ |
| 119 | + import {defineSupportCode} from 'cucumber' |
| 120 | + import Promise from 'bluebird' |
| 121 | +
|
| 122 | + defineSupportCode(({defineParameterType}) => { |
| 123 | + defineParameterType({ |
| 124 | + regexp: /particular/, |
| 125 | + transformer: s => Promise.reject(new Error('transform error')), |
| 126 | + typeName: 'param' |
| 127 | + }) |
| 128 | + }) |
| 129 | + """ |
| 130 | + When I run cucumber.js |
| 131 | + Then it fails |
| 132 | + And the step "a particular step" failed with: |
| 133 | + """ |
| 134 | + transform error |
| 135 | + """ |
0 commit comments