maxenglander/beatbrush — pull request #1 by mjhoy (2012-11-18 03:31:38+00:00)
Title: refactoring/tests for "Search"

@maxenglander No change in functionality here but wondering what you think of this refactoring. Big changes are: add the `jasmine-rails` gem, which allows for headless javascript testing (see README for info), a [refactoring of the Search class][search] (previously StartSearch) and [tests for Search][tests].

[search]:https://github.com/maxenglander/beatbrush/blob/f59c57798bb02e135ee0ee00a2911665e7cfda19/app/assets/javascripts/search.js.coffee
[tests]:https://github.com/maxenglander/beatbrush/blob/f59c57798bb02e135ee0ee00a2911665e7cfda19/spec/javascripts/search_spec.coffee

One pattern I'd like to adopt in general is passing references to classes or objects to constructors. For Search, it accepts a reference to the Rdio object (`R`) and a "musicSearcher" class (should the variable name be uppercase to indicate it is a class reference?)

Two reasons for this. One is that `R` will simply not be defined in our tests, because of how it gets loaded in. Two is that we can pass in stubs and examine methods called on them. Note how I defined one-off classes in the spec for this purpose.

This is my first time using Jasmine, seems pretty good.