[rspec-users] Specs for RJS HTML output NOT containing an element

Ashley Moran work at ashleymoran.me.uk
Thu Feb 15 10:42:34 EST 2007


Hi

I have an RJS template that renders a partial to update a page.  I  
just added a parameter to get passed into this partial to eliminate a  
row in the table it generates, but I can't find a way to test that  
the unwanted output is in fact missing.  should(_not)_have_tag  
doesn't work with RJS, and there's no should_not_have from assert  
select.

What I've just cobbled together is this addition to my spec_helper.rb:

     module Spec
       module Rails
         class AssertSelectWrapper
           def should_not_have(*opts)
             begin
               should_have(*opts)
             rescue Spec::Expectations::ExpectationNotMetError
             else
               fail_with("Expected no matching elements but at least  
one was detected.")
             end
           end
         end
       end
     end

     module ActionController
       class TestResponse
         def should_not_have(*opts)
           __assert_select_wrapper.should_not_have(*opts)
         end
       end
     end

Is there already a way of doing this, or a better (shorter) way than  
above?

Ashley


More information about the rspec-users mailing list