Reputation: 1945
Is there any BDD tool for Scala supporting reusable parameterized Gherkin clauses?
I would like to be able to have the ability to use specs like these:
Given number 4 is entered
When "+" is pressed
And number -1 is entered
And "*" is pressed
And number 2 is entered
And "=" is pressed
Then result is 6
And I would like to define fixtures to Gherkin clauses differing by a parameter only once, something like:
scenario("(4+(-1)) * 2 = 6") {
given("number 4 is entered")
when("'+' is pressed")
and("number -1 is entered")
and("'*' is pressed")
and("number 2 is entered")
and("'=' is pressed")
then("result is 0")
}
Given definitions of clauses looking like as follows:
"number $number is entered" {
calculator.enter(number)
}
"'$key' is pressed" {
calculator.press(key)
}
"result is $number" {
assert(calculator.getDisplayedNumber === number)
}
I looked through ScalaTest and Specs manuals but I didn't find such feature. ScalaTest seems to be able to reuse the defined clause in a different scenario, but looks like it is not parameterised.
Do you know some tools that does support what I want, or e.g. some extensions to ScalaTest, or a way to extend it myself with such result?
Upvotes: 6
Views: 699
Reputation: 2399
We can find the following example in specs2 to implement Given When Then specs : https://github.com/etorreborre/specs2/blob/1.6/src/test/scala/org/specs2/examples/GivenWhenThenSpec.scala
Hope this will help.
Upvotes: 5