title: How to use mock $httpBackend to test error branch
body: <p>I am following the <a href="http://docs.angularjs.org/api/ngMock.%24httpBackend">AngularJS documentation from here</a></p>
  
  <p>The problem is that the documentation describes only the "success/happy" branch of the code, and there is no example of how to test the "failure" branch.</p>
  
  <p>What I want to do, is to set the precondition for triggering the <code>$scope.status = 'ERROR!'</code> code.</p>
  
  <p>Here is a minimal example.</p>
  
  <pre><code>// controller
  function MyController($scope, $http) {
  
    this.saveMessage = function(message) {
      $scope.status = 'Saving...';
      $http.post('/add-msg.py', message).success(function(response) {
        $scope.status = '';
      }).error(function() {
        $scope.status = 'ERROR!';
      });
    };
  }
  
  // testing controller
  var $httpBackend;
  
  beforeEach(inject(function($injector) {
    $httpBackend = $injector.get('$httpBackend');
  }));
  
  it('should send msg to server', function() {
  
    $httpBackend.expectPOST('/add-msg.py', 'message content').respond(500, '');
  
    var controller = scope.$new(MyController);
    $httpBackend.flush();
    controller.saveMessage('message content');
    $httpBackend.flush();
  
    // Here is the question: How to set $httpBackend.expectPOST to trigger
    // this condition.
    expect(scope.status).toBe('ERROR!');
  });
  
  });
  </code></pre>