Placeholders not recognizeds by assert_select
everton opened this issue · 10 comments
Until Rails 4.1.6 I used placeholders to avoid quoting manually some attributes of #assert_select selector, like on this example:
assert_select 'form[action=?][method=?]', action, methodbut now it is generating this error:
ArgumentError: I don't understand what you're trying to matchwhich not happens when not using the placeholders:
assert_select "form[action='#{action}'][method='#{method}']"Will this placeholders feature be removed on stable 4.2.0 or is this a bug?
There never was a placeholders feature. What you're doing is an unintended side effect of how substitution values worked.
They've changed in Rails 4.2: https://github.com/rails/rails-dom-testing/blob/master/lib/rails/dom/testing/assertions/selector_assertions.rb#L161-L167
Sorry @kaspth, but if it was unintentional, I think I misunderstood this documentation:
"The selector may be a CSS selector expression (String), an expression with substitution values, or an HTML::Selector object."
# All input fields in the form have a name
assert_select "form input" do
assert_select "[name=?]", /.+/ # Not empty
endYou are looking the documentation of Rails < 4.2. This was changed now. See the new documentation @kaspth pointed.
Are you sure, @rafaelfranca ?
https://github.com/rails/rails-dom-testing/blob/master/lib/rails/dom/testing/assertions/selector_assertions.rb#L106-L107
Looks like the feature had change . So, now on, it'll only work with RegExp. Right?
Yes, it changed. But it should work with a string too. But you have to use :match operator. Are not string working with the :match operator?
This test in our test suite is passing:
render_html %Q{<div id="1">foo</div><div id="2">foo</div>}
assert_select "div[id=?]", "1" do |elements|
assert_equal 1, elements.size
endI didn't understood clearly how to deal with my example about the form using the :match selector.
If I use:
"form:match('action', ?):match('method', ?)"it always give me this error:
DEPRECATION WARNING: The assertion was not run because of an invalid css selector.About your test, it is exactly what we are using here, except that we are dealing with a (path) string on the attribute action and it is raising the error I reported:
ArgumentError: I don't understand what you're trying to match@everton it sounds to me that action or method is an unexpected class here, and it actually has nothing to do with whether you're using the ? or :match spelling in the selector.
@everton awesome!
From a quick look through history, it doesn't sound like symbols ever would've worked: rails/rails@3142502#diff-74f6318eecf03bd2173930ea13ad8202R213 -- so I guess this isn't a misbehaviour in previously-working-but-newly-upgraded code, as I'd originally inferred?
Anyway, if you're feeling adventurous, I think a PR to improve that exception message ("don't know how to match #{arg.class}", perhaps?) would be an excellent precaution for the next person to hit it.