var sinon = require('sinon');
var expect = require('chai').expect;
var assert = require('assert');
var Q = require('q');
var cases = require('cases');

describe('runner', function() {
    it('follows redirects', cases([['Location'], ['location']], function(headerName, done) {
        // Arrange
        var client = {
            request: sinon.stub()
        };
        var redirectFrom = 'http://test.example.com/redirectFrom';
        var redirectTo = 'http://test.example.com/redirectTo';

        var urls = [redirectFrom];
        var reporter = {
            report: sinon.spy(),
            summarise: function() {
                return Q('Done');
            }
        };
        var checker = { check: sinon.spy() };
        var runner = require('../runner.js');

        var headers = {};
        headers[headerName] = redirectTo;

        client.request.withArgs(redirectFrom).returns(Q({
            status: 302,
            headers: headers
        }));

        client.request.withArgs(redirectTo).returns(Q({
            status: 200
        }));

        // Act
        runner.run(client, urls, reporter, checker).then(function() {
            // Assert
            assert(reporter.report.calledWith(redirectFrom));
            assert(reporter.report.calledWith(redirectTo));
            assert(!isNaN(reporter.report.firstCall.args[2]));

            assert(!checker.check.calledWith(redirectFrom));
            assert(checker.check.calledWith(redirectTo));
        }).then(done).done();
    }))
})

@@ -1507,12 +1507,845 @@
 %0A    %7D))
+;%0A%0A    it('returns a failed request as a failure', function(done) %7B%0A        // Arrange%0A        var client = %7B%0A            request: sinon.stub()%0A        %7D;%0A        var failingUrl = 'https://test.example.com/failsRequest';%0A%0A        var urls = %5BfailingUrl%5D;%0A        var reporter = %7B%0A            report: sinon.spy(),%0A            summarise: sinon.spy()%0A        %7D;%0A        var checker = %7B check: sinon.spy() %7D;%0A        var runner = require('../runner.js');%0A%0A        client.request.withArgs(failingUrl).returns(%0A            Q.fcall(function() %7B%0A                throw 'Request failure error message';%0A            %7D)%0A        );%0A%0A        // Act%0A        runner.run(client, urls, reporter, checker).then(function() %7B%0A            // Assert%0A            assert(reporter.summarise.calledWith(%5B%5D, %5BfailingUrl%5D));%0A        %7D).then(done).done();%0A    %7D);
 %0A%7D)%0A

Add unit test for reporting fetch errors