JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script src="http://documentcloud.github.com/backbone/backbone-min.js"></script>
<script src="http://sinonjs.org/releases/sinon-1.3.4.js"></script>
<html>
<head>
<link href="http://blog.bandzarewicz.com/stylesheets/jasmine/jasmine.css" media="screen, projection" rel="stylesheet" type="text/css">
<script src="https://raw.github.com/pivotal/jasmine/v1.1.0/lib/jasmine-core/jasmine.js"></script>
<script src="https://raw.github.com/pivotal/jasmine/v1.1.0/lib/jasmine-core/jasmine-html.js"></script>
<script src="https://bitbucket.org/cleonello/jqplot/raw/dd65cd032132/src/jquery.jqplot.js"></script>
<title>Jasmine Spec Runner</title>
</head>
<body>
</body>
</html>
CoffeeScript
# abbreviated todo model
class window.Todo extends Backbone.Model
# complete todos collection
class window.Todos extends Backbone.Collection
model: window.Todo
url: "/todos"
comparator: (todo) ->
todo.get('priority')
parse: (res) ->
res.response.todos
# spec/javascripts/fixtures/todos_fixture.js.coffee
beforeEach ->
@fixtures = Todos:
valid:
status: "OK"
version: "1.0"
response:
todos: [
id: 1
title: "Paint the fence"
,
id: 2
title: "Wash the dog"
]
# spec/javascripts/helpers/valid_response.js.coffee
beforeEach ->
@validResponse = (responseText) ->
[ 200, "Content-Type": "application/json",
JSON.stringify responseText ]
# todo spec
describe "Todos collection", ->
beforeEach ->
@todo = sinon.stub(window, "Todo")
@todos = new Todos()
@todo1 = new Backbone.Model
id: 1
title: "Todo 1"
priority: 3
@todo2 = new Backbone.Model
id: 2
title: "Todo 2"
priority: 2
@todo3 = new Backbone.Model
id: 3
title: "Todo 3"
priority: 1
afterEach ->
@todo.restore()
describe "when instantiated with a model literal", ->
beforeEach ->
@model = new Backbone.Model(id: 5, title: "Foo")
@todo.returns @model
@todos.model = Todo
@todos.add(id: 5, title: "Foo")
it "should add a model", ->
expect(@todos.length).toEqual 1
it "should find a model by id", ->
expect(@todos.get(5).get("id")).toEqual 5
it "orders models by priority", ->
@todos.add [@todo1, @todo2, @todo3]
expect(@todos.at(0)).toBe @todo3
expect(@todos.at(1)).toBe @todo2
expect(@todos.at(2)).toBe @todo1
describe "when fetching models from the server", ->
beforeEach ->
@fixture = @fixtures.Todos.valid
@server = sinon.fakeServer.create()
@server.respondWith "GET", "/todos", @validResponse(@fixture)
afterEach ->
...