BeforeEach(func() { fakeLockHandler.ResetLockReturns(errors.New("some-error")) }) It("returns an error", func() { _, _, err := lockPool.AcquireLock() Ω(err).Should(HaveOccurred()) }) }) Context("when resetting the lock succeeds", func() { It("tries to acquire an available lock", func() { _, _, err := lockPool.AcquireLock() Ω(err).ShouldNot(HaveOccurred()) Ω(fakeLockHandler.GrabAvailableLockCallCount()).Should(Equal(1)) }) Context("when grabbing an available lock fails", func() { BeforeEach(func() { called := false fakeLockHandler.GrabAvailableLockStub = func() (string, string, error) { // succeed on second call if !called { called = true return "", "", errors.New("disaster") } else { return "", "", nil } }