diff options
author | Azul <azul@leap.se> | 2012-07-02 17:39:56 +0200 |
---|---|---|
committer | Azul <azul@leap.se> | 2012-07-02 17:39:56 +0200 |
commit | 337df30b51d2c1bdddcb7fbd05f0ccf46a7a31b3 (patch) | |
tree | 706e68051b796b172d7f172dc3da1d13027a2e6e /javascript/spec/specHelper.js | |
parent | 4da016f111510f185b4bf16b4164d43342ef1d66 (diff) |
expectRequest and respond{JSON,XML} functions to simplify the tests
Diffstat (limited to 'javascript/spec/specHelper.js')
-rw-r--r-- | javascript/spec/specHelper.js | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/javascript/spec/specHelper.js b/javascript/spec/specHelper.js index 747fa9d..21a0cb7 100644 --- a/javascript/spec/specHelper.js +++ b/javascript/spec/specHelper.js @@ -1,31 +1,40 @@ var specHelper = (function() { // HELPERS - function respondXML(request, content) { + function setupFakeXHR() { + this.xhr = sinon.useFakeXMLHttpRequest(); + var requests = this.requests = []; + this.xhr.onCreate = function (xhr) { + requests.push(xhr); + }; + this.expectRequest = expectRequest; + this.respondJSON = respondJSON; + this.respondXML = respondXML; + } + + function expectRequest(url, content) { + expect(this.requests.length).toBe(1); + expect(this.requests[0].url).toBe(url); + expect(this.requests[0].requestBody).toBe(content); + } + + function respondXML(content) { + var request = this.requests.pop(); header = { "Content-Type": "application/xml;charset=utf-8" }; body = '<?xml version="1.0" encoding="UTF-8"?>\n'; body += content; request.respond(200, header, body); } - function respondJSON(request, object) { + function respondJSON(object) { + var request = this.requests.pop(); header = { "Content-Type": "application/json;charset=utf-8" }; body = JSON.stringify(object); request.respond(200, header, body); } - function setupFakeXHR() { - this.xhr = sinon.useFakeXMLHttpRequest(); - var requests = this.requests = []; - this.xhr.onCreate = function (xhr) { - requests.push(xhr); - }; - } - return { - respondJSON: respondJSON, - respondXML: respondXML, - setupFakeXHR: setupFakeXHR + setupFakeXHR: setupFakeXHR, } })(); |