Add better errors to .toHaveLength spec exception

Returns a helpful error when the actual object does not have a length
var.
This commit is contained in:
Corey Johnson 2013-09-09 09:28:36 -07:00
parent 2876618218
commit c90eb7fc73

View File

@ -118,9 +118,13 @@ addCustomMatchers = (spec) ->
@actual instanceof expected @actual instanceof expected
toHaveLength: (expected) -> toHaveLength: (expected) ->
notText = if @isNot then " not" else "" if not @actual?
this.message = => "Expected object with length #{@actual.length} to#{notText} have length #{expected}" this.message = => "Expected object #{@actual} has no length method"
@actual.length == expected false
else
notText = if @isNot then " not" else ""
this.message = => "Expected object with length #{@actual.length} to#{notText} have length #{expected}"
@actual.length == expected
toExistOnDisk: (expected) -> toExistOnDisk: (expected) ->
notText = this.isNot and " not" or "" notText = this.isNot and " not" or ""