summaryrefslogtreecommitdiff
path: root/spec/helper.js
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2012-11-14 12:28:57 +0100
committerAzul <azul@riseup.net>2012-11-14 12:33:31 +0100
commit2859af0287d7672df0a8965be43fb9859fca8bf8 (patch)
tree4be112443f48a29763b6adae5f68d521022dcc55 /spec/helper.js
parent7b73cbd591aa9ac3f46400c040ae14ec26e2d839 (diff)
parent47c7a78e948f139074ec8d975cdd38cc3335253d (diff)
Merge branch 'feature/cleanup-non-restful' into develop
Diffstat (limited to 'spec/helper.js')
-rw-r--r--spec/helper.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/helper.js b/spec/helper.js
new file mode 100644
index 0000000..11327af
--- /dev/null
+++ b/spec/helper.js
@@ -0,0 +1,44 @@
+var specHelper = (function() {
+ // HELPERS
+
+ 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;
+ }
+
+ // TODO: validate http verb
+ function expectRequest(url, content, verb) {
+ expect(this.requests.length).toBe(1);
+ expect(this.requests[0].url).toBe(url);
+ expect(decodeURI(this.requests[0].requestBody)).toBe(content);
+ if (verb) {
+ expect(this.requests[0].method).toBe(verb);
+ }
+ }
+
+ 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(object) {
+ var request = this.requests.pop();
+ header = { "Content-Type": "application/json;charset=utf-8" };
+ body = JSON.stringify(object);
+ request.respond(200, header, body);
+ }
+
+ return {
+ setupFakeXHR: setupFakeXHR,
+ }
+
+})();