Skip to content

Instantly share code, notes, and snippets.

@lukelex
Created August 15, 2013 04:01
Show Gist options
  • Select an option

  • Save lukelex/6238165 to your computer and use it in GitHub Desktop.

Select an option

Save lukelex/6238165 to your computer and use it in GitHub Desktop.
describe 'Contexts.ContextManager', ->
reloadContextManager = ->
@contextManager = new Contexts.ContextManager
sampleContext = {id: 'uniqueId'}
differentContext = {id: 'differentId'}
describe '#push', ->
beforeEach reloadContextManager
it 'with different contexts', ->
@contextManager.push sampleContext
(expect =>
@contextManager.push differentContext
).not.toThrow()
it 'with equal contexts', ->
@contextManager.push sampleContext
(expect =>
@contextManager.push sampleContext
).toThrow()
describe '#pop', ->
beforeEach reloadContextManager
it 'should not allow poping an unpushed context', ->
(expect =>
@contextManager.pop sampleContext
).toThrow()
it 'should allow poping a pre-pushed context', ->
@contextManager.push sampleContext
(expect =>
@contextManager.pop sampleContext
).not.toThrow()
it 'should return an undefined context after poping the last one', ->
@contextManager.push sampleContext
@contextManager.pop sampleContext
(expect @contextManager.current()).toBeUndefined()
describe '#isCurrent', ->
beforeEach reloadContextManager
it 'while is the current', ->
@contextManager.push sampleContext
(expect @contextManager.isCurrent sampleContext).toBeTruthy()
it 'while is the current', ->
@contextManager.push sampleContext
(expect @contextManager.isCurrent differentContext).toBeFalsy()
it 'without a current context', ->
(expect @contextManager.isCurrent sampleContext).toBeFalsy()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment