Skip to content
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

ruby: introduce Gherkin::Query#parent_locations. #89

Merged
merged 1 commit into from
Sep 12, 2023

Conversation

botandrose
Copy link
Contributor

@botandrose botandrose commented Jan 18, 2023

🤔 What's changed?

Introduces a new Gherkin::Query#parent_locations method in the Ruby implementation.

Cucumber::Core::Compiler will use this method to tell Cucumber::Core::Test::Case the locations of its parent lines, such as Feature:, Background:, and Rule:, so that it will correctly match them during location filtering. This particular strategy was identified as potentially reasonable while pairing with @mattwynne.

⚡️ What's your motivation?

This is one part of a two-repo PR to resolve the last remaining bits of the regression described in cucumber/cucumber-ruby#1469

🏷️ What kind of change is this?

  • ⚡ New feature (non-breaking change which adds new behaviour)

📋 Checklist:

  • I agree to respect and uphold the Cucumber Community Code of Conduct
  • I've changed the behaviour of the code
    • I have added/updated tests to cover my changes.
  • [?] My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • [?] Users should know about my change
    • I have added an entry to the "Unreleased" section of the CHANGELOG, linking to this pull request.

I'm not sure about these last two, since this could be considered as internals from a high-level cucumber point-of-view, but a public-interface addition from the gem point-of-view. Thoughts?

@luke-hill
Copy link
Contributor

So I've had another quick scan of this @botandrose - I think firstly this probably "feels" like a major change, because you're refactoring a huge chunk of how features e.t.c. are updated (I know they're private), but this entire area is a private DSL essentially.

Looking at the code changes (Not spec), I actually think it all makes sense and is fine. Next step would be to review specs.

@luke-hill
Copy link
Contributor

@botandrose so I'm keeping you in the loop and working "semi" linearly. Are we saying this should / must go in first and be released before thinking about other fixes?

Copy link
Contributor

@luke-hill luke-hill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think by and large this might be the last review I do on this, and just go off a bit of faith as it's still a bit alien to me.

update_steps(background.steps)
parent_id = parent.respond_to?(:id) ? parent.id : parent.object_id # Cucumber::Messages::Feature doesn't have an id :(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I'm assuming this might need tweaking?

Copy link
Contributor Author

@botandrose botandrose Sep 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, the "correct" thing to do here would be to add a Cucumber::Messages::Feature#id method, to make it consistent with the rest of the message types, and then we could get rid of this workaround. It seems like an obvious hole to me. But it also seemed out of scope for this PR.

It seems to me that we have some options:

  1. I can push another commit adding C::M::F#id
  2. I can do a follow-up PR cleaning this up

I'm leaning towards 2 to avoid scope creep, but you're the boss! What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luke-hill Oh derp, 1 is impossible because its a different repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luke-hill I guess option 1 would be opening a PR on https://github.com/cucumber/messages , and waiting for that to be merged and released, and then we could merge and release this with a bumped requirement on that version, and then finally merge and release the cucumber-ruby-core PR with a bumped requirement on this.

Copy link
Contributor Author

@botandrose botandrose Sep 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luke-hill Ugh, and it looks like that code is all auto-generated. Adding an id to feature would change the data structure for ALL implementations of cucumber, not just the ruby one.

Maybe the simplest method would be to just use #object_id as the internal data structure key for both Feature and Rule. Or maybe just the object itself!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luke-hill Okay, I just pushed a commit that uses the object itself as the key instead, which ends up simplifying everything greatly, including removing the need for so many safe navigation operators. I'm happy with this if you are!

@botandrose
Copy link
Contributor Author

@luke-hill Yes, my cucumber-ruby-core PR is built on-top of this new API, so this has to land before that one can take advantage of it. And they are essentially a pair... without one, the other doesn't really make any sense.

@luke-hill
Copy link
Contributor

Approved CI to run. Think we're definitely 90% of the way there now. Sorry for the delay, I'm coming back after a long time off.

@botandrose
Copy link
Contributor Author

@luke-hill all good! I really appreciate your time on this and my other contributions throughout the years. Cucumber is my most used testing framework, as well, so again, your time and effort are very much appreciated

Copy link
Contributor

@luke-hill luke-hill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a changelog entry for this, we'll look into getting this approved and merged shortly.

Cucumber::Core::Compiler will use this to tell Cucumber::Core::Test::Case the
locations of its parent lines, such as `Feature:`, `Background:`, and `Rule:`,
so that it will correctly match them during location filtering.
@botandrose
Copy link
Contributor Author

@luke-hill Okay, added a changelog entry, rebased on current main, squashed, force-pushed. I think this is ready for merge!

Copy link
Contributor

@luke-hill luke-hill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for delays.

@luke-hill luke-hill merged commit f37bb92 into cucumber:main Sep 12, 2023
@aslakhellesoy
Copy link
Contributor

Hi @botandrose,

Thanks for your making your first contribution to Cucumber, and welcome to the Cucumber committers team! You can now push directly to this repo and all other repos under the cucumber organization! 🍾

In return for this generous offer we hope you will:

  • ✅ Continue to use branches and pull requests. When someone on the core team approves a pull request (yours or someone else's), you're welcome to merge it yourself.
  • 💚 Commit to setting a good example by following and upholding our code of conduct in your interactions with other collaborators and users.
  • 💬 Join the community Slack channel to meet the rest of the team and make yourself at home.
  • ℹ️ Don't feel obliged to help, just do what you can if you have the time and the energy.
  • 🙋 Ask if you need anything. We're looking for feedback about how to make the project more welcoming, so please tell us!

On behalf of the Cucumber core team,
Aslak Hellesøy
Creator of Cucumber

@luke-hill
Copy link
Contributor

This will go into the next major (v27), eta a week or so.

@botandrose botandrose deleted the parent_locations branch September 12, 2023 11:39
@botandrose
Copy link
Contributor Author

@luke-hill @mattwynne thanks to both of you for your help on this! When v27 is out the door I'll rebase the other PR.

@mattwynne
Copy link
Member

Thank you @botandrose!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants