fix for before/after hooks

This commit is contained in:
John Bintz 2012-01-11 14:18:57 -05:00
parent 14a7e68397
commit cda88b6054

View File

@ -59,18 +59,20 @@ class jasmine.GWT.Scenario extends jasmine.GWT.Background
describe scenarioName, -> describe scenarioName, ->
_this.spies_ = [] _this.spies_ = []
jasmine.GWT.runHook('Before', _this)
for index in [ 0..._statements.length ] for index in [ 0..._statements.length ]
[ type, name, param ] = _statements[index] [ type, name, param ] = _statements[index]
_this._type = type _this._type = type
_this._name = name _this._name = name
isLast = (index + 1) == _statements.length runCode = (param, index, args = []) ->
isLast = (index + 1) == _statements.length
isFirst = (index == 0)
runCode = (param, isLast, args = []) ->
it "#{type} #{name}", -> it "#{type} #{name}", ->
if isFirst
jasmine.GWT.runHook('Before', _this)
this.spyOn = (args...) -> this.spyOn = (args...) ->
this.spies_ = _this.spies_ this.spies_ = _this.spies_
jasmine.Spec.prototype.spyOn.apply(this, args) jasmine.Spec.prototype.spyOn.apply(this, args)
@ -81,11 +83,14 @@ class jasmine.GWT.Scenario extends jasmine.GWT.Background
param.apply(_this, args) param.apply(_this, args)
if isLast
jasmine.GWT.runHook('After', _this)
args = [] args = []
if param? if param?
if typeof param == "function" if typeof param == "function"
runCode(param, isLast) runCode(param, index)
continue continue
else else
args = [ param ] args = [ param ]
@ -97,13 +102,13 @@ class jasmine.GWT.Scenario extends jasmine.GWT.Background
if match.constructor == RegExp if match.constructor == RegExp
if result = name.match(match) if result = name.match(match)
result.shift() result.shift()
runCode(code, isLast, result.concat(args)) runCode(code, index, result.concat(args))
found = true found = true
break break
else else
if name == match if name == match
runCode(code, isLast) runCode(code, index)
found = true found = true
break break
@ -141,8 +146,6 @@ class jasmine.GWT.Scenario extends jasmine.GWT.Background
jasmine.getEnv().currentSpec.addMatcherResult(fakeResult) jasmine.getEnv().currentSpec.addMatcherResult(fakeResult)
jasmine.GWT.runHook('After', _this)
allStatements: => allStatements: =>
allStatements = [] allStatements = []