-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
4.2, assert_select, substitution value regexes #19098
Comments
It still does. You just need to add quotes around the question mark: http://edgeguides.rubyonrails.org/4_2_release_notes.html#assert-select. |
Aha, thanks! I read those release notes (several times!) in trying to see if there was an issue covered by release notes, but since the release notes didn't specifically include an example of The docs I linked to above still need to be corrected, so their examples of substitution use quotes around the question mark, don't they? The examples in the docs will not work. |
And I have no idea how you can use quotation marks to make this example from the docs work:
The quotation marks seem only to apply when you are inside attribute brackets in the selector... is substitution now only supported inside attribute brackets? |
And actually I can't get them to work even inside an attribute selector. I try:
I get:
I think substitutions with regexes may in fact not be working? I can try to put together a demo reproduction, but I'm not sure the best way to make a demo repro for assert_select, if there's a way to make an isolated reproduction app that mocks a given response to be used against assert_select. Anyone have any hints? I think perhaps this issue should be re-opened. I don't think it's the quote issue. |
Oh, sorry, I wasn't being clear. You have to use double quotes. |
You're right about the documentation needing an update. Do you (or anyone else watching) want to submit a PR for that? The examples should be: assert_select %{[name="?"]}, /.+/
assert_select %{ol>li[id="?"]}, /item-\d+/ |
It is not working for me with double quotes either. I really don't think it's a quoting issue, I think it's an issue with regexes and substitution in assert_select.
Can you make substiution with a regex work? For me substitution with a literal works -- and does not in fact require quotes.
I think you are mistaken. Quotes are not in fact needed for However, |
I'm sorry, I should've looked more into this. I had completely forgotten the syntax had changed for 4.2. Here's an excerpt from the Rails Dom Testing documentation which has the right syntax: # # Use substitution values
# assert_select "ol>li:match('id', ?)", /item-\d+/
#
# # All input fields in the form have a name
# assert_select "form input" do
# assert_select ":match('name', ?)", /.+/ # Not empty
# end |
@fxn do you know why there's still documentation being generated for this here? The file was extracted in 4.2 and is empty: https://github.com/rails/rails/blob/29a10173e235ea495634de39f3dadd2da2e28fd4/actionpack/lib/action_dispatch/testing/assertions/selector.rb. |
Thanks @kaspth, let's see if I can succesfully figure out how to use that....
Worked! Okay. Note it's got nothing to do with quotes, the It would have been nice if this had been in the release notes somewhere, but ce la vie (and maybe it is somewhere I missed). I think it does need to be doc'd and the old wrong docs removed. I'm not sure how someone would ever figure this out without docs (or diving into the source/tests, I guess). Sorry, I don't think I can commit to a doc PR, I'm still not exactly clear on how this functionality works in general, and I'm a bit frustrated after having so much trouble getting my own tests to work in my own code. |
Oops, there IS a bug in the non-matched message though.
Passes, because I did have a link like that. However, if I change it to:
I get the test failure message:
That doesn't make any sense, does it? Shouldn't it say something like:
? |
I've fixed the misleading test failure message on Rails Dom Testing at rails/rails-dom-testing@f2a7eb4. Note, it won't be exactly as you want because converting Regexps to strings makes Ruby wrap it in (?-mix:REGEXP). But it's as close as we're going to get.
I'll look into updating the release notes tomorrow. @rafaelfranca can you ship a new version of the gem? I don't have access to it on RubyGems. |
@kaspth done |
I think the documentation says that assert_select still supports substitution values, and regex substitution values, in Rails 4.2.
When I try an example like the second one, however, I get:
Is there a way to still use substitution values with regexes? Alternately, is there another way to use assert_select to check for an element which has an attribute that matches a regex?
The text was updated successfully, but these errors were encountered: