Context("when making a plan for the build fails due to an error", func() { BeforeEach(func() { factory.CreateReturns(atc.Plan{}, errors.New("to err is human")) }) It("marks the build as finished with an errored status and returns nil", func() { Expect(fakeBuildsDB.FinishBuildCallCount()).To(Equal(1)) buildID, status := fakeBuildsDB.FinishBuildArgsForCall(0) Expect(buildID).To(Equal(build.ID)) Expect(status).To(Equal(db.StatusErrored)) }) Context("when updating the builds status errors", func() { BeforeEach(func() { fakeBuildsDB.FinishBuildReturns(errors.New("but to really foul up requires a computer")) }) It("logs and returns nil", func() { Expect(engineBuild).To(BeNil()) Expect(logger).To(gbytes.Say("failed-to-mark-build-as-errored")) }) }) }) Context("when the plan is created", func() { var plan atc.Plan var fakeEngineBuild *enginefakes.FakeBuild BeforeEach(func() { plan = atc.Plan{}