# Rspecing rjs - form.reset('form')

**URL:** <https://www.ruby-forum.com/t/rspecing-rjs-form-reset-form/155372>\
**Category:** RSpec\
**Created:** [December 11, 2008, 5:36am UTC](https://www.ruby-forum.com/t/rspecing-rjs-form-reset-form/155372 "2008-12-11T05:36:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cautaro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/dbc845/32.png) [@cautaro](https://www.ruby-forum.com/u/cautaro)\
**Post date:** [December 11, 2008, 5:36am UTC](https://www.ruby-forum.com/t/rspecing-rjs-form-reset-form/155372/1 "2008-12-11T05:36:12Z")

</div>

Hello,

---

<div class="post-metadata">

**Author:** ![cautaro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/dbc845/32.png) [@cautaro](https://www.ruby-forum.com/u/cautaro)\
**Post date:** [December 11, 2008, 9:26am UTC](https://www.ruby-forum.com/t/rspecing-rjs-form-reset-form/155372/2 "2008-12-11T09:26:46Z")

</div>

On Dec 10, 2008, at 10:27 AM, Andrei E. wrote:

> –  
> Andrei

I tend not to use rjs much, but what I suspect you are looking for is  
the response to contain a particular snippet of Javascript. So, it  
might look sort of like:

it “should send Javascript to reset the form” do  
post :action\_that\_resets\_the\_form  
response.should have\_text(/$(‘form’).reset()/)  
end

Does this sound like what you are looking for?

---

<div class="post-metadata">

**Author:** ![cautaro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/dbc845/32.png) [@cautaro](https://www.ruby-forum.com/u/cautaro)\
**Post date:** [December 12, 2008, 7:11am UTC](https://www.ruby-forum.com/t/rspecing-rjs-form-reset-form/155372/3 "2008-12-12T07:11:58Z")

</div>

Thank you for your help. I still need a bit of help on calling have\_text  
correctly.

I tried your version and it failed. Then I tried a couple of variations  
of  
this:

response.should have\_text(/$(‘Form’).reset(“tag\_form”)/) but I got  
this  
error message:

expected /$(‘Form’).reset(“tag\_form”)/, got  
“Element.update(“tag\_list”,  
“”);\nElement.toggle(“add\_tag”);\nElement.toggle(“new\_tag”);\nForm.reset(“tag\_form”);”

Also tried:

response.should have\_text(/Form.reset(“tag\_form”)/) That also failed.  
Any  
ideas?

---

<div class="post-metadata">

**Author:** ![cautaro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/dbc845/32.png) [@cautaro](https://www.ruby-forum.com/u/cautaro)\
**Post date:** [December 12, 2008, 8:08am UTC](https://www.ruby-forum.com/t/rspecing-rjs-form-reset-form/155372/4 "2008-12-12T08:08:46Z")

</div>

What you are looking for is the string:

Form.reset(“tag\_form”)

Ignore the escaping backslashes in the output from the matcher. To  
tell have\_text that it can appear anyplace in the body of the  
response, use the regex /Form.reset(“tag\_form”)/ in your call to  
have\_text.

So, this should work:

response.should have\_text(/Form.reset(“tag\_form”)/)

Hope this works for you. Oh, and you might want to branch out and make  
sure that the content-type is text/javascript.

-s
