title: Angular Unit Testing a resource request
body: <p>I am attempting to perform a unit test on this controller. </p>
  
  <pre><code>angular.module('app.dashboard', [])
  .controller('DashboardController', ['$scope', 'myAppService'], function($scope, myAppService) {
      var _data = myAppService.requests.get(function() {
          $scope.requests = _data.requests;
      });
  });
  </code></pre>
  
  <p>myAppService is a service based on ngResource.</p>
  
  <p>I want to test for the number of requests. I spent all day figuring out how to get $httpBackend injected, now I'm hung up on properly measuring the data.</p>
  
  <pre><code>beforeEach(inject(function ($controller, $rootScope, $injector) {
      $httpBackend = $injector.get('$httpBackend');
      $httpBackend.when('GET', '/api/requests').respond(
          {requests: [{sender: 'joe', message: 'help'}, {sender: 'larry', message: 'SOS'}]}
      );
  });
  it('should have a properly working Dashboard controller', inject(function($rootScope, $controller, $httpBackend) {
      var $scope = $rootScope.$new();
      var ctrl = $controller('DashboardController', {
          $scope : $scope
      });
      expect($scope.requests.length).toBe(2);
  }));
  </code></pre>
  
  <p>Any assistance would be greatly, massively appreciated.</p>