step {cucumber} | R Documentation |
Define a step
Description
Provide a description that matches steps in feature files and the implementation function that will be run.
Usage
given(description, implementation)
when(description, implementation)
then(description, implementation)
Arguments
description |
A description of the step. A simple version of a Cucumber expression.
The description is used by the |
implementation |
A function that will be run when the step is executed.
The implementation function should always have the last parameter named If a step has a description If a table or a docstring is defined for a step, it will be passed as an argument after plceholder parameters
and before |
Details
Placeholders in expressions are replaced with regular expressions that match values in the feature file.
The regular expressions are generated during runtime based on defined parameter types.
The expression "I have {int} cucumbers in my basket"
will be converted to
"I have [+-]?(?<![.])[:digit:]+(?![.]) cucumbers in my basket"
. The extracted value of {int}
will be passed to the implementation function after being transformed with as.integer
.
To define your own parameter types use define_parameter_type
.
Value
A function of class step
, invisibly. Function should be called for side effects.
See Also
Examples
given("I have {int} cucumbers in my basket", function(n_cucumbers, context) {
context$n_cucumbers <- n_cucumbers
})
given("I have {int} cucumbers in my basket and a table", function(n_cucumbers, table, context) {
context$n_cucumbers <- n_cucumbers
context$table <- table
})
when("I eat {int} cucumbers", function(n_cucumbers, context) {
context$n_cucumbers <- context$n_cucumbers - n_cucumbers
})
then("I should have {int} cucumbers in my basket", function(n_cucumbers, context) {
expect_equal(context$n_cucumbers, n_cucumbers)
})