-
-
Notifications
You must be signed in to change notification settings - Fork 690
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
Add gherkin query in Ruby #845
Conversation
This avoid generating the mesages twice, getting different IDs in the AST and so on.
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.
Looks cool. I can see how this would start giving us more powerful capabilities when it comes to the custom parts we can add post gherkin-9
update_feature(message.gherkin_document.feature) if message.gherkin_document | ||
end | ||
|
||
def get_location(ast_node_id) |
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.
are these methods "synched up" across all implementations. If they are that's cool. If not traditionally we would drop get_
and set_
prefixes in methods.
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.
We aim to have a consistent API between implementations, but I still think we should be idiomatic. Please change to location
.
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.
done
gherkin/ruby/lib/gherkin/errors.rb
Outdated
@@ -1,5 +1,7 @@ | |||
module Gherkin | |||
class ParserError < StandardError; end | |||
class AstNodeNotLocatedException < Exception; end |
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.
traditionally errors in ruby all end in error (I'm aware that there are existing ones here that don't), so it's not a biggie if you don't fix
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.
Custom exceptions should extend from StandardError
. Never extend Exception
.
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.
inheritance is done.
For the Error
vs Exception
, all (except ParserError
) are called XXXException
, so I went with the rest
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.
Makes sense for now yeh, top work though, this stuff should get gherkin 9 ready soon :)
gherkin/ruby/lib/gherkin/errors.rb
Outdated
@@ -1,5 +1,7 @@ | |||
module Gherkin | |||
class ParserError < StandardError; end | |||
class AstNodeNotLocatedException < Exception; end |
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.
Custom exceptions should extend from StandardError
. Never extend Exception
.
update_feature(message.gherkin_document.feature) if message.gherkin_document | ||
end | ||
|
||
def get_location(ast_node_id) |
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.
We aim to have a consistent API between implementations, but I still think we should be idiomatic. Please change to location
.
@@ -0,0 +1,54 @@ | |||
module Gherkin | |||
class Query |
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.
Rename the file to query.rb
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.
done
Note: I'm giving a bit more thoughts on I think |
which is there (#847) and in progress |
Summary
Like this was done in Gherkin-JS, this PR adds a simple GherkinQuery object that provides the
Location
objects of various AST nodes found inGherkinDocument
message after parsing.Also, it raises an exception when we iterate more than once on the messages. If we don't do so, we may end up with multiple AST node objects representing the same part of the
Gherkin
feature but with different IDs.This object will likely grow in the future (for example for finding the original
PickleStep
location), but this should already be enough to be used incucumber-ruby(-core)
.Maybe more will be added to this PR or in other ones when needed.
How Has This Been Tested?
With Unit tests
Screenshots (if appropriate):
Types of changes
Checklist: