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

David Chelimsky dchelimsky at gmail.com
Thu Feb 15 11:01:01 EST 2007


On 2/15/07, Ashley Moran <work at ashleymoran.me.uk> wrote:
> 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?

If you're using trunk (if you're not, there is a release candidate
coming in the next few days), you can do this:

response.should_not have_tag(...)

Cheers,
David

>
> Ashley
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list