...

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

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

     1  package integration_test
     2  
     3  import (
     4  	"strings"
     5  
     6  	. "github.com/onsi/ginkgo/v2"
     7  	. "github.com/onsi/gomega"
     8  	"github.com/onsi/gomega/gbytes"
     9  	"github.com/onsi/gomega/gexec"
    10  )
    11  
    12  func extractRandomSeeds(content string) []string {
    13  	lines := strings.Split(content, "\n")
    14  	randomSeeds := []string{}
    15  	for _, line := range lines {
    16  		if strings.Contains(line, "Random Seed:") {
    17  			randomSeeds = append(randomSeeds, strings.Split(line, ": ")[1])
    18  		}
    19  	}
    20  	return randomSeeds
    21  }
    22  
    23  var _ = Describe("Repeat", func() {
    24  	Context("when a test attempts to invoke RunSpecs twice", func() {
    25  		BeforeEach(func() {
    26  			fm.MountFixture("rerun_specs")
    27  		})
    28  
    29  		It("errors out and tells the user not to do that", func() {
    30  			session := startGinkgo(fm.PathTo("rerun_specs"))
    31  			Eventually(session).Should(gexec.Exit())
    32  			Ω(session).Should(gbytes.Say("It looks like you are calling RunSpecs more than once."))
    33  		})
    34  	})
    35  
    36  	Context("when told to keep going --until-it-fails", func() {
    37  		BeforeEach(func() {
    38  			fm.MountFixture("eventually_failing")
    39  		})
    40  
    41  		It("should keep rerunning the tests, until a failure occurs", func() {
    42  			session := startGinkgo(fm.PathTo("eventually_failing"), "--until-it-fails", "--no-color")
    43  			Eventually(session).Should(gexec.Exit(1))
    44  			Ω(session).Should(gbytes.Say("This was attempt #1"))
    45  			Ω(session).Should(gbytes.Say("This was attempt #2"))
    46  			Ω(session).Should(gbytes.Say("Tests failed on attempt #3"))
    47  
    48  			//it should change the random seed between each test
    49  			randomSeeds := extractRandomSeeds(string(session.Out.Contents()))
    50  			Ω(randomSeeds[0]).ShouldNot(Equal(randomSeeds[1]))
    51  			Ω(randomSeeds[1]).ShouldNot(Equal(randomSeeds[2]))
    52  			Ω(randomSeeds[0]).ShouldNot(Equal(randomSeeds[2]))
    53  		})
    54  	})
    55  
    56  	Context("when told to --repeat", func() {
    57  		BeforeEach(func() {
    58  			fm.MountFixture("eventually_failing")
    59  		})
    60  
    61  		Context("when the test passes for N repetitions", func() {
    62  			It("should run the tests N+1 times and report success", func() {
    63  				session := startGinkgo(fm.PathTo("eventually_failing"), "--repeat=1", "--no-color")
    64  				Eventually(session).Should(gexec.Exit(0))
    65  				Ω(session).Should(gbytes.Say("This was attempt 1 of 2"))
    66  
    67  				//it should change the random seed between each test
    68  				randomSeeds := extractRandomSeeds(string(session.Out.Contents()))
    69  				Ω(randomSeeds[0]).ShouldNot(Equal(randomSeeds[1]))
    70  			})
    71  		})
    72  
    73  		Context("when the test eventually fails", func() {
    74  			It("should report failure and stop running", func() {
    75  				session := startGinkgo(fm.PathTo("eventually_failing"), "--repeat=3", "--no-color")
    76  				Eventually(session).Should(gexec.Exit(1))
    77  				Ω(session).Should(gbytes.Say("This was attempt 1 of 4"))
    78  				Ω(session).Should(gbytes.Say("This was attempt 2 of 4"))
    79  				Ω(session).Should(gbytes.Say("Tests failed on attempt #3"))
    80  
    81  				//it should change the random seed between each test
    82  				randomSeeds := extractRandomSeeds(string(session.Out.Contents()))
    83  				Ω(randomSeeds[0]).ShouldNot(Equal(randomSeeds[1]))
    84  				Ω(randomSeeds[1]).ShouldNot(Equal(randomSeeds[2]))
    85  				Ω(randomSeeds[0]).ShouldNot(Equal(randomSeeds[2]))
    86  			})
    87  		})
    88  	})
    89  
    90  	Context("if both --repeat and --until-it-fails are set", func() {
    91  		BeforeEach(func() {
    92  			fm.MountFixture("eventually_failing")
    93  		})
    94  
    95  		It("errors out early", func() {
    96  			session := startGinkgo(fm.PathTo("eventually_failing"), "--repeat=3", "--until-it-fails", "--no-color")
    97  			Eventually(session).Should(gexec.Exit(1))
    98  			Ω(session.Err).Should(gbytes.Say("--repeat and --until-it-fails are both set"))
    99  		})
   100  	})
   101  
   102  	Context("if MustPassRepeatedly is set at suite config level", func() {
   103  		BeforeEach(func() {
   104  			fm.MountFixture("config_override_must_pass_repeatedly")
   105  		})
   106  
   107  		It("it should override node decorator", func() {
   108  			session := startGinkgo(fm.PathTo("config_override_must_pass_repeatedly"))
   109  			Eventually(session).Should(gexec.Exit(0))
   110  		})
   111  	})
   112  })
   113  

View as plain text