Sha256: f957215c841a394060048337964d99bb7bb9f6dd83fee66f243d88f788cb338e

Contents?: true

Size: 830 Bytes

Versions: 1

Compression:

Stored size: 830 Bytes

Contents

# =require jquery
# =require sinon

@FakeAjaxServer = class FakeAjaxServer
  constructor: (@fakeServerResponse, @imediateServe = false)->
  start: ->
    @ajaxCallbacksQueue = []
    @ajaxStub = sinon.stub $, 'ajax', @fakeAjax
  stop: -> $.ajax.restore()
  fakeAjax: =>
    responseStub = sinon.stub(new jQuery.Deferred)
    @ajaxCallbacksQueue.push [arguments, responseStub]
    @processAllRequests() if @imediateServe
    responseStub
  processNextRequest: -> @fakeServerResponse.apply this, @ajaxCallbacksQueue.shift()[0]
  processAllRequests: -> @processNextRequest() while @ajaxCallbacksQueue.length
  ignoreNextRequest: -> @ajaxCallbacksQueue.shift()
  ignoreAllRequests: -> @ajaxCallbacksQueue = []
  ajaxResponse: (index = 0)-> @ajaxCallbacksQueue[index][1]
  ajaxSettings: (index = 0)-> @ajaxCallbacksQueue[index][0][0]

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fake-ajax-server-0.0.1 lib/assets/javascripts/fake_ajax_server.js.coffee