1
0

reuse: Apply function with Ramda and Lodash

This commit is contained in:
Eugen Wissner 2019-01-03 06:11:13 +01:00
parent 54fcfda40a
commit 48a1f3756b
7 changed files with 78 additions and 29 deletions

View File

@ -3,3 +3,13 @@ Feature:
Given a person with name
And a person named Jack
Then the same function is called for two distinct step definitions
Scenario:
Given a person with a first name
And a person with the first name Jack
Then the first names are collected by the same function
Scenario:
Given a person with a last name
And a person with the last name Doe
Then the last names are collected by the same function

View File

@ -0,0 +1,15 @@
import { Before, Given, Then } from 'cucumber'
import { expect } from 'chai'
import _ from 'lodash'
function step (name) {
this.names.push(name)
}
Given('a person with a first name', _.partial(step, 'John'))
Given('a person with the first name {word}', step)
Then('the first names are collected by the same function', function () {
expect(this.names).to.have.lengthOf(2)
expect(this.names).to.include.members(['John', 'Jack'])
})

View File

@ -0,0 +1,15 @@
import { Before, Given, Then } from 'cucumber'
import { expect } from 'chai'
import R from 'ramda'
function step (name) {
this.names.push(name)
}
Given('a person with a last name', R.partial(step, ['Junior']))
Given('a person with the last name {word}', R.partial(step, []))
Then('the last names are collected by the same function', function () {
expect(this.names).to.have.lengthOf(2)
expect(this.names).to.include.members(['Junior', 'Doe'])
})

View File

@ -1,10 +1,6 @@
import { Before, Given, Then } from 'cucumber'
import { expect } from 'chai'
Before(function () {
this.names = []
})
function step (name) {
this.names.push(name)
}

View File

@ -0,0 +1,5 @@
import { setWorldConstructor } from 'cucumber'
setWorldConstructor(function () {
this.names = []
})

View File

@ -625,6 +625,16 @@
"regexpu-core": "^4.1.3"
}
},
"@babel/polyfill": {
"version": "7.2.5",
"resolved": "https://registry.npmjs.org/@babel/polyfill/-/polyfill-7.2.5.tgz",
"integrity": "sha512-8Y/t3MWThtMLYr0YNC/Q76tqN1w30+b0uQMeFUYauG2UGTR19zyUtFrAzT23zNtBxPp+LbE5E/nwV/q/r3y6ug==",
"dev": true,
"requires": {
"core-js": "^2.5.7",
"regenerator-runtime": "^0.12.0"
}
},
"@babel/preset-env": {
"version": "7.2.3",
"resolved": "https://registry.npmjs.org/@babel/preset-env/-/preset-env-7.2.3.tgz",
@ -784,16 +794,6 @@
"util.promisify": "^1.0.0"
}
},
"babel-runtime": {
"version": "6.26.0",
"resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz",
"integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=",
"dev": true,
"requires": {
"core-js": "^2.4.0",
"regenerator-runtime": "^0.11.0"
}
},
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
@ -967,13 +967,13 @@
}
},
"cucumber": {
"version": "5.0.3",
"resolved": "https://registry.npmjs.org/cucumber/-/cucumber-5.0.3.tgz",
"integrity": "sha512-FsOKcEquPTVzK2sDqshI3Bw8ETztNIrMQ5+Ph8Z8QNaStl7cvIS3M9/T+9zeXvadPJX0jUWkbWcJ91x4gBw9Fg==",
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/cucumber/-/cucumber-5.1.0.tgz",
"integrity": "sha512-zrl2VYTBRgvxucwV2GKAvLqcfA1Naeax8plPvWgPEzl3SCJiuPPv3WxBHIRHtPYcEdbHDR6oqLpZP4bJ8UIdmA==",
"dev": true,
"requires": {
"@babel/polyfill": "^7.2.3",
"assertion-error-formatter": "^2.0.1",
"babel-runtime": "^6.11.6",
"bluebird": "^3.4.1",
"cli-table3": "^0.5.1",
"colors": "^1.1.2",
@ -994,7 +994,7 @@
"mz": "^2.4.0",
"progress": "^2.0.0",
"resolve": "^1.3.3",
"serialize-error": "^2.1.0",
"serialize-error": "^3.0.0",
"stack-chain": "^2.0.0",
"stacktrace-js": "^2.0.0",
"string-argv": "0.1.1",
@ -1418,8 +1418,7 @@
"lodash": {
"version": "4.17.11",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
"integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==",
"dev": true
"integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg=="
},
"loose-envify": {
"version": "1.4.0",
@ -1660,6 +1659,11 @@
"integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==",
"dev": true
},
"ramda": {
"version": "0.26.1",
"resolved": "https://registry.npmjs.org/ramda/-/ramda-0.26.1.tgz",
"integrity": "sha512-hLWjpy7EnsDBb0p+Z3B7rPi3GDeRG5ZtiI33kJhTt+ORCd38AbAIjB/9zRIUoeTbE/AVX5ZkU7m6bznsvrf8eQ=="
},
"regenerate": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.0.tgz",
@ -1676,9 +1680,9 @@
}
},
"regenerator-runtime": {
"version": "0.11.1",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz",
"integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==",
"version": "0.12.1",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz",
"integrity": "sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg==",
"dev": true
},
"regenerator-transform": {
@ -1761,9 +1765,9 @@
"dev": true
},
"serialize-error": {
"version": "2.1.0",
"resolved": "http://registry.npmjs.org/serialize-error/-/serialize-error-2.1.0.tgz",
"integrity": "sha1-ULZ51WNc34Rme9yOWa9OW4HV9go=",
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/serialize-error/-/serialize-error-3.0.0.tgz",
"integrity": "sha512-+y3nkkG/go1Vdw+2f/+XUXM1DXX1XcxTl99FfiD/OEPUNw4uo0i6FKABfTAN5ZcgGtjTRZcEbxcE/jtXbEY19A==",
"dev": true
},
"shebang-command": {

View File

@ -14,6 +14,10 @@
"@babel/register": "^7.0.0",
"babel-loader": "^8.0.4",
"chai": "^4.2.0",
"cucumber": "^5.0.3"
"cucumber": "^5.1.0"
},
"dependencies": {
"lodash": "^4.17.11",
"ramda": "^0.26.1"
}
}