• Engine Yard
  • LivingSocial
  • VMware
  • Heroku
  • Rackspace Hosting
  • Blue Box Group
  • JetBrains
  • New Relic
  • Percona
  • Pivotal Labs
  • Rails Dog
  • WyeWorks
  • Chargify

Sponsorship Opportunities

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

Download the RailsConf Sponsor/Exhibitor Prospectus

Contact Us

View a complete list of RailsConf contacts.

Why Can't I Test My JavaScript?

Greg Moeck (Strobe, Inc.)
General
Location: Ballroom IV
Average rating: ***..
(3.70, 20 ratings)

The world of web development is changing. As Avi Bryant pointed out at Golden Gate Ruby Conference 2010, more and more development is getting pushed into the client, which means that more and more of our applications are being written in JavaScript. However one of the major problems that Ruby/Rails developers face as more and more logic is pushed into the client is how do we maintain our disciplines? How do we keep writing high quality maintainable code when we have to work in another environment?

The Ruby/Rails community is known for it’s adoption of agile practices like TDD, and aggressive refactoring. Yet when we move into the browser, most developers seem unable to keep up the same kind of workflow, particularly when it comes to testing. Many reasons have been offered as to why this is the case: The testing tools for JavaScript just aren’t good enough. The browser just isn’t conductive to testing. The DOM is too much of a pain. Yet none of these issues are the biggest reason why.

Why is it that developers have a hard time writing tests for a PHP application? It isn’t because of PHP as a language, but the way that PHP is generally written. A single page that has business logic intermixed with application logic, which is itself intermixed in the display logic will never be testable. However when PHP is written in an isolatable way, breaking the code into units which do a single thing, PHP is almost as easy to test as Ruby. The same is true of JavaScript.

Specifically, the talk will focus on the following ways to break your JavaScript into testable chunks:

  1. How to isolate your JavaScript into objects that do a single thing
  2. How to isolate your tests for those objects using techniques like stubs, mocks and spies
  3. How to treat the DOM like an external dependency in your unit tests
  4. How frameworks like Sproutcore or Backbone.js help make JavaScript more testable
  5. How to move your currently existing code toward unit testability this using integration tests as a test harness
  6. How to know when it’s ok to treat JavaScript like CSS.

The Ruby community has been tremendously successful at getting Agile/XP practices adopted into the mainstream of our community. Now it’s time to continue to expand that influence as some of our developers move into languages like JavaScript, and as we build the next generation of web applications.

Photo of Greg Moeck

Greg Moeck

Strobe, Inc.

Greg Moeck is a software craftsman currently living in Burbank, California. His passions lie in all things Agile, Ruby and JavaScript. He spent a good portion of 2010 writing a MVP style JavaScript framework which hooked up to a Rails backend for internal use at his company, but now spends most of his time working with the Sproutcore framework.

Comments on this page are now closed.

Comments

Picture of Conrad Taylor
05/22/2011 3:47pm EDT

There were simply too many good talks at Railsconf 2011 and I wish that I could have attended them all. However, I look forward to reviewing the slides when they are posted.