first commit

This commit is contained in:
Nils N Haukas 2012-07-10 12:40:45 +02:00
commit 23b10c9132
5 changed files with 73 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

8
README Normal file
View File

@ -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. :)

12
package.json Normal file
View File

@ -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"
}
}

17
src/task.coffee Normal file
View File

@ -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

35
test/taskTest.coffee Normal file
View File

@ -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."