fakeLockHandler.SetupReturns(errors.New("some-error"))
				})

				It("returns an error", func() {
					_, _, err := lockPool.AddUnclaimedLock(lockDir)
					Ω(err).Should(HaveOccurred())
				})
			})

			Context("when setup succeeds", func() {
				It("tries to add the lock it found in the name file", func() {
					_, _, err := lockPool.AddUnclaimedLock(lockDir)
					Ω(err).ShouldNot(HaveOccurred())

					Ω(fakeLockHandler.AddLockCallCount()).Should(Equal(1))
					lockName, lockContents, initiallyClaimed := fakeLockHandler.AddLockArgsForCall(0)
					Ω(lockName).Should(Equal("some-lock"))
					Ω(string(lockContents)).Should(Equal("lock-contents"))
					Ω(initiallyClaimed).Should(BeFalse())
				})

				Context("when adding the lock fails", func() {
					BeforeEach(func() {
						called := false

						fakeLockHandler.AddLockStub = func(_ string, _ []byte, _ bool) (string, error) {
							// succeed on second call
							if !called {
								called = true
								return "", errors.New("disaster")
							} else {
					fakeLockHandler.SetupReturns(errors.New("some-error"))
				})

				It("returns an error", func() {
					_, _, err := lockPool.AddLock(lockDir)
					Ω(err).Should(HaveOccurred())
				})
			})

			Context("when setup succeeds", func() {
				It("tries to add the lock it found in the name file", func() {
					_, _, err := lockPool.AddLock(lockDir)
					Ω(err).ShouldNot(HaveOccurred())

					Ω(fakeLockHandler.AddLockCallCount()).Should(Equal(1))
					lockName, lockContents := fakeLockHandler.AddLockArgsForCall(0)
					Ω(lockName).Should(Equal("some-lock"))
					Ω(string(lockContents)).Should(Equal("lock-contents"))
				})

				Context("when adding the lock fails", func() {
					BeforeEach(func() {
						called := false

						fakeLockHandler.AddLockStub = func(lockName string, lockContents []byte) (string, error) {
							// succeed on second call
							if !called {
								called = true
								return "", errors.New("disaster")
							} else {
								return "some-ref", nil