私はファイルを持っていますapp.coffee
:
class TaskList
class Task
constructor: (@name) ->
@status = 'incomplete'
complete: ->
if @parent? and @parent.status isnt 'completed'
throw "Dependent task '#{@parent.name}' is not completed."
@status = 'complete'
true
dependsOn: (@parent) ->
@parent.child = @
@status = 'dependent'
# Prepare scope stuff
root = exports ? window
root.TaskList = TaskList
root.Task = Task
と呼ばれるファイルtest/taskTest.coffee
:
{TaskList, Task} = require '../app'
should = require 'should'
describe 'Task Instance', ->
task1 = task2 = null
it 'should have a name', ->
something = 'asdf'
something.should.equal 'asdf'
task1 = new Task 'feed the cat'
task1.name.should.equal 'feed the cat'
it 'should be initially incomplete', ->
task1.status.should.equal 'incomplete'
it 'should be able to be completed', ->
task1.complete().should.be.true
task1.status.should.equal 'complete'
it 'should be able 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 'should refuse completion it is dependent on an uncompleted task', ->
(-> task2.complete()).should.throw "Dependent task 'wash dishes' is not completed."
ターミナルでこのコマンドを実行した場合:mocha -r should --compilers coffee:coffee-script -R spec
「依存タスク「食器洗い」が完了していません」という例外を予期していたという失敗したテスト(最後のテスト)があります。しかし、「未定義」になりました。
括弧を削除してに変更(-> task2.complete()).should.throw
する-> task2.complete().should.throw
と、テストは成功し、例外をスローしないと失敗します。しかし、例外メッセージをランダムなものに変更しても、それでも成功します。私は何か間違ったことをしていますか?メッセージが文字通り「依存タスク「皿洗い」が完了していない」である場合にのみ、テストに合格するべきではありませんか?