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

Expand Substitution Matching Types support #90

Merged
merged 1 commit into from
Dec 14, 2020

Conversation

seanpdoyle
Copy link
Contributor

Add substitution support for Symbol and Numeric. It can be
convenient to pass in the value of an ActiveRecord::Base#id, or a
Symbol declared elsewhere in the test.

@kaspth
Copy link
Contributor

kaspth commented Dec 3, 2020

Dig it! Is there someplace we need to update the documentation too?

This was some of the first Rails related code I wrote way back in 2013 and now I shudder that I didn't just fix [id=?] instead of that :match('id', ?) monstrosity 😂

@seanpdoyle
Copy link
Contributor Author

@kaspth great question!

This repository seems light on documentation. I can't find any mention of substitutions in assertions in the README, and the link back to Rails is for the 4.2 release.

Is there somewhere in Rails that mentions substitutions?

@kaspth
Copy link
Contributor

kaspth commented Dec 3, 2020

It's documented here, it seems

# assert_select "div:match('id', ?)", /\d+/

Add substitution support for `Symbol` and `Numeric`. It can be
convenient to pass in the value of an `ActiveRecord::Base#id`, or a
`Symbol` declared elsewhere in the test.
# with substitution values (Array).
# Substitution uses a custom pseudo class match. Pass in whatever attribute you want to match (enclosed in quotes) and a ? for the substitution.
# assert_select returns nil if called with an invalid css selector.
#
# assert_select "div:match('id', ?)", "id_string"
# assert_select "div:match('id', ?)", :id_string
# assert_select "div:match('id', ?)", 1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kaspth is this what you had in mind?

@kaspth kaspth merged commit c0688b4 into rails:master Dec 14, 2020
@kaspth
Copy link
Contributor

kaspth commented Dec 14, 2020

Yes, that's it!

@seanpdoyle seanpdoyle deleted the substitution-types branch December 14, 2020 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants