# \[ANN\] assert2 presents assert\_no\_rjs\_, and .should send\_js\_to

**URL:** <https://www.ruby-forum.com/t/ann-assert2-presents-assert-no-rjs-and-should-send-js-to/165301>\
**Category:** Rails\
**Created:** [April 11, 2009, 7:25pm UTC](https://www.ruby-forum.com/t/ann-assert2-presents-assert-no-rjs-and-should-send-js-to/165301 "2009-04-11T19:25:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [April 11, 2009, 7:25pm UTC](https://www.ruby-forum.com/t/ann-assert2-presents-assert-no-rjs-and-should-send-js-to/165301/1 "2009-04-11T19:25:27Z")

</div>

assert\_no\_rjs\_ now negates all the JavaScript assertions listed here:

[http://groups.google.com/group/rubyonrails-talk/browse\_thread/thread/49fd7c9b9107d577](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…😉

---

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [April 12, 2009, 6:33pm UTC](https://www.ruby-forum.com/t/ann-assert2-presents-assert-no-rjs-and-should-send-js-to/165301/2 "2009-04-12T18:33:11Z")

</div>

> assert\_no\_rjs\_ now negates all the JavaScript assertions listed here:
> 
> [http://groups.google.com/group/rubyonrails-talk/browse\_thread/thread/49fd7c9b9107d577](http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/49fd7c9b9107d577)

> (Sorry - no .should not\_send\_js\_to yet…😉

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

 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!

–  
Quark

---

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [April 12, 2009, 6:51pm UTC](https://www.ruby-forum.com/t/ann-assert2-presents-assert-no-rjs-and-should-send-js-to/165301/3 "2009-04-12T18:51:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [April 12, 2009, 6:55pm UTC](https://www.ruby-forum.com/t/ann-assert2-presents-assert-no-rjs-and-should-send-js-to/165301/4 "2009-04-12T18:55:28Z")

</div>

Brandon O. 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…

---

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [April 12, 2009, 9:54pm UTC](https://www.ruby-forum.com/t/ann-assert2-presents-assert-no-rjs-and-should-send-js-to/165301/5 "2009-04-12T21:54:33Z")

</div>

> …} }  
> 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
