Andy, Senior Engineer @ Contactually

JavaScript Test-Driven Development with Rails 4 & Konacha

At Contactually, our app’s back-end is written in Rails 4, while most of the front-end is a Single-Page Application (SPA) written in JavaScript, using Backbone.js, Marionette.js, and a number of JavaScript plugins. On the back-end, we have a suite of RSpec unit specs and Capybara acceptance specs to make sure everything works on the back-end. When I joined Contactually in September 2014, the front-end code didn’t have any unit tests – everything was tested manually by traditional QA processes. In our app, there’s a lot of business logic between different objects. A User has many Contacts and Groupings A Contact can be in many Groupings, but only certain subtypes of Grouping, such as Buckets A Grouping can belong to many Users A Domain can have many Users, and many Groupings Etc. Almost all of this logic is spec’ed out and verified by RSpec and Capybara specs, but a lot of the same business logic on the client-side was not, which led to hard-to-find bugs in the Backbone app. As an example, after creating a new Contact, the UI didn’t update properly despite the new Contact was created successfully on the back-end. I set up a Test-Driven Development (TDD) environment for testing the various Views, Models, Controllers, and Mixins that make up Contactually’s Backbone app. Going forward with new UI features or bug fixes, any developer can set up a JavaScript spec with minimal overhead and keep the TDD ball rolling. Since Contactually is a Rails app, I chose a JS testing framework that’s similar in style to RSpec. I chose Mocha (and Chai) over alternatives such as QUnit or...