-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for string-based matchers for step definitions. #48
Conversation
Format example: - 'I increment the variable by %d' - 'I enter %s into firstname and %s into lastname'
I'm not an expert on regular expressions, but i do agree with you about keeping the syntax the same as the ruby version of cucumber. I think that matching for numbers/strings etc can be usefull in some situations where you build your logic for a certain datatype and when specs change, you know immediatly that your steps are being skipped because the parameter does not map to a single step. How does the ruby version of cucumber handle string-based matchers? Perhaps it is the best to keep the feature the same. |
I think $-variables are simply matching any string of non-whitespace characters. Basically, it maps to When one needs smarter step arguments, transforms are generally a nice way to go. It allows for both matching group reuse and typecasting. NUMBER = Transform /^(\d+)$/ do |number|
return number.to_i
end
Given /^I have #{NUMBER} cucumbers$/ do |cucumber_count|
# cucumber_count is an integer, not a string
end But of course, this is all based on regexps. |
I agree, the name in the $ should not mean anything (unless someone really wants it, like in your example). Do you want me to rewrite the code so it can use $ANYTHING and replace that with ([^\s]*) or something? |
Sure, that'd be a nice addition. |
Example: - 'I incremend the variable by $VAR1' - 'I enter $var into firstname and $var2 into lastname'
I have added the simpler matcher that matches on parameters with a $. Step usage: Feature: |
Great, thank you Ted. I'm thinking it would be a good idea to introduce a "step definition pattern" that would encapsulate the string/regexp of the step definition. Also we need some tests for this ;) Are you up to it? |
While a "step definition pattern" isn't a bad idea, perhaps that would overengineer it. What kind of tests do you have in mind? |
As soon as we're dealing with a "multi-type" variable, I smell a need for encapsulation. Additionally, I try to keep constructors a simple as possible. They're then easier to test and much less responsible for business logic. Regarding the tests, there are both features and specs. Cucumber.js is passing the cucumber-tck feature suite entirely when run from both Cucumber-ruby and Cucumber.js in addition to a few features specific to it. But again, I can help on this if you want. |
Okay. I would really appreciate the help, im not familiar with ruby and i dont know how to properly run those .tck spec tests. |
I have added a testfeature that now passes in the cucumber-tck suite (running npm test). Rewriting the code should be safe now :). |
Will you implement this feature in cucumber-js? |
@tdekoning Don't worry, I will. I'm quite busy preparing my talks at CukeUp!, among other things. I should be able to take care of it in ~two weeks or so. I'm sorry for this rather long delay. Stay tuned! |
@@ -34,6 +34,7 @@ Cucumber.js is still a work in progress. Here is its current status. | |||
| [Undefined steps](https://github.com/cucumber/cucumber-tck/blob/master/undefined_steps.feature) | Done | | |||
| [Wire protocol](https://github.com/cucumber/cucumber-tck/blob/master/wire_protocol.feature) | To do | | |||
| [World](https://github.com/cucumber/cucumber-tck/blob/master/world.feature) | Done | | |||
| [String defined step definitions](https://github.com/cucumber/cucumber-tck/blob/master/stringdefined.feature) | Done | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no such feature in cucumber-tck. Do you have it on your local repo?
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Format example:
Regexp support in step-definitions are still working as they should.