commit 23b10c91327d394011e2905fe73beb830685d7d6 Author: Nils N Haukas Date: Tue Jul 10 12:40:45 2012 +0200 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/README b/README new file mode 100644 index 0000000..3c1356b --- /dev/null +++ b/README @@ -0,0 +1,8 @@ +This project is just me following the instructions from this site: + +http://net.tutsplus.com/tutorials/javascript-ajax/better-coffeescript-testing-with-mocha/ + +With some minor adjustments based on the commenters. + +After downloading, do "npm install" in the base folder to get the required node_modules to test and run the code. :) + diff --git a/package.json b/package.json new file mode 100644 index 0000000..b647f28 --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "name": "Better Coffe-script testing with Mocha" + , "version": "0.0.1" + , "private": true + , "dependencies": { + "coffee-script": "x" + } + , "devDependencies": { + "mocha": "x", + "should": "x" + } +} diff --git a/src/task.coffee b/src/task.coffee new file mode 100644 index 0000000..1659f01 --- /dev/null +++ b/src/task.coffee @@ -0,0 +1,17 @@ +class Task + constructor: (@name) -> + @status = 'incomplete' + + complete: -> + if @parent? and @parent.status isnt 'complete' + throw "Dependent task '#{@parent.name}' is not completed." + + @status = 'complete' + true + + dependsOn: (@parent) -> + @parent.child = @ + @status = 'dependent' + +root = exports ? window +root.Task = Task \ No newline at end of file diff --git a/test/taskTest.coffee b/test/taskTest.coffee new file mode 100644 index 0000000..0d614e4 --- /dev/null +++ b/test/taskTest.coffee @@ -0,0 +1,35 @@ +{Tasklist, Task} = require '../src/task' + +describe 'Task instance', -> + task1 = task2 = null + it 'has name', -> + task1 = new Task 'feed the cat' + task1.name.should.equal 'feed the cat' + + it 'is initially incomplete', -> + task1.status.should.equal 'incomplete' + + it 'is able to be completed', -> + task1.complete().should.be.true + task1.status.should.equal 'complete' + + it 'is able to to be dependent on another task', -> + task1 = new Task 'wash dishes' + task2 = new Task 'dry dishes' + + task2.dependsOn task1 + + task2.status.should.equal 'dependent' + task2.parent.should.equal task1 + task1.child.should.equal task2 + + it 'refuses completed if it is dependent on an uncompleted task', -> + task1 = new Task 'wash dishes' + task2 = new Task 'dry dishes' + + task2.dependsOn task1 + + 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." \ No newline at end of file