justinhelmer
1/10/2016 - 4:47 PM

pretty rspec testing with helpers

pretty rspec testing with helpers

describe('RETRIEVE logfile', function() {
  var request;

  beforeEach('setting up request', function() {
    request = helpers.request.get('/api/logfile/' + id);

    request.locals = {
      expectLogfile: _.partial(expectLogfile, request)
    };
  });

  it('should prevent access for unauthenticated users', function(done) {
    request.expectUserCheckFailure(done);
  });

  it('should return errors thrown by the api', function(done) {
    request.authenticate();
    helpers.stub('GET', 'API_ERROR');
    request.expect(500, 'API_ERROR', done);
  });

  it('should return an error if the api does not return a valid JSON string', function(done) {
    request.authenticate().expectJSONString(done);
  });

  it('should return the transformed api response', function(done) {
    request.locals.expectLogfile(done);
  });
});