1. Sep 10th, 2006

    assert_select and intuitive text matching

    logo.jpg

    [Special thanks to Jamie van Dyke who first pointed the problem to me and then helped test it.]

    Up until today, when you use assert_select with a text value, it would select all matching elements using the CSS selector, and then asserts that all matching elements have the same text value. For example:

    assert_select "p", "Welcome"
    

    This assertion fails if it finds one paragraph with the text “Welcome”, and another paragraph with a different text value.

    You can make the assertion succeed using the (undocumented) :content pseudo class, for example:

    assert_select "p:content(?)", "Welcome"
    

    It works, but it’s not intuitive. So I just rolled out a change that will make the first example work the way you expect it to.

    With the new behavior, assert_select will first select all the elements that match the CSS selector, then narrow the list to only those elements that match the text value, and finally assert the number of elements found. In this case, it will look for the paragraph, then for those paragraphs with the text value “Welcome”, and finally asserts that it found at least one.

    To get the new behavior: script/plugin update

    Your comment, here ⇓