Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Assert_Select problem with * selector

#1288

Given a response containing the following

<div id='cart'>
</div>

and the desire to test that my cart div is empty

The following don't work

assert_select("div#cart") do
  assert_select("*",0)
end

assert_select("div#cart", 0) do
  assert_select("*")
end

Whilst

assert_select("div#cart>*", 0)

does succeed.

Reported by diabolo · October 29th, 2008 @ 07:24 AM

State: invalid
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Frederick Cheung
    Frederick Cheung
    • State changed from new to invalid

    That is normal: when given a block assert_select tries to match the element specified (in this case div#cart) and then yields the matches. so you should be doing

    
    assert_select("div#cart") do |elements|
      elements.each {|element| assert_select("*",0)}
    end
    

    Your code on the other hand asserts that div#cart exists and then asserts that there are no elements at the top level rather than asserting that there are no elements that are children of the match.

    December 10th, 2008 @ 02:32 PM

  2. diabolo
    diabolo

    Ah that explains it - many thanks and apologies for submitting an invalid bug

    December 11th, 2008 @ 12:43 AM