From 032c02fc1471a392066d78b1d6da68a0c641067d Mon Sep 17 00:00:00 2001 From: Sebastian Schulze Date: Fri, 29 Jul 2011 08:00:59 +0200 Subject: [PATCH] - add a (yet failing) test for correct error state --- frameworks/foundation/debug/base.js | 15 +++++++ .../integration/requested_error_state.js | 43 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 frameworks/foundation/tests/integration/requested_error_state.js diff --git a/frameworks/foundation/debug/base.js b/frameworks/foundation/debug/base.js index 0836678..f0aa07e 100644 --- a/frameworks/foundation/debug/base.js +++ b/frameworks/foundation/debug/base.js @@ -55,11 +55,26 @@ Fictum = { if (!response.get('status')) { response.set('status', 200); } + + if ((response.get('status') < 200) || (response.get('status') >= 300)) { + try { + msg = this.statusText || ''; + } catch(e2) { + msg = ''; + } + + error = SC.$error(msg || "HTTP Request failed", "Request", response.get('status')) ; + error.set("errorValue", this) ; + response.set('isError', YES); + response.set('errorObject', error); + } + response.notify(); }, 1); } else { if (!response.get('status')) { response.set('status', 200); + response.set('isError', YES); } response.notify(); } diff --git a/frameworks/foundation/tests/integration/requested_error_state.js b/frameworks/foundation/tests/integration/requested_error_state.js new file mode 100644 index 0000000..90c2133 --- /dev/null +++ b/frameworks/foundation/tests/integration/requested_error_state.js @@ -0,0 +1,43 @@ +describe('Scenario: Requesting with a non 200 status code', function() { + describe('Given I have setup Fictum', function() { + beforeEach(function() { + Fictum.setup(); + }); + + afterEach(function() { + Fictum.teardown(); + }); + + describe('And a URL that I want to stub', function() { + var url; + beforeEach(function() { + url = '/broken'; + }); + + describe('When I register that URL with a non 200 status code', function() { + beforeEach(function() { + Fictum.registerUrl(url, "You made response kitty cry!", { status: 500 } ); + }); + + describe('And I make a request to a url asking for JSON that matches the registered URL regular expression', function() { + var request, response; + beforeEach(function() { + request = SC.Request.getUrl('/broken') + response = request.send(); + waitsFor(function() { + return response.get('status') !== -100; + }); + }); + + it('Then I should receive the registered response in JSON', function() { + + expect(response.get('body')).toEqual("You made response kitty cry!"); + expect(response.get('status')).toEqual(500); + expect(response.get('isError')).toEqual(true); + expect(SC.ok(response)).toEqual(false); + }); + }); + }); + }); + }); +});