It("responds with a relevant error message", func() { err := json.Unmarshal(garbageRequest, &receptor.TaskCreateRequest{}) expectedBody, _ := json.Marshal(receptor.Error{ Type: receptor.InvalidJSON, Message: err.Error(), }) Expect(responseRecorder.Body.String()).To(Equal(string(expectedBody))) }) }) }) Describe("GetAll", func() { Context("when reading tasks from the BBS fails", func() { BeforeEach(func() { fakeClient.TasksReturns(nil, errors.New("Something went wrong")) }) It("responds with an error", func() { handler.GetAll(responseRecorder, newTestRequest("")) Expect(responseRecorder.Code).To(Equal(http.StatusInternalServerError)) }) }) Context("when reading tasks from BBS succeeds", func() { var domain1Task, domain2Task *models.Task BeforeEach(func() { domain1Task = model_helpers.NewValidTask("task-guid-1") domain1Task.Domain = "domain-1" domain2Task = model_helpers.NewValidTask("task-guid-2")