class Purchase(Story):
I.fetch_discount
when('has_discount') > I.apply_discount
In that case, we have :chicken: and :egg: problem.
fetch discount would set has_discount and discount variables.
apply discount expect discount to be not null domain object
if discount is null, apply discount would not be executed in any case
if discount exists, apply discount would run
What kind of contract we need to write for discount variable?
I could see couple of options here.
Make discount nullable, which would broke apply discount story expectation but would not have state union error
Raise validation error on first attribute access, not on attribute assign. We would need to have different variables for discount for different stories. Apply discount would never executed, so it would never access invalid discount variable, so validation error would not be raised.
Do not assign invalid discount in the first place. We would have if statement inside fetch discount method which would only assign has discount variable in case discount is null.
I suggest we document pattern number 3 from the list above and call it a day.
Let say we would have nested stories.
In that case, we have :chicken: and :egg: problem.
has_discount
anddiscount
variables.discount
to be not null domain objectI could see couple of options here.
I suggest we document pattern number 3 from the list above and call it a day.