From a286e23fdf32abbf99d067dcaed95bbad284c121 Mon Sep 17 00:00:00 2001 From: nilsnh Date: Wed, 11 Jul 2012 01:25:27 +0200 Subject: [PATCH] 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. --- src/task.coffee | 6 ++++-- test/taskTest.coffee | 10 ++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/task.coffee b/src/task.coffee index 853bcfc..03dbbce 100644 --- a/src/task.coffee +++ b/src/task.coffee @@ -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) -> diff --git a/test/taskTest.coffee b/test/taskTest.coffee index 940c1d7..b7b4159 100644 --- a/test/taskTest.coffee +++ b/test/taskTest.coffee @@ -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)