Speccing the existance of an unchecked checkbox

Hey list,

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…

On Wed, Sep 3, 2008 at 6:56 AM, Bart Z. [email protected]
wrote:

any ideas?

Let’s say you want 10 checked and 5 unchecked. You could do this:

response.should have_tag(“input[type=checkbox]”, 15)
response.should have_tag(“input[type=checkbox][checked=checked]”, 10)

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

WDYT?

On 3 sep 2008, at 15:28, David C. wrote:

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.

thanks,
bartz

On Wed, Sep 3, 2008 at 8:38 AM, Matt W. [email protected] wrote:

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…

You might be interested in this:

On 3 Sep 2008, at 14:31, Bart Z. wrote:

A checked checkbox is easy,
any ideas?
response.should have_tag(“input[type=checkbox]”, 15)

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…

cheers,
Matt