Ruby implementation - #98
Conversation
There was a problem hiding this comment.
It looks like you're writing tests for each method. That isn't necessary.
Rather you can define a list of sources:
- "../testdata/attachments.ndjson"
- "../testdata/empty.ndjson"
- "../testdata/hooks.ndjson"
- "../testdata/minimal.ndjson"
- "../testdata/rules.ndjson"
- "../testdata/examples-tables.ndjson"
And a map of query functions queries of the form (Query query) -> /* execute some query and return the results*/. For example:
queries.put("findAllTestStepsStarted", (query) -> query.findAllTestStepsStarted().size());
Then take the product of sources and queries and for each of those populate a instance of the Query object with the messages from the source, and then apply the query function to the Query object.
Then you compare the result of query function to the ../testdata/<source>.<methodname>.results.json file.
The nice thing is that you can add methods to the queries list as you implement them.
|
Atm I'm copying over things that already exist. I'm well aware this is likely wrong. I just want to get what currently "works" in here and equivalent passing/failing. See https://github.com/cucumber/cucumber-ruby/tree/main/lib/cucumber/formatter/query for where I'm adapting things from for now. |
mpkorstanje
left a comment
There was a problem hiding this comment.
Some other nitpicks below, but I suppose those are there because this is WIP
|
|
||
| s.add_dependency 'cucumber-messages', '> 25', '< 30' | ||
|
|
||
| s.add_development_dependency 'cucumber', '~> 10.1' |
| s.metadata = { | ||
| 'bug_tracker_uri' => 'https://github.com/cucumber/query/issues', | ||
| 'changelog_uri' => 'https://github.com/cucumber/query/blob/main/CHANGELOG.md', | ||
| 'documentation_uri' => 'https://github.com/cucumber/query/blob/main/CONTRIBUTING.md', |
There was a problem hiding this comment.
Should be the read me I guess, not the contributors guide.
| def hook_id(test_step) | ||
| return @hook_id_by_test_step_id[test_step.id] if @hook_id_by_test_step_id.key?(test_step.id) | ||
|
|
||
| raise TestStepUnknownError, "No hook found for #{test_step.id} }. Known: #{@hook_id_by_test_step_id.keys}" |
There was a problem hiding this comment.
The design of the query object assumes that if something can't be found either an empty list, empty optional or null is returned. There are no methods that throw.
This is also why all the methods are name findX or findAllX or findZByX`.
That doesn't seem like a good idea. The query object is used by the xml, json, pretty formatters, ect. By using a different API the Ruby implementations of these will lose the resemblance to the Java and Javascript versions. That will make maintenance much harder. I think you'd be better of leaving that old query object in place, implement the new query object here, then migrate your users of the old query object over to the new query object instead. |
|
Removed WIP from title, marked PR as draft. |
mpkorstanje
left a comment
There was a problem hiding this comment.
Looks okay. What does the code coverage look like?
| # Given one Cucumber Message, find another. | ||
| # | ||
| # Queries can be made while the test run is incomplete - and this will naturally return incomplete results | ||
| # see <a href="https://github.com/cucumber/messages?tab=readme-ov-file#message-overview">Cucumber Messages - Message Overview</a> |
There was a problem hiding this comment.
I don't think html tags are valid in Ruby doc.
https://github.com/ruby/rdoc/blob/master/doc/markup_reference/rdoc.rdoc#multi-word-text-link
| find_test_steps_finished_by(message) | ||
| .map(&:test_step_result) | ||
| .max_by { |test_step_result| test_step_result_rankings[test_step_result.status] } | ||
| # Java code: "PREVIOUS".max(comparing(TestStepResult::getStatus, new TestStepResultStatusComparator())); |
There was a problem hiding this comment.
Comments like this can be cleaned up.
|
|
||
| def message_types | ||
| { | ||
| pickle_step: Cucumber::Messages::PickleStep, |
There was a problem hiding this comment.
Does Ruby have some sort of alias that lets you use the qualified name instead of the unqualified name? If so, this lookup table could be removed.
| attachments_by_test_run_hook_started_id[attachment.test_run_hook_started_id] << attachment if attachment.test_run_hook_started_id | ||
| end | ||
|
|
||
| def update_feature(feature) |
There was a problem hiding this comment.
I would suggest removing this method and it's dependencies for now. You won't need it unless you implement the naming strategy which is a long way away. It's also not testable without implementing the naming strategy so you can safe on some work here.
There was a problem hiding this comment.
Update @mpkorstanje we need this method and "some" type of handler (Even if it's a nil handler), to handle the metaprogrammed enumeration.
We've added in 2 more "dumb" handlers for undefined_parameter_type and source as well as a catchall method that'll bubble up a warning that things aren't updating.
Merging this in AS IS, as it's essentially RtM - but there's no need to rush anything out for this, so it can just sit until someone builds a new version. 16.1+
There was a problem hiding this comment.
Then why not use a nil handler? Dead and untested code just slow you down.
…w message type on envelopes
|
Note to viewers. CI is red whilst we move forward on messages being cut for a new major - Which would bring version parity in-line plus enable access to new methods |
|
Updated with latest main and fixed version requirements to pick up a new enough version of messages to facilitate this working. Should be green now |
…or new undefined ones
🤔 What's changed?
Just enough cucumber-query to satisfy the rerun formatter.
⚡️ What's your motivation?
Move code that was written inside Cucumber-ruby over to this library. Get a first release out that we can build on.
🏷️ What kind of change is this?
♻️ Anything particular you want feedback on?
Are we following standard patterns? Is this a good foundation to build on?
Checklist