I have a "when" in JBehave which under certain circumstances should throw an exception. I cant find any documentation, however, on how to handle this. Here is my scenario:
given a game with 6 existing bets and the game's max bets are 6 when a user places a bet
there's no then, since I want an exception thrown when the user places the bet.
Keep in mind, I don't always want the when to throw an exception. E.g. when the existing bets are less than max bets. In that case, I want to do some ensuring in the "then".
As there are no answers yet, I will give it a try. The way I do this is by storing the exception as part of the Steps` implementation's internal state:
This works well for me, but requires careful state management.
Implementation Details and "Computer-ese" Don't Belong in Scenarios
My understanding of BDD is that it is stakeholder-focused, allowing non-technical people to write what a system is supposed to do, using (more-or-less) natural language, in a way that developers can code to:
It extends TDD by writing test cases:
That said, a stakeholder would never write "throw an exception" in a "Then". They'd probably write:
or
We have used the pattern suggested by Nils Wloka, very valid answer, capture the exception in "When" using try --> catch and then validate against expected exception in "Then" step.