I found myself trying to verify there are some non-checked checkboxes
in a template today, and am kinda stumped how to do it :).
A checked checkbox is easy, have_tag('input[type=checkbox]
[checked=checked]). But, an unchecked checkbox hasn’t got the checked
attribute at all. And as it so happens, I want to test for a number of
checked, and a number of unchecked checkboxes. So, just testing for
input[type=checkbox] would return the number of checked and
unchecked checkboxes…
any ideas?
bartz
ps: that’s prolly the most occurences of ‘check’ in a single email…
It’s not perfectly expressive, but a good example name would help:
it “should have 15 checkboxes, 10 checked, 5 unchecked” do
render “/path/to/file”
response.should have_tag(“input[type=checkbox]”, 15)
response.should have_tag(“input[type=checkbox][checked=checked]”, 10)
end
hasn’t got the checked attribute at all. And as it so happens, I
WDYT?
Yeah, that’s how I ended up doing it. Googled around a bit, and
apparently you cannot do something like input[type=checkbox][checked!
=checked].
I’ll file a ticket for assert_select.
I found myself trying to verify there are some non-checked checkboxes in
unchecked checkboxes…
it “should have 15 checkboxes, 10 checked, 5 unchecked” do
thanks,
bartz
I guess you could also consider putting response.body into a HPricot object
and doing something fancy with that.
IIRC, asset_select isn’t using HPricot which seems like a shame - I seem to
remember barking up this tree myself a few weeks ago…