Skip to content

Instantly share code, notes, and snippets.

@msanroman
Created May 11, 2012 08:59
Show Gist options
  • Save msanroman/2658514 to your computer and use it in GitHub Desktop.
Save msanroman/2658514 to your computer and use it in GitHub Desktop.
TodoList.Models.Task jasmine description in CoffeeScript
describe 'TodoList.Models.Task', ->
beforeEach ->
@task = new TodoList.Models.Task
it "should exist", ->
expect(TodoList.Models.Task).toBeDefined()
it "should be instantiable", ->
expect(@task).not.toBeNull()
describe "default values for new tasks", ->
it "should have an empty string as default name", ->
expect(@task.get "name").toEqual ""
it "shouldn't be completed", ->
expect(@task.get "completed").toEqual false
describe "getters", ->
describe "getId", ->
it "should be defined", ->
expect(@task.getId).toBeDefined()
it "should return model's id", ->
@task.id = 1
expect(@task.getId()).toEqual 1
describe "getName", ->
it "should be defined", ->
expect(@task.getName).toBeDefined()
it "should return an empty string as default behaviour", ->
expect(@task.getName()).toEqual ''
it "should return its name if defined", ->
stub = sinon.stub(@task, 'get').returns 'Trololo!'
expect(@task.getName()).toEqual 'Trololo!'
expect(stub.calledWith('name')).toBeTruthy()
describe "isCompleted", ->
it "should be defined", ->
expect(@task.isCompleted).toBeDefined()
it "should return value for the completed attribute", ->
spyOn(@task, 'get').andReturn(false)
expect(@task.isCompleted()).toEqual false
expect(@task.get).toHaveBeenCalledWith('completed')
describe "save", ->
beforeEach ->
@server = sinon.fakeServer.create()
afterEach ->
@server.restore()
it 'sends valid data to the server', ->
@task.save {name: 'new task'}
request = @server.requests[0]
params = JSON.parse(request.requestBody)
expect(params.task).toBeDefined()
expect(params.task.name).toEqual 'new task'
expect(params.task.complete).toBeFalsy()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment