Forum: RSpec How To Drive Out AJAX Functionality in Rails' Views?

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.
Lee (Guest)
on 2009-05-12 18:26
(Received via mailing list)
I am new to RSpec and have just started to drive out my first view
using a spec. I have used the The RSpec Book (beta) to do the basic
stuff like testing for the presence of a field but I am unsure where
to start for driving out some AJAX functionality.

In the view, I will have a text field that a user can enter a name
into and then click on a link to check the availability of this name
or otherwise. I plan to implement the check as an AJAX request,
returning an HTML snippet or 'available' or 'not available'.

I would appreciate some help on what sort of examples one might write
and the various mocks, stubs and helpers etc that can be used. Or
alternatively a pointer to some existing information/tutorials on this
topic.

Thanks.
Lee (Guest)
on 2009-05-12 19:12
(Received via mailing list)
My apologies! I posted twice by accident. Please see my other post on
this topic.
Zach D. (Guest)
on 2009-05-12 23:00
(Received via mailing list)
On Tue, May 12, 2009 at 8:31 AM, Lee <removed_email_address@domain.invalid>
wrote:
> I would appreciate some help on what sort of examples one might write
> and the various mocks, stubs and helpers etc that can be used. Or
> alternatively a pointer to some existing information/tutorials on this
> topic.

For end to end coverage you'll need to utilize something like Selenium
or Watir. Webrat has  built-in Selenium support which I know folks are
using successfully (we are at MHS). It is not as polished as the
simulated support that Webrat has using an in-memory DOM, but that is
starting to change. Selenium and Webrat have a bright future ahead
(and a little longer term so does Watir IIRC).

For isolated and/or complex client-side logic in JS you can utilize a
JS-based testing framework like Screw.Unit or JSSpec:

* http://github.com/nkallen/screw-unit/tree/master
* http://jania.pe.kr/aw/moin.cgi/JSSpec

Sorry I don't have any links to any tutorials, maybe others can
provide. For me it was a largely dive-in and figure it out with
Selenium a few years back, and I personally haven't taken the time to
dump what I've learned to the world. The RSpec Book will include a
chapter on automating Cucumber scenarios in the browser with Selenium,
although I know that chapter has not been released yet.

--
Zach D.
http://www.continuousthinking.com (personal)
http://www.mutuallyhuman.com (hire me)
@zachdennis (twitter)
This topic is locked and can not be replied to.