Hi Everyone,
as the subject line states suggests, I was looking for ways to get rid of the callback argument in step definitions.
The reason for this is that my step definitions most of the time are either synchronous or they use promises for handling asynchronous execution.
In both cases, handling the callback in the step definitions adds extra code and technical complexity but it doesn't help the reader to understand the domain.
On the other hand there *are* situations where I want to handle the callback explicitly in the step definition. I just don't like being forced to do it, if I think it does not belong there.
Looking at how other tools (e.g. jasmine-node) solved a similar problem, I came up with a solution that I think is really neat, and I would like hear your thoughts on it:
It is basically a wrapper around the original step definition body that works by the following rules:
- The body expects the same number of arguments as are provided by the call, i.e. the body expects a callback argument --> assume the step wants to explicitly deal callback
- The body returns something that looks like a promise --> wire it up with the callback
- The body (synchronously) raises an exception --> Big deal, fail the step.
- The body does nothing of the above --> Assume a passing, synchronous step.
Check it out and let me know what you think.
Cheers,
--lu