2011-10-24 20:40:08 +00:00
|
|
|
# Try to get the line number of a failed spec
|
|
|
|
class window.HeadlessReporterResult
|
|
|
|
constructor: (@name, @splitName) ->
|
|
|
|
@results = []
|
2011-10-26 02:22:29 +00:00
|
|
|
|
2011-10-24 20:40:08 +00:00
|
|
|
addResult: (message) ->
|
|
|
|
@results.push(message)
|
2011-10-26 02:22:29 +00:00
|
|
|
|
2011-11-29 20:36:17 +00:00
|
|
|
toString: ->
|
|
|
|
output = "\n" + @name.foreground('red')
|
2011-10-24 20:40:08 +00:00
|
|
|
bestChoice = HeadlessReporterResult.findSpecLine(@splitName)
|
|
|
|
output += " (#{bestChoice.file}:#{bestChoice.lineNumber})".foreground('blue') if bestChoice.file
|
|
|
|
|
|
|
|
for result in @results
|
2011-11-29 20:36:17 +00:00
|
|
|
line = result.message.foreground('red')
|
2011-10-24 20:40:08 +00:00
|
|
|
if result.lineNumber
|
2011-11-29 20:36:17 +00:00
|
|
|
line += " (line ~#{bestChoice.lineNumber + result.lineNumber})".foreground('red').bright()
|
|
|
|
output += "\n #{line}"
|
2011-10-26 12:45:23 +00:00
|
|
|
|
|
|
|
if result.line?
|
2011-11-29 20:36:17 +00:00
|
|
|
output += "\n #{result.line}".foreground('yellow')
|
|
|
|
|
|
|
|
output
|
2011-10-26 02:22:29 +00:00
|
|
|
|
2011-10-24 20:40:08 +00:00
|
|
|
@findSpecLine: (splitName) ->
|
|
|
|
bestChoice = { accuracy: 0, file: null, lineNumber: null }
|
|
|
|
|
|
|
|
for file, lines of HeadlessReporterResult.specLineNumbers
|
|
|
|
index = 0
|
|
|
|
lineNumber = 0
|
|
|
|
while newLineNumberInfo = lines[splitName[index]]
|
|
|
|
if newLineNumberInfo.length == 0
|
|
|
|
lineNumber = newLineNumberInfo[0]
|
|
|
|
else
|
|
|
|
lastLine = null
|
|
|
|
for line in newLineNumberInfo
|
|
|
|
lastLine = line
|
|
|
|
break if line > lineNumber
|
|
|
|
|
|
|
|
lineNumber = lastLine
|
|
|
|
|
|
|
|
index++
|
|
|
|
|
|
|
|
if index > bestChoice.accuracy
|
|
|
|
bestChoice = { accuracy: index, file: file, lineNumber: lineNumber }
|
2011-10-26 02:22:29 +00:00
|
|
|
|
2011-11-29 20:11:40 +00:00
|
|
|
break if index == splitName.length
|
|
|
|
|
2011-10-24 20:40:08 +00:00
|
|
|
bestChoice
|