2011-10-24 20:40:08 +00:00
|
|
|
if !jasmine?
|
|
|
|
throw new Error("jasmine not laoded!")
|
|
|
|
|
|
|
|
if window.JHW
|
|
|
|
# Jasmine extensions
|
|
|
|
getSplitName = (parts) ->
|
|
|
|
parts.push(String(@description).replace(/[\n\r]/g, ' '))
|
|
|
|
parts
|
|
|
|
|
|
|
|
jasmine.Suite.prototype.getSuiteSplitName = ->
|
|
|
|
this.getSplitName(if @parentSuite then @parentSuite.getSuiteSplitName() else [])
|
|
|
|
|
|
|
|
jasmine.Spec.prototype.getSpecSplitName = ->
|
|
|
|
this.getSplitName(@suite.getSuiteSplitName())
|
|
|
|
|
|
|
|
jasmine.Suite.prototype.getSplitName = getSplitName
|
|
|
|
jasmine.Spec.prototype.getSplitName = getSplitName
|
|
|
|
|
|
|
|
jasmine.Spec.prototype.getJHWSpecInformation = ->
|
|
|
|
parts = this.getSpecSplitName()
|
|
|
|
specLineInfo = HeadlessReporterResult.findSpecLine(parts)
|
|
|
|
if specLineInfo.file
|
|
|
|
parts.push("#{specLineInfo.file}:#{specLineInfo.lineNumber}")
|
|
|
|
else
|
|
|
|
parts.push('')
|
|
|
|
parts.join("||")
|
|
|
|
|
2011-11-10 19:18:25 +00:00
|
|
|
jasmine.Spec.prototype.finishCallback = ->
|
|
|
|
JHW.ping()
|
|
|
|
this.env.reporter.reportSpecResults(this)
|
|
|
|
|
2011-10-24 20:40:08 +00:00
|
|
|
jasmine.Spec.prototype.fail = (e) ->
|
|
|
|
if e and e.sourceURL and window.CoffeeScriptToFilename
|
|
|
|
filename = e.sourceURL.split('/').pop()
|
|
|
|
if realFilename = window.CoffeeScriptToFilename[filename]
|
|
|
|
e = {
|
|
|
|
name: e.name,
|
|
|
|
message: e.message,
|
|
|
|
lineNumber: "~" + String(e.line),
|
|
|
|
sourceURL: realFilename
|
|
|
|
}
|
|
|
|
|
|
|
|
expectationResult = new jasmine.ExpectationResult({
|
|
|
|
passed: false,
|
|
|
|
message: if e then jasmine.util.formatException(e) else 'Exception',
|
|
|
|
trace: { stack: e.stack }
|
|
|
|
})
|
|
|
|
@results_.addResult(expectationResult)
|
|
|
|
|
|
|
|
jasmine.NestedResults.isValidSpecLine = (line) ->
|
|
|
|
line.match(/^\s*expect/) != null || line.match(/^\s*return\s*expect/) != null
|
|
|
|
|
|
|
|
jasmine.NestedResults.parseFunction = (func) ->
|
|
|
|
lines = []
|
|
|
|
lineCount = 0
|
|
|
|
for line in func.split("\n")
|
|
|
|
if jasmine.NestedResults.isValidSpecLine(line)
|
|
|
|
line = line.replace(/^\s*/, '').replace(/\s*$/, '').replace(/^return\s*/, '')
|
|
|
|
lines.push([line, lineCount])
|
|
|
|
lineCount += 1
|
|
|
|
lines
|
|
|
|
|
|
|
|
jasmine.NestedResults.parseAndStore = (func) ->
|
|
|
|
if !jasmine.NestedResults.ParsedFunctions[func]
|
|
|
|
jasmine.NestedResults.ParsedFunctions[func] = jasmine.NestedResults.parseFunction(func)
|
|
|
|
jasmine.NestedResults.ParsedFunctions[func]
|
|
|
|
|
|
|
|
jasmine.NestedResults.ParsedFunctions = []
|
|
|
|
|
|
|
|
if !jasmine.WaitsBlock.prototype._execute
|
|
|
|
jasmine.WaitsBlock.prototype._execute = jasmine.WaitsBlock.prototype.execute
|
|
|
|
jasmine.WaitsForBlock.prototype._execute = jasmine.WaitsForBlock.prototype.execute
|
|
|
|
|
|
|
|
pauseAndRun = (onComplete) ->
|
|
|
|
JHW.timerPause()
|
2011-11-21 15:55:37 +00:00
|
|
|
if this.env.reporter.reportSpecWaiting
|
|
|
|
this.env.reporter.reportSpecWaiting(this)
|
2011-10-24 20:40:08 +00:00
|
|
|
this._execute ->
|
2011-11-21 15:55:37 +00:00
|
|
|
if this.env.reporter.reportSpecRunning
|
|
|
|
this.env.reporter.reportSpecRunning(this)
|
2011-10-24 20:40:08 +00:00
|
|
|
JHW.timerDone()
|
|
|
|
onComplete()
|
|
|
|
|
|
|
|
jasmine.WaitsBlock.prototype.execute = pauseAndRun
|
|
|
|
jasmine.WaitsForBlock.prototype.execute = pauseAndRun
|
|
|
|
|
|
|
|
jasmine.NestedResults.prototype.addResult_ = jasmine.NestedResults.prototype.addResult
|
|
|
|
jasmine.NestedResults.prototype.addResult = (result) ->
|
|
|
|
result.expectations = []
|
|
|
|
# always three up?
|
|
|
|
|
|
|
|
result.expectations = jasmine.NestedResults.parseAndStore(arguments.callee.caller.caller.caller.toString())
|
|
|
|
|
|
|
|
this.addResult_(result)
|