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
Concise step definitions #132
Conversation
Hi, I agree that writing those regexes by hand is a pain. I always let Ecukes do the job for me, which makes it almost painless. Another idea is to allow the first argument to be a list. I'm thinking the way Flycheck works (see http://flycheck.readthedocs.org/en/latest/manual/extending.html#defining-new-syntax-checkers). It provides a DSL for defining checkers, with a few special keywords and support for (When "^I place the cursor between \"\\(.+\\)\" and \"\\(.+\\)\"$"
...) Could be written as: (When (line-start "I place the cursor between " (one-or-more char) " and " (one-or-more char) line-end)
...) What do you think? |
<< I always let Ecukes do the job for me, which makes it almost painless. I treat this as good advice. Will try to follow this way in the future. But right now, as I imagine, this will reduce flexibility. But will see how it will be going. In the meantime, I was thinking about another idea... To be able to write (besides step definitions) variable (keyword?) definitions so it will be possible just to put a keyword-pattern definition just before step definitions and be able to do not write patterns. In this way, there could be described (by unit test writer) some common keywords and they could be used within the tests. And step definitions could looks like I described before. Keyword def may looks like the following: But! My ideas comparing to idea with May this to be a part of ecukes? How? |
I don't think your idea is bad either. I like it more when there's an API to add your own definitions like you suggested. Let's say for example that your plugin works a lot with ip-addresses. I would be very nice to avoid that duplication. (When "^When I do something with IP-ADDRESS$"
(lambda (ip-address)
...
)) The downside with (When (rx line-start "I place the cursor between " (one-or-more char) " and " (one-or-more char) line-end)
...) |
Great! Will try What if I'll implement such possibility to define such keywords and use them within step definitions? Can such thing become as a part of ecukes? |
Definitely, I'm just discussing options here. A few comments: I'm not sure about what we should call this feature. You say key. Template is another alternative. What would be a good name..? How about making the templates a little more verbose, such as I don't think that Ecukes should have any pre defined templates. I just think that Ecukes should provide the functionality. Then packages such as Espuds can define these. And you can also define your own domain specific. We have to figure out a good name for the function that defines a template. For example: |
Well, I'm here with more thoughts and comments... What would be a good name..? Well, English is not my native language thus it is hard for me to choose correct name. But this is of course not the only reason. I'm continue thinking about feature name also and trying to wrap its essence by a notional terms :-) About more verbose templates, such as {IP-ADDRESS} or $ip-address. I've chose CAPITALIZED NAMES because they are very similar to the ARGUMENTS in the elisp doc-strings. When describing a step definition it may looks like the following:
And you see that TEXT and argument About {IP-ADDRESS} or $ip-address. Despite the fact (is that really the fact?) that such definitions seems (as for me) are a little bit aliens in the elisp world I like Well, in general, I becoming feel mixed feelings about this feature :-) My thoughts are not fluent about it, I still feel that I'm still not able think about it fluently and coherently. The mixing of regular expression and custom definitions in it still confuses me. In the meantime I'm continue thinking about For example,
or
(lets imagine that I, as a user of ecukes, am able to define (in mine *-steps.el file) Other example:
or (with the same meaning)
Well, this probably looks a little bit complicated but at least, I feel, the general picture is more consistent than in case of template way. What do you think? |
Ok, keyword is not bad at all actually.
I agree, makes more sense. It's prettier syntax and we really don't need to be that verbose.
Personally, I don't think that adding the
Yes, I'm thinking the same. Do you know if Cucumber has any similar feature? It might be worth checking that out and perhaps in such case use their approach. |
I agree, but I afraid about parsing issues, when user will use accidentally upper cased text in the step definition... However may be this is wrong fear.
I'm sorry, I didn't even know that there is such library as Cucumber (shame on me). I've read ecukes documentation and see the reference but didn't take a look... Currently I'm not lucky while looking for similar feature. But I'm not surprised because cucumber and its step definitions looks quite good as for me: regexps are not required there to be escaped. But, what else I wanted to say by means of Thus the original idea was to use these entities as widely as possible within ecukes. The reason is: they are pretty pronounced and I believe that such approach may help users to be allowed express theirs steps by means of short and precise terms which are very close to the real world (to the world of emacs). |
@@ -41,6 +41,13 @@ | |||
"^\\s-*|.+|" | |||
"Regexp matching table.") | |||
|
|||
(defconst ecukes-concise-keywords-alist | |||
'(("\\(?: \"\\(.*\\)\"\\|:\\)" . (" CONTENTS")) |
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.
You have a space before CONTENTS
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.
Yes. I didn't want this piece of code to be a part of ecukes. I left it to be fixed later.
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.
For now keywords are removed so this issue with CONTENTS seems is not actual any more. But in case it will be required to add it I have no idea how it could be fixed except:
make from step definitions with such complex regular expression two step definitions. So one of them accept "lorem ipsum strings" and another one py-strings.
Yes I agree, but we would still have to allow the user to define domain specific keywords, such as ip address. I will look at your implementation in more detail when I have the time and try it out on my projects. I do have a few quick comments if you want to start work on it directly:
|
(matches)) | ||
(dolist (keyword concise-keywords) | ||
(while (setq matches (s-match (format "[[:upper:]0-9-]+-%s" keyword) body)) | ||
(setq body (s-replace (nth 0 matches) regexp body))) |
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.
Why not (car matches)
?
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.
car
still not usual for me. But thanks! Fixed!
…and use them within a step definition.
I just committed new version. It is more better than previous one.
And I'm sorry, seems I skipped somehow yours last list of comments and didn't make appropriate fixes; And I put < What other keywords can we think of? Line is one that came to my mind. Sorry that I was boring with my last long comments... I somehow described there some ideas about keywords. But well, there was just examples. Other keywords could be:
Here is another question: would be |
And... I finally broke unit tests... Appropriate fix already committed.
My bad. This is required because without it |
And lastly (for today)... Again, please, any comments, suggestions, code reviews etc are much appreciated! |
…m `ecukes-parse.el' to the `ecukes-load.el'
|
Statute of limitations has run its course. |
While I was writing integration tests (using ecukes package) I was thinking how it could be possible to get rid regexps from step definitions.
For example there is such step definion:
My wish was to make it:
\"\\(.+\\)\"
;This feature request is a try to implement these desired things. It is rather about proof of concept than about final version.
This feature request contains the functionality by means of which it is possible to define steps in the following way:
The package treats such definition as usual:
^I translate \"\\(.+\\)\" from \"\\(.+\\)\" to \"\\(.+\\)\"$
The possibility to define a step definition in the usual way still remain:
There are special keywords are defined to be replaced by appropriate regexps. For example
CONTENTS
will be replaced by the\\(?: \"\\(.*\\)\"\\|:\\)
regexp,POSITION
(POS
orNUMBER
orNUM
) by\\([0-9]+\\)
andMODE
(VARIABLE
orVALUE
) by the\\(.+\\)
pattern. Capitalized words which contains in itself any mentioned keyword and separated by "-" will be also replaced by the appropriate regexp. For exampleLINE-NUM
orPOINT-POSITION
will be replaced by\\([0-9]+\\)
. The idea about capitalized words (separated by "-") was to make a correct decision (while replacing a keyword) by means of special endings (such asNUM
,POSITION
etc).In case of undefined keyword is used in step definition they replaces by default
\"\\(.+\\)\"
regexp pattern which matches any string. As for example, mentionedSOURCE-LANGUAGE
replaces by\"\\(.+\\)\"
.What do you think?