Jasmine and Shared Examples

I’ve been doing a bit more Javascript development as of late and am using
Jasmine for my unit tests. It’s been wonderful. I did find that it was a bit
of a bear to test shared behavior (there’s a couple levels of inheritance in
the Backbone models) so I decided to whip up a crude implementation of shared
behavior.

This uses a handful of Underscore.js functions to slice and dice arguments and
expects our appNamespace.jasmine.sharedExamples object to exist.

This checks to see that our example group exists, and if it doesn’t, it
creates a failing test case warning us about it. If the example group does
exist, it’ll wrap the behavior in a describe block (the property of the object
being the describe string), pass any additional arguments, and finally execute
any additional block of code.