Skip to content

Instantly share code, notes, and snippets.

@rosenfeld
Created June 3, 2012 22:24
Show Gist options
  • Save rosenfeld/2865221 to your computer and use it in GitHub Desktop.
Save rosenfeld/2865221 to your computer and use it in GitHub Desktop.
oojs sample generated files
# =require fake_ajax_server
createProducts = -> [
{id: 1, name: 'One'}
{id: 2, name: 'Two'}
]
extendClass 'specs.ShoppingCartSpec', ->
createFakeServer: ->
@fakeServer = new FakeAjaxServer (url, settings)->
if settings then settings.url = url else settings = url
handled = false
switch settings.dataType
when 'json' then switch settings.type
when 'get' then switch settings.url
when '/products' then handled = true; settings.success createProducts()
# when 'post' then switch settings.url
# when ...
# when undefined then switch settings.type
# when 'get' then switch settings.url
# when ...
# when 'post' then switch settings.url
# when ...
return if handled
console.log arguments
throw "Unexpected AJAX call: #{settings.url}"
# =require spec_helper
# =require_tree ./shopping_cart
$ -> new specs.ShoppingCartSpec
extendClass 'specs.ShoppingCartSpec', (spec)->
initialize: ->
@createFakeServer()
@extend this, new specs.jasmine.AjaxHelpers(@fakeServer)
@describe()
describe: ->
describe 'ShoppingCart', =>
@beforeAll()
beforeEach @beforeEach
@runSpecs()
runs @afterAll
beforeAll: ->
@fakeServer.start()
afterAll: =>
@fakeServer.stop()
beforeEach: =>
@fakeServer.ignoreAllRequests()
runSpecs: =>
it 'passes', =>
expect(@fakeServer).not.toBeUndefined()
# =require application
# =require modules
# =require jquery
# =require jasmine_helpers
# #require jquery.ba-bbq # uncomment for enabling $.deparam()
#
# Put your common spec code here.
# Then put "# =require spec_helper" in your specs headers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment