Sha256: ea4bf8636602b71bab956a0739f0c31f599913c40e259c5ad1012ab9d4c49798
Contents?: true
Size: 1.04 KB
Versions: 1
Compression:
Stored size: 1.04 KB
Contents
# =require jquery # =require sinon @FakeAjaxServer = class FakeAjaxServer constructor: (@fakeServerResponse, @options = {})-> start: -> @ajaxCallbacksQueue = [] @ajaxStub = sinon.stub jQuery, 'ajax', @fakeAjax stop: -> jQuery.ajax.restore() fakeAjax: => responseStub = @createFakeJqXHR() @ajaxCallbacksQueue.push [arguments, responseStub] @processAllRequests() if @options.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] createFakeJqXHR: -> xhr = jQuery.Deferred() xhr.abort = -> (xhr[m] = (->) for m in ['error', 'success', 'complete']) if @options.legacySupport sinon.stub xhr, m, (-> xhr) for m, f of xhr when typeof f is 'function' xhr
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fake-ajax-server-0.0.3 | lib/assets/javascripts/fake_ajax_server.js.coffee |