Skip to content

Commit

Permalink
- add a (yet failing) test for correct error state
Browse files Browse the repository at this point in the history
  • Loading branch information
bascht committed Jul 29, 2011
1 parent 3802b94 commit 032c02f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
15 changes: 15 additions & 0 deletions frameworks/foundation/debug/base.js
Expand Up @@ -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();
}
Expand Down
43 changes: 43 additions & 0 deletions 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);
});
});
});
});
});
});

0 comments on commit 032c02f

Please sign in to comment.