ValidateInteractionsWithLockHandler := func(expectedNumberOfInteractions int) { Ω(fakeLockHandler.BroadcastLockPoolCallCount()).Should(Equal(expectedNumberOfInteractions)) additionalValidation(expectedNumberOfInteractions) } Context("when broadcasting fails with ", func() { Context("for an unexpected reason", func() { BeforeEach(func() { called := false fakeLockHandler.BroadcastLockPoolStub = func() ([]byte, error) { // succeed on second call if !called { called = true return nil, errors.New("disaster") } else { return nil, nil } } }) It("logs an error as it retries", func() { err := operationUnderTest() Ω(err).ShouldNot(HaveOccurred()) Ω(output).Should(gbytes.Say("err")) ValidateInteractionsWithLockHandler(2) })