add support for World, works like it does in cucumber

This commit is contained in:
John Bintz 2012-01-12 10:13:58 -05:00
parent 50881d3d86
commit e4b2d39b31
3 changed files with 15 additions and 0 deletions

View File

@ -5,13 +5,25 @@ jasmine.GWT =
else
jasmine.GWT.Steps[type] ||= []
jasmine.GWT.Steps[type].push([ name, parameter ])
Hook: (type, code) ->
jasmine.GWT.Hooks[type] ||= []
jasmine.GWT.Hooks[type].push(code)
World: (object_or_code) ->
if typeof object_or_code != 'function'
object_or_code = jasmine.GWT._generateWorldMethods(object_or_code)
jasmine.GWT.Hook('World', object_or_code)
runHook: (type, context) ->
for code in (jasmine.GWT.Hooks[type] || [])
code.apply(context)
_generateWorldMethods: (object) ->
->
for method, code of object
this[method] = code
Steps: {}
Hooks: {}

View File

@ -23,6 +23,7 @@ class jasmine.GWT.Scenario extends jasmine.GWT.Background
it "#{type} #{name}", ->
if isFirst
jasmine.GWT.runHook('World', _this)
jasmine.GWT.runHook('Before', _this)
this.spyOn = (args...) ->

View File

@ -26,3 +26,5 @@ jasmine.GWT.globals =
Before: (args...) -> jasmine.GWT.Hook('Before', args...)
After: (args...) -> jasmine.GWT.Hook('After', args...)
World: (args...) -> jasmine.GWT.World(args...)