TOP

Stubbing Backbone.js fetch with Jasmine & Sinon.js

I needed to stub out a Backbone collection’s fetch method and make it return success. I’m using Jasmine BDD for the testing framework and Sinon.js for stubbing the methods. Here’s how I did it: (more…)

Read More
TOP

Validating a polymorphic association for a new record

Currently, in Rails, if you have a validates_associated on a model with accepts_nested_attributes_for, it will fail when creating a new record. (It fails because the foreign key is nil … because the object doesn’t exist yet.) Normally, using inverse_of solves this problem. However, with polymorphic associations, this doesn’t work. What would the point of defining the inverse_of a polymorphic object when polymorphism allows the associated object to be anything? (more…)

Read More
TOP

Restoring my dev machine from a Time Machine backup

In what turned out to be the second worst news of the day, I found out my computer was stolen from our office. (The worst news came in the form of a realization that I was not going to get a cab and instead had to subway it home with a 10 pound box of frozen meat, a new laptop, my big-ass purse, and a bag containing 3 pound ankle weights, 2 pound wrist weights, and foam roller. It was awesome.) Fortunately, I’m anal (and lucky that my Time Machine hard drive wasn’t also stolen) and had the machine backed up with Time Machine (and CrashPlan to the cloud). Word. (more…)

Read More
TOP

Testing Jammit’s packaged assets with Jasmine

In my new job, I’m trying to start things out right — behavior-driven, test-driven, “cutting-edge” tools (whatever the hell that means), etc. I’ve gone through the new Rspec book (review to come) and used Cucumber and Rspec on my Rails app. I recently re-did the front-end with Backbone.js (and I am ready to marry it) and now I’m testing the javascript with Jasmine and Sinon.js.

I was rolling happily along writing tests for my Backbone.js controllers, collections and models with Jasmine/Sinon.js. Then I got to views and hit a wall. Why? Well, I’m using Jammit to package my assets for production. This is cool and all for individual javascript files as I’m also adding them to my jasmine.yml config file. The problem is that Jammit is packaging my haml templates into a global JST object and I need to access those templates, and more importantly, that global JST object when testing my view code. (more…)

Read More
TOP

Debugging Cucumber in RubyMine {Quick Hit}

Using Cucumber and Rspec for the first time has been … a little frustrating. I followed along with the main tutorial in The Rspec Book and then skimmed the later chapters. I thought it was quite good until I had to start testing an actual rails app and felt a little at a loss. But I digress … (more…)

Read More