4 . "github.com/onsi/gomega/gexec"
8 . "github.com/onsi/ginkgo"
9 . "github.com/onsi/gomega"
12 type NeverExits struct{}
14 func (e NeverExits) ExitCode() int {
18 var _ = Describe("ExitMatcher", func() {
24 command = exec.Command(fireflyPath, "0")
25 session, err = Start(command, nil, nil)
26 Ω(err).ShouldNot(HaveOccurred())
29 Describe("when passed something that is an Exiter", func() {
30 It("should act normally", func() {
31 failures := InterceptGomegaFailures(func() {
32 Ω(NeverExits{}).Should(Exit())
35 Ω(failures[0]).Should(ContainSubstring("Expected process to exit. It did not."))
39 Describe("when passed something that is not an Exiter", func() {
40 It("should error", func() {
41 failures := InterceptGomegaFailures(func() {
42 Ω("aardvark").Should(Exit())
45 Ω(failures[0]).Should(ContainSubstring("Exit must be passed a gexec.Exiter"))
49 Context("with no exit code", func() {
50 It("should say the right things when it fails", func() {
51 Ω(session).ShouldNot(Exit())
53 failures := InterceptGomegaFailures(func() {
54 Ω(session).Should(Exit())
57 Ω(failures[0]).Should(ContainSubstring("Expected process to exit. It did not."))
59 Eventually(session).Should(Exit())
61 Ω(session).Should(Exit())
63 failures = InterceptGomegaFailures(func() {
64 Ω(session).ShouldNot(Exit())
67 Ω(failures[0]).Should(ContainSubstring("Expected process not to exit. It did."))
71 Context("with an exit code", func() {
72 It("should say the right things when it fails", func() {
73 Ω(session).ShouldNot(Exit(0))
74 Ω(session).ShouldNot(Exit(1))
76 failures := InterceptGomegaFailures(func() {
77 Ω(session).Should(Exit(0))
80 Ω(failures[0]).Should(ContainSubstring("Expected process to exit. It did not."))
82 Eventually(session).Should(Exit(0))
84 Ω(session).Should(Exit(0))
86 failures = InterceptGomegaFailures(func() {
87 Ω(session).Should(Exit(1))
90 Ω(failures[0]).Should(ContainSubstring("to match exit code:"))
92 Ω(session).ShouldNot(Exit(1))
94 failures = InterceptGomegaFailures(func() {
95 Ω(session).ShouldNot(Exit(0))
98 Ω(failures[0]).Should(ContainSubstring("not to match exit code:"))
102 Describe("bailing out early", func() {
103 It("should bail out early once the process exits", func() {
106 failures := InterceptGomegaFailures(func() {
107 Eventually(session).Should(Exit(1))
109 Ω(time.Since(t)).Should(BeNumerically("<=", 500*time.Millisecond))
110 Ω(failures).Should(HaveLen(1))