[rspec-devel] [Cucumber] --guess option to choose between Ambiguous step definitions when appropriate
Jake Howerton
jake.howerton at gmail.com
Fri Jan 30 13:18:34 EST 2009
Hey All,
I discussed this option with Aslak in #cucumber and think I convinced him of
its value ;) Please chime in with any thoughts.
This feature is currently available in my github fork here:
http://github.com/jakehow/cucumber/tree/master
Please pull and test if this matters to you or you are curious.
Way back in Story Runner ;), the order you defined your steps in mattered.
This allowed you to put steps in a specific order if you had more specific
steps that you wanted to match first. ( Aslak tells me this was a bad idea,
b/c different OS's order Dir[] differently). Either way I found it useful,
because it allows you to make a more specific step definition instead of
contorting your English in order to avoid multiple matches. Every time I sit
down with cucumber, I hit this issue, in cucumber you can at least make more
specific regex's, but this is also a pain, especially in complex situations.
Say we have two step definitions.
Then /the form has a field called: (.*)/
and
Then /the form has a field called: (.*) with value: (.*)/
By default this will raise a Cucumber::Multiple error because of the
ambiguousness of it from the regex standpoint. However, it is not really
ambiguous for the user who entered the step: Then the form has a field
called: name with value: Jake. My changes will pick the appropriate step,
when you have the --guess option turned on.
How it works:
There is ranking logic that gets invoked when the option is turned on:
- The step definition with the most capture groups wins
- If there are 2+ definitions with the same amount of capture groups, the
one with the shortest overall captured string length wins
- If there are still 2+ options the Ambiguous error is raised
I am pretty happy with how accurately this ranking works for how I intend to
use it, but it is not perfect. Let me know your thoughts about this, method
names, and my implementation ( which I think is pretty ugly atm).
Particularly, I had to inject the config option into StepMother, and had to
change some stubs in other specs in order to accomodate this.
Also it is probably slow b/c I test the matches multiple times, should this
be cached within the best_matches method body? Is there a better way to
select the top matches, etc.
Thanks,
Jake
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-devel/attachments/20090130/cf4bdda9/attachment.html>
More information about the rspec-devel
mailing list