This project is archived and is in readonly mode.

#1288 ✓invalid
diabolo

Assert_Select problem with * selector

Reported by diabolo | October 29th, 2008 @ 07:24 AM | in 2.x

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.

Comments and changes to this ticket

  • Frederick Cheung

    Frederick Cheung December 10th, 2008 @ 02:32 PM

    • 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.

  • diabolo

    diabolo December 11th, 2008 @ 12:43 AM

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

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages