}) It("fails with error", func() { Expect(runCLIerr).To(HaveOccurred()) Expect(runCLIerr.Error()).To(Equal("Error refreshing oauth token: auth-error")) }) }) Context("when refreshing the token succeeds", func() { BeforeEach(func() { authRepo.RefreshAuthTokenReturns("auth-token", nil) }) It("tries to get the ssh-code", func() { Expect(runCLIerr).NotTo(HaveOccurred()) Expect(authRepo.AuthorizeCallCount()).To(Equal(1)) Expect(authRepo.AuthorizeArgsForCall(0)).To(Equal("auth-token")) }) Context("when getting the ssh-code succeeds", func() { BeforeEach(func() { authRepo.AuthorizeReturns("some-code", nil) }) It("displays the token", func() { Expect(runCLIerr).NotTo(HaveOccurred()) Expect(ui.Outputs()).To(ContainSubstrings( []string{"some-code"}, )) }) })