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