JavaScript Testing in Rails: Fast, Headless, In-Browser. Pick Any Three.

Larry Karnowski (Relevance, Inc.), Jason Rudolph (GitHub)
General
Location: Ballroom B
Average rating: ****.
(4.14, 69 ratings)

You wouldn’t consider developing a Rails application without having a solid test suite for your Ruby code, but you’ve somehow convinced yourself to cross your fingers and look the other way when it comes to JavaScript. It doesn’t have to be that way. In this session, you’ll learn how to apply test-driven and behavior-driven development to your unobtrusive JavaScript code in a Rails-friendly manner.

Historically, when selecting a JavaScript testing solution, you were forced to choose whether you wanted a framework that could run your tests in the browser or one that could only run your tests in a headless fashion. With the right combination of tools [1], you can enjoy the best of both worlds: fast, automation-friendly, and headless testing plus the ability to run your tests in whichever browser is acting up on any given day.

In this session, you’ll learn how to give your JavaScript code the testing love it deserves. We’ll tackle:

  • Choosing and configuring a JavaScript testing framework
  • Writing RSpec-style specifications for test-first JavaScript development
  • Adding jQuery, Prototype, or other libraries to the mix
  • Coding in true red-green-refactor fashion with TextMate
  • Running tests in the browser
  • Running JavaScript tests headlessly with Rake
  • Automating your tests with Continuous Integration

[1] http://github.com/relevance/javascript_testing

Photo of Larry Karnowski

Larry Karnowski

Relevance, Inc.

Larry Karnowski has been designing and developing software applications—mostly network management tools—for almost fifteen years. His biggest passion is solving problems for real people—creating user interfaces that let users kick ass. In addition to hard technical skills like Ruby, Java, etc., he brings experience in usability, product design, and uncovering what users really need.

Photo of Jason Rudolph

Jason Rudolph

GitHub

Jason Rudolph is a Principal at Relevance, a leading consultancy and training organization specializing in Ruby, Rails, Groovy, and Grails, and integrating them into enterprise environments. Jason has more than nine years of experience in developing software solutions for domestic and international clients of all sizes, including start-ups, Dow 30 companies, and government organizations. Jason holds a degree in Computer Science from the University of Virginia.

Comments on this page are now closed.

Comments

Picture of Jeff Wigal
Jeff Wigal
05/08/2009 8:27am PDT

This was a terrific session. What a novel concept, actually test the javascript code we’re writing :) It was great to see you guys do the live programming thing, not as many people did that as I would have though.

Picture of Larry Karnowski
Larry Karnowski
05/06/2009 7:46am PDT

@Marcus: We recommend not using Blue Ridge to test “glue code” where you’re just shuffling an event to a function. Instead you should unit test that target function. As such, whether it’s a simple “click” or “livequery click” shouldn’t make a difference.

If you really need to make sure that when your function (for example an Ajax call) creates a new DOM element that its new links/buttons are activated through LiveQuery, then I recommend using Watir or Selenium for a user-acceptance level test.

Picture of Larry Karnowski
Larry Karnowski
05/06/2009 7:43am PDT

@Ray: Thanks for the feedback, sorry the slides were hard to read.

@Nathaniel: Thanks! We practiced the live coding a lot, and it was a lot of fun. I’m starting to think most talks should be given by pairs.

Picture of Nathaniel Bibler
Nathaniel Bibler
05/05/2009 4:50pm PDT

Nice job guys and an excellent job of live demo/programming.

Picture of Marcus Derencius
Marcus Derencius
05/05/2009 2:38pm PDT

I really liked your session. Have you guys already tested any code using jquery.live or jquery.livequery?

Ray Baxter
05/05/2009 2:35pm PDT

Nice presentation with a clear story. The slides and the live-coding were hard to read. (This has been a problem in every session.)

Picture of Larry Karnowski
Larry Karnowski
04/29/2009 7:03am PDT

@Derek: We are definitely covering that.

Derek Kastner
04/28/2009 3:28pm PDT

I’m interested in a way to test JavaScript’s interaction with the DOM on a specific page from the command line (no GUI browser required). Any chance of seeing that?

News and Coverage
co-presented by Ruby Central, Inc. O'Reilly
  • Engine Yard
  • Heroku
  • Sun Microsystems
  • Blue Box Group
  • New Relic

Sponsorship Opportunities

For information on exhibition and sponsorship opportunities at RailsConf, contact Yvonne Romaine at yromaine@oreilly.com.

Download the RailsConf Sponsor/Exhibitor Prospectus

Media Partner Opportunities

Download the Media & Promotional Partner Brochure (PDF) for information on trade opportunities with O'Reilly conferences or contact mediapartners@ oreilly.com

Program Ideas

Post your suggestions for speakers, topics, and activities on the RailsConf wiki or send an email to rails-idea@oreilly.com.

Press and Media

For media-related inquiries, contact Maureen Jennings at maureen@oreilly.com.

Contact Us

View a complete list of RailsConf 2009 contacts.