How odd, a first post that isn't the first post. It is in fact the second and most uninteresting post. The rSquery post was the first one. When I wrote it, we didn't have a blog at all, so I had to put it in a folder and wait till we did. To make it realistic, we've predated the previous post to the time when I effectively wrote it. So this post serves the only cause to inform you about the date this blog takes off ...
Enjoy!
Comments
Choosing the red pill and maybe we'll stay in wonderland ... *

The moment had to come eventually: we are proud to present our first gem, rSquery. A project that aims to reduce the pain involved in writing Selenium tests in rSpec environments for webapps that use jQuery.
The project contains several methods to help you with writing javascript commands for selenium and javascript based tests for Cucumber or maybe even rSpec in projects that use jQuery.
The name is made of the purposes:
- r - rSpec
- S - Selenium
- query - jQuery
History
The project's origin lies in a project I work on at by2.be which makes use of jQuery for most of its tasks. Selenium tests were the only way to test this bugger (as webrat isn't an option to test js actions) and these tests were taking all the speed and fun out of the project. Testing with jquery matchers instead of those provided by selenium sounded very handy and after some hours of frustration we hacked these few lines together and because of the enormous speed enhancements in writing tests I decided to wrap things up in a gem and release them to whoever would like to use jQuery matchers in an easy way to handle tests.
How it works
The source code is so short it should speak for itself but let me explain the concept:
Everything works around a central jQuery matcher you call with 'jquery(matcher)'. If you leave out 'matcher' the matcher returns the whole document.
The matcher must match exactly one element or it will raise an error. This behaviour makes testing easier for me, but I'm still in search of a better idea here. For now it does the job. (If you have ideas, let me know! Or fork the project on github)
You can call methods upon the matched jquery object: wait_for_element(matcher), wait_for_text(text), wait_for_visible, wait_for_invisible.
Other methods will call that same method upon the jquery. Example: jquery("#content").html will call $("#content").html() in the page you're testing and return what that method returns.
Examples
Using the gem in a project with jQuery you can use lines like these inside tests:
Pitfalls
- rSquery only works if jQuery is activated on the page you test (obviously).
- rSquery can only do tests that are purely javascript based. Clicking links will not work, use normal Selenium commands for triggering js-less events (just like jQuery itself).
requirements
- rSpec
- Cucumber
- Ruby-Selenium
Image
Image from http://feedingthepuppy.typepad.com/feeding_the_puppy/
Comments