kbaltrinic/http-backend-proxy — pull request #10 by tadas-s (2014-10-01 22:23:41+00:00)
Title: Allow overriding already defined responses (work in progress)

Hi,

Proof of concept modification to allow overriding responses. I feel rather silly because only after finishing this I realized that context object solves my problem.. But hey.. For your consideration. If anyone is interested in this I could finish it up (unit test fail, e2e pass, includes demo of this new feature too).

What I wanted to achieve with this is:
```
describe('The page', function() {
beforeEach(function() {
proxy.when('GET', '/something').respond(200, {prop: "value"});
proxy.when('GET', '/something/more').respond(200, {prop: "another value"});
proxy.when('GET', '/something/else').respond(200, {prop: "yet another"});
});

it('shows everything neatly', function() {
page.go(...);
.... expectations ...
});

describe('when some things respond differently', function() {
beforeEach(function() {
proxy.when('GET', '/something/else').respond(404, {msg: "not found"});
});

it('does not show "else"', function() {
page.go(...);
... expectations ...
});
});
});
```

To achieve this I maintain a registry of $httpBackend mocks so I can alter responses later. This registry is indexed by md5 of mock arguments. When registering a new mock, injected JS code checks for existing mock and updates response if found or creates a new and registers it.

Does it make sense? Should I try to finish it up to something merge-to-mainline-worthy?

Cheers,
Tadas