...

Source file src/github.com/onsi/ginkgo/v2/integration/fail_test.go

Documentation: github.com/onsi/ginkgo/v2/integration

     1  package integration_test
     2  
     3  import (
     4  	. "github.com/onsi/ginkgo/v2"
     5  	. "github.com/onsi/gomega"
     6  	"github.com/onsi/gomega/gexec"
     7  )
     8  
     9  var _ = Describe("Failing Specs", func() {
    10  	Describe("when the tests contain failures", func() {
    11  		BeforeEach(func() {
    12  			fm.MountFixture("fail")
    13  		})
    14  
    15  		It("should fail in all the possible ways", func() {
    16  			session := startGinkgo(fm.PathTo("fail"), "--no-color")
    17  			Eventually(session).Should(gexec.Exit(1))
    18  			output := string(session.Out.Contents())
    19  
    20  			Ω(output).ShouldNot(ContainSubstring("NEVER SEE THIS"))
    21  
    22  			Ω(output).Should(ContainSubstring("a top level failure on line 12"))
    23  			Ω(output).Should(ContainSubstring("fail_fixture_test.go:12"))
    24  
    25  			Ω(output).Should(ContainSubstring("a sync failure"))
    26  			Ω(output).Should(MatchRegexp(`Test Panicked`))
    27  			Ω(output).Should(MatchRegexp(`a sync panic`))
    28  			Ω(output).Should(ContainSubstring("a sync FAIL failure"))
    29  
    30  			Ω(output).Should(ContainSubstring("a top level specify"))
    31  			Ω(output).ShouldNot(ContainSubstring("ginkgo_dsl.go"))
    32  			Ω(output).Should(ContainSubstring("fail_fixture_test.go:38"))
    33  
    34  			Ω(output).Should(ContainSubstring("[TIMEDOUT]"))
    35  			Ω(output).Should(MatchRegexp(`goroutine \d+ \[chan receive\]`), "from the progress report emitted by the timeout")
    36  			Ω(output).Should(MatchRegexp(`>\s*\<\-c\.Done\(\)`), "from the progress report emitted by the timeout")
    37  
    38  			Ω(output).Should(MatchRegexp(`a top level DescribeTable \[It\] a TableEntry constructed by Entry\n.*fail_fixture_test\.go:45`),
    39  				"the output of a failing Entry should include its file path and line number")
    40  
    41  			Ω(output).Should(ContainSubstring(`a helper failed`))
    42  			Ω(output).Should(ContainSubstring(`fail_fixture_test.go:54`), "the code location reported for the helper failure - we're testing the call to GinkgoHelper() works as expected")
    43  
    44  			Ω(output).Should(ContainSubstring("synchronous failures with GinkgoT().Fail"))
    45  			Ω(output).Should(ContainSubstring("fail_fixture_ginkgo_t_test.go:9"))
    46  
    47  			Ω(output).Should(ContainSubstring("GinkgoT DescribeTable"))
    48  			Ω(output).Should(ContainSubstring("fail_fixture_ginkgo_t_test.go:15"))
    49  
    50  			Ω(output).Should(ContainSubstring(`tracks line numbers correctly when GinkgoT().Helper() is called`))
    51  			Ω(output).Should(ContainSubstring(`fail_fixture_ginkgo_t_test.go:21`), "the code location reported for the ginkgoT helper failure")
    52  
    53  			Ω(output).Should(ContainSubstring(`tracks the actual line number when no helper is used`))
    54  			Ω(output).Should(ContainSubstring(`fail_fixture_ginkgo_t_test.go:30`), "the code location reported for the ginkgoT no helper failure")
    55  
    56  			Ω(output).Should(ContainSubstring("synchronous failures with GinkgoTB().Fail"))
    57  			Ω(output).Should(ContainSubstring("fail_fixture_ginkgo_tb_test.go:9"))
    58  
    59  			Ω(output).Should(ContainSubstring("GinkgoTB DescribeTable"))
    60  			Ω(output).Should(ContainSubstring("fail_fixture_ginkgo_tb_test.go:15"))
    61  
    62  			Ω(output).Should(ContainSubstring(`tracks line numbers correctly when GinkgoTB().Helper() is called`))
    63  			Ω(output).Should(ContainSubstring(`fail_fixture_ginkgo_tb_test.go:21`), "the code location reported for the ginkgoTB helper failure")
    64  
    65  			Ω(output).Should(ContainSubstring(`tracks the actual line number when no GinkgoTB helper is used`))
    66  			Ω(output).Should(ContainSubstring(`fail_fixture_ginkgo_tb_test.go:30`), "the code location reported for the ginkgoT no helper failure")
    67  
    68  			Ω(output).Should(ContainSubstring("0 Passed | 16 Failed"))
    69  		})
    70  	})
    71  
    72  	Describe("when the tests are incorrectly structured", func() {
    73  		BeforeEach(func() {
    74  			fm.MountFixture("malformed")
    75  		})
    76  
    77  		It("exits early with a helpful error message", func() {
    78  			session := startGinkgo(fm.PathTo("malformed"), "--no-color")
    79  			Eventually(session).Should(gexec.Exit(1))
    80  			output := string(session.Out.Contents())
    81  
    82  			Ω(output).Should(ContainSubstring("Ginkgo detected an issue with your spec structure"))
    83  			Ω(output).Should(ContainSubstring("malformed_fixture_test.go:9"))
    84  		})
    85  
    86  		It("emits the error message even if running in parallel", func() {
    87  			session := startGinkgo(fm.PathTo("malformed"), "--no-color", "--procs=2")
    88  			Eventually(session).Should(gexec.Exit(1))
    89  			output := string(session.Out.Contents()) + string(session.Err.Contents())
    90  
    91  			Ω(output).Should(ContainSubstring("Ginkgo detected an issue with your spec structure"))
    92  			Ω(output).Should(ContainSubstring("malformed_fixture_test.go:9"))
    93  		})
    94  	})
    95  
    96  	Describe("when By is called outside of a runnable node", func() {
    97  		BeforeEach(func() {
    98  			fm.MountFixture("malformed_by")
    99  		})
   100  
   101  		It("exits early with a helpful error message", func() {
   102  			session := startGinkgo(fm.PathTo("malformed_by"), "--no-color", "--procs=2")
   103  			Eventually(session).Should(gexec.Exit(1))
   104  			output := string(session.Out.Contents()) + string(session.Err.Contents())
   105  
   106  			Ω(output).Should(ContainSubstring("Ginkgo detected an issue with your spec structure"))
   107  			Ω(output).Should(ContainSubstring("malformed_by_fixture_suite_test.go:16"))
   108  
   109  		})
   110  	})
   111  })
   112  

View as plain text