a little more cleanup

This commit is contained in:
John Bintz 2012-01-17 09:09:44 -05:00
parent 98982e28e5
commit 81673543fe
2 changed files with 37 additions and 6 deletions

View File

@ -3,16 +3,14 @@ jasmine.GWT =
if scenario = jasmine.GWT.currentScenario_ if scenario = jasmine.GWT.currentScenario_
scenario[type](name, parameter) scenario[type](name, parameter)
else else
jasmine.GWT.Steps[type] ||= [] (jasmine.GWT.Steps[type] ||= []).push([ name, parameter ])
jasmine.GWT.Steps[type].push([ name, parameter ])
Hook: (type, code) -> Hook: (type, code) ->
jasmine.GWT.Hooks[type] ||= [] (jasmine.GWT.Hooks[type] ||= []).push(code)
jasmine.GWT.Hooks[type].push(code)
World: (object_or_code) -> World: (object_or_code) ->
if typeof object_or_code != 'function' if typeof object_or_code != 'function'
object_or_code = jasmine.GWT._generateWorldMethods(object_or_code) object_or_code = jasmine.GWT.generateWorldMethods(object_or_code)
jasmine.GWT.Hook('World', object_or_code) jasmine.GWT.Hook('World', object_or_code)
@ -20,7 +18,7 @@ jasmine.GWT =
for code in (jasmine.GWT.Hooks[type] || []) for code in (jasmine.GWT.Hooks[type] || [])
code.apply(context) code.apply(context)
_generateWorldMethods: (object) -> generateWorldMethods: (object) ->
-> ->
for method, code of object for method, code of object
this[method] = code this[method] = code

View File

@ -28,3 +28,36 @@ describe 'jasmine.GWT', ->
expect(jasmine.GWT.currentScenario_[type]).toHaveBeenCalledWith(name, parameter) expect(jasmine.GWT.currentScenario_[type]).toHaveBeenCalledWith(name, parameter)
describe '.Hook', ->
type = 'type'
code = 'code'
beforeEach ->
jasmine.GWT.Hooks = {}
it 'should add the hook', ->
jasmine.GWT.Hook(type, code)
expect(jasmine.GWT.Hooks[type]).toEqual([ code ])
describe '.World', ->
worldMethods = 'worldMethods'
beforeEach ->
spyOn(jasmine.GWT, 'Hook')
spyOn(jasmine.GWT, 'generateWorldMethods').andReturn(worldMethods)
context 'with object', ->
object = {}
it 'should add an object that adds methods to the World', ->
jasmine.GWT.World(object)
expect(jasmine.GWT.Hook).toHaveBeenCalledWith('World', worldMethods)
context 'with function', ->
func = ->
it 'should add the function to the queue', ->
jasmine.GWT.World(func)
expect(jasmine.GWT.Hook).toHaveBeenCalledWith('World', func)