})

	AfterEach(func() {
		gitRepo.AssertExpectations(GinkgoT())
	})

	Context("with autosquash failing", func() {
		BeforeEach(func() {
			gitRepo.
				On("RebaseAutosquash", "origin/"+baseRef, headSHA).
				Return(errors.New("merge conflict"))
		})

		It("reports the failure", func() {
			repositories.
				On("CreateStatus", repositoryOwner, repositoryName, headSHA, mock.MatchedBy(func(status *github.RepoStatus) bool {
					return *status.State == "failure" && *status.Context == "review/squash"
				})).
				Return(nil, nil, nil)

			handle()

			Expect(responseRecorder.Code).To(Equal(http.StatusOK))
		})
	})

	Context("with autosquash succeeding", func() {
		BeforeEach(func() {
			gitRepo.
				On("RebaseAutosquash", "origin/"+baseRef, headSHA).
				Return(nil)
		})
					Head: &github.PullRequestBranch{
						SHA:  github.String(headSHA),
						Ref:  github.String("feature"),
						Repo: repository,
					},
				}

				BeforeEach(func() {
					pullRequests.
						On("Get", repositoryOwner, repositoryName, issueNumber).
						Return(pr, nil, nil)
				})

				Context("with combined state being failing", func() {
					BeforeEach(func() {
						repositories.
							On("GetCombinedStatus", repositoryOwner, repositoryName, headSHA, mock.AnythingOfType("*github.ListOptions")).
							Return(&github.CombinedStatus{
								State: github.String("failing"),
							}, &github.Response{}, nil)
					})

					It("succeeds", func() {
						handle()
						Expect(responseRecorder.Code).To(Equal(http.StatusOK))
					})
				})

				Context("with a pending squash status in paged combined status request", func() {
					BeforeEach(func() {
						repositories.
							On("GetCombinedStatus", repositoryOwner, repositoryName, headSHA, &github.ListOptions{