cucumber/cucumber-jvm — pull request #357 by tryge (2012-07-06 09:08:20+00:00)
Title: [JavaBackend] apply advices to an existing step definition (AOP)

The Problem we're facing at my company is that we have to execute a step with some specified timings e.g.

When clock signals start, do something

or

When 3 seconds have passed, do something

etc.

We have several timing related phrases, up to now there were only 2 possibilities (that we know of) to express our intention without major effort

1. create several methods with different step definitions for all the "additional behaviour" it supports and then call the corresponding library method to do whatever this additional behaviour is (I guess that's how nested stepdefs are meant to be implemented)
2. have the timing on a different line (i.e. before and/or after the step)

The first solution creates a lot of unnecessary code, which will become a maintenance nightmare (our project is just about to begin, I anticipate a lot more "advices" to come).

The second solution is hard to read as the statements can't really be linked with When, And or But - also as we see it, it should be expressed as a single step not several.

Our solution adds the possibility to implement some behaviour as an advice and run the advised step within the advice. Also the step itself can control which advices can be applied (which is very important for us).

Best is probably to just look at the example in the tests directory (ExampleAdvice).

If you're interested in this feature we'll work towards a version you can accept.

Remarks:
- only one level of advice is supported at the moment (we don't need more, but we don't like arbitrary limits...)
- we had to expose the StepDefinition in StepDefinitionMatch in order to verify the pointcuts.