A few months ago I blogged about tags in cucumber-c++. The scenario I presented involved using tags to call a
BEFORE hook before the first scenario and an
AFTER hook after the last scenario. The code looked a little bit like this:
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5
The scnenario labeled
@first would call the corresponding
BEFORE macro and the
@last scenario would call the
AFTER macro. If I didn’t have tags in place, the macros would have both been invoked before/after each scenario. Macros for
AROUND_STEP are also available;
BEFORE_STEP allows you to tag individual steps and
AROUND_STEP acts as a before/after for individual steps.
This was a workaround. What I really wanted to do was to not use tags, and instead unconditionally perform an action before the first scenario was run and after the last scenario is complete. Since cucumber-cpp is open source, I decided to implement that a few weeks ago (see changeset). Now the above example becomes:
1 2 3 4 5 6 7 8
1 2 3 4 5
This is the same behavior as the first example, except I don’t have to force my fellow developers to move tags around when they add/remove scenarios. Also now my fellow developers can stop asking me why I was using tags and why when they added a scenario they couldn’t get the tests to pass.
The moral of the story is that you should go implement that feature you want to see in your favorite open source project.