assert2 presents assert_no_rjs_, and .should send_js_to

assert_no_rjs_ now negates all the JavaScript assertions listed here:

http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/49fd7c9b9107d577

And assert_rjs_ now works in RSpec:

     it 'should use Ajax to replace person 45' do
       xhr :get, :replace_person, :id => 45
       @response.body.should send_js_to(:replace_html, 'person_45') do
         strong 'person_45'
       end
     end

Once again, the do-end block calls Nokogiri::HTML::Builder to build a sample of HTML. The assertion then matches this to the HTML delivered in the payload of the JS Element.update() call.

The committee is unaware of any other RJS solution for RSpec...

(Sorry - no .should not_send_js_to yet..:wink:

assert_no_rjs_ now negates all the JavaScript assertions listed here:

http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/49fd7c9b9107d577

(Sorry - no .should not_send_js_to yet..:wink:

Version 0.5.1 fixes that: .should_not send_js_to

Next, assert_xhtml (and .should be_html_with) add the any! keyword:

     assert_xhtml do
       ul.kalika do
         any! 'Billings report'
       end
     end

It evaluates to the XPath * operator, so the above passes if any element below the <ul class='kalika'> contains any "Billings report".

This example fails if "Billings report" appears anywhere in the document (assuming we _reeally_ don't like it!;):

     assert_xhtml do
       without!{ any! /Billings report/ }
     end

If anyone can think of new features to add to (or take out of) these DSLs,
I'm all ears!

Phlip,

Is there any plan to allow for negative assertions (e.g., should_not
be_html_with)? I use this in a custom matcher, and can't think of a way to
support negative assertions unless be_html_with does.

I'm of course going by the output of negative_failure_message saying not to
use it that way.

Brandon

Brandon Olivares wrote:

Is there any plan to allow for negative assertions (e.g., should_not
be_html_with)? I use this in a custom matcher, and can't think of a way to
support negative assertions unless be_html_with does.

I can't think of a reason not to use .should be_html_with{ without!{ ...} }

And it seems that .should_not be_html_with() would, in theory, pass if a page weren't HTML...

From: rubyonrails-talk@googlegroups.com [mailto:rubyonrails-
talk@googlegroups.com] On Behalf Of Phlip
Sent: Sunday, April 12, 2009 12:54 PM
To: rubyonrails-talk@googlegroups.com
Subject: [Rails] Re: [ANN] assert2 presents assert_no_rjs_, and .should
send_js_to

I can't think of a reason not to use .should be_html_with{ without!{
...} }

It could, if I could determine whether the matcher was being called with
.should or .should_not. I don't know of a way to do this?

Anyway I'm excited about this new release. Thanks.

Brandon