Added feature of checking if task added is neither a string nor a Task object. But I also discovered that the error thrown is not checked properly.

This commit is contained in:
nilsnh 2012-07-11 01:25:27 +02:00
parent d7efe472f3
commit a286e23fdf
2 changed files with 12 additions and 4 deletions

View File

@ -17,10 +17,12 @@ class TaskList
@tasks = []
@length = 0
add: (@name) ->
unless typeof @name is 'string' or @name instanceof Task
throw "Here's an error"
if typeof @name is 'string'
task = new Task 'take out garbage'
@tasks.push task
else
@tasks.push task
if @name instanceof Task
@tasks.push @name
@length++
remove: (task) ->

View File

@ -1,5 +1,5 @@
chai = require 'chai'
chai.should()
should = chai.should()
expect = chai.expect
{TaskList, Task} = require '../src/task'
@ -36,7 +36,8 @@ describe 'Task instance', ->
task2.status.should.equal 'dependent'
task2.parent.should.equal task1
task1.child.should.equal task2
-> task2.complete().should.throw "Dependent task 'wash dishes' is not completed."
#-> task2.complete().should.throw "Dependent task 'wash dishes' is not completed."
(-> task2.complete()).should.throw "Dependent task 'wash dishes' is not completed."
describe 'TaskList', ->
taskList = null
@ -90,3 +91,8 @@ describe 'TaskList', ->
"""
taskList.print().should.equal desiredOutput
it "throws error if anything but strings or task is added", ->
taskList = new TaskList
Error = "This is an error"
(-> taskList.add(123123)).should.throw(Error)
#assert(expression, message, negateMessage, expected, actual)