Following the latest campaign against imperative Cucumber stories in favour of declarative stories (see especially Dan North’s great article on domain languages), I’ve been trying to get more naturalistic language into my stories. However, it becomes very easy to run into step ambiguities, something that Cucumber can try to handle on its own with
--guess, but that I’d rather just resolve for it instead.
I’ve been trying to reuse human descriptions for page elements in selectors.rb to say that those elements described can themselves be seen. I want to be able to say any of the following:
I should see “blah” within the cart summary
I should see the 1st design within the cart summary
I should see the cart summary
“the cart summary” here is defined in selectors.rb as, for example:
However, when adding a simple implementation of a “I should see” step that used selectors, I ran into an ambiguity. Here are the ambiguous steps:
And here’s the type of error you’ll get:
I resolved the ambiguity with some use of negative look-ahead:
This says that the step should match “I should see …” steps, so long as they don’t contain the string “within” or have quotation marks. The “(?:” designates a non-capturing group, whereas the “(?!” designates a negative look-ahead.
While I’m on the subject, I think that the antipathy towards Pickle is misplaced. Pickle is great for keeping state about models in stories. However, using only the built-in steps is quite foolish, and will definitely end up in some unreadable stories.