Forum: RSpec rspecing rjs - form.reset('form')

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E7349346374a0c685bf8055b7977af5c?d=identicon&s=25 Andrei Erdoss (cautaro)
on 2008-12-11 05:36
(Received via mailing list)
Hello,
Ef0db53920b243d6758c2f6b1306df0d?d=identicon&s=25 Steve Ross (cwd)
on 2008-12-11 09:26
(Received via mailing list)
On Dec 10, 2008, at 10:27 AM, Andrei Erdoss 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?
E7349346374a0c685bf8055b7977af5c?d=identicon&s=25 Andrei Erdoss (cautaro)
on 2008-12-12 07:11
(Received via mailing list)
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?
Ef0db53920b243d6758c2f6b1306df0d?d=identicon&s=25 Steve Ross (cwd)
on 2008-12-12 08:08
(Received via mailing list)
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
This topic is locked and can not be replied to.