Quick and dirty deny_select

Posted on June 24, 2007

I’ve just been learning how incredibly powerful Test First Development is in Rails – being able to test for elements on the dom using assert_select is fantastico!

However I note that there’s no opposite – a deny_select if you will. Something that will test to see if a given element does NOT exist.

Here’s one I cooked up earlier:


  def deny_select(element, message)
    assert_select element, false, message
  end

Use it by passing in the css element id and the message if the assertion fails like this:


  deny_select 'table.calendar', "Calendar should not be on page"