How to use BePending method of test_helpers Package

Best Ginkgo code snippet using test_helpers.BePending

Run Ginkgo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

config_dry_run_test.go

Source: config_dry_run_test.go Github

copy
1package internal_integration_test
2
3import (
4	. "github.com/onsi/ginkgo/v2"
5	. "github.com/onsi/ginkgo/v2/internal/test_helpers"
6	. "github.com/onsi/gomega"
7)
8
9var _ = Describe("when config.DryRun is enabled", func() {
10	BeforeEach(func() {
11		conf.DryRun = true
12		conf.SkipStrings = []string{"E"}
13
14		RunFixture("dry run", func() {
15			BeforeSuite(rt.T("before-suite"))
16			BeforeEach(rt.T("bef"))
17			ReportBeforeEach(func(_ SpecReport) { rt.Run("report-before-each") })
18			Describe("container", func() {
19				It("A", rt.T("A"))
20				It("B", rt.T("B", func() { F() }))
21				PIt("C", rt.T("C", func() { F() }))
22				It("D", rt.T("D"))
23				It("E", rt.T("D"))
24			})
25			AfterEach(rt.T("aft"))
26			AfterSuite(rt.T("after-suite"))
27			ReportAfterEach(func(_ SpecReport) { rt.Run("report-after-each") })
28			ReportAfterSuite("", func(_ Report) { rt.Run("report-after-suite") })
29		})
30	})
31
32	It("does not run any tests", func() {
33		Ω(rt).Should(HaveTrackedNothing())
34	})
35
36	It("reports on the tests (both that they will run and that they did run) and honors skip state", func() {
37		Ω(reporter.Will.Names()).Should(Equal([]string{"A", "B", "C", "D", "E"}))
38		Ω(reporter.Will.Find("C")).Should(BePending())
39		Ω(reporter.Will.Find("E")).Should(HaveBeenSkipped())
40
41		Ω(reporter.Did.Names()).Should(Equal([]string{"A", "B", "C", "D", "E"}))
42		Ω(reporter.Did.Find("A")).Should(HavePassed())
43		Ω(reporter.Did.Find("B")).Should(HavePassed())
44		Ω(reporter.Did.Find("C")).Should(BePending())
45		Ω(reporter.Did.Find("D")).Should(HavePassed())
46		Ω(reporter.Did.Find("E")).Should(HaveBeenSkipped())
47	})
48
49	It("reports the correct statistics", func() {
50		Ω(reporter.End).Should(BeASuiteSummary(NSpecs(5), NPassed(3), NPending(1), NSkipped(1)))
51	})
52})
53
Full Screen

filter_test.go

Source: filter_test.go Github

copy
1package integration_test
2
3import (
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	. "github.com/onsi/ginkgo/v2/internal/test_helpers"
12	"github.com/onsi/ginkgo/v2/types"
13)
14
15var _ = Describe("Filter", func() {
16	BeforeEach(func() {
17		fm.MountFixture("filter")
18	})
19
20	It("honors the focus, skip, focus-file and skip-file flags", func() {
21		session := startGinkgo(fm.PathTo("filter"),
22			"--focus=dog", "--focus=fish",
23			"--skip=cat",
24			"--focus-file=sprocket", "--focus-file=widget:1-24", "--focus-file=_b:24-42",
25			"--skip-file=_c",
26			"--json-report=report.json",
27			"--label-filter=TopLevelLabel && !SLOW",
28		)
29		Eventually(session).Should(gexec.Exit(0))
30		specs := Reports(fm.LoadJSONReports("filter", "report.json")[0].SpecReports)
31
32		passedSpecs := []string{
33			"SprocketA dog fish",
34			"SprocketB dog", "SprocketB dog fish",
35			"WidgetA dog", "WidgetA dog fish",
36			"WidgetB dog fish",
37			// lines in _b > 24 are in --focus-file
38			"More WidgetB dog", "More WidgetB dog fish",
39		}
40
41		skippedSpecs := []string{
42			// nugget files are not in focus-file
43			"NuggetA cat", "NuggetA dog", "NuggetA cat fish", "NuggetA dog fish",
44			"NuggetB cat", "NuggetB dog", "NuggetB cat fish", "NuggetB dog fish",
45			// cat is not in -focus
46			"SprocketA cat", "SprocketB cat", "WidgetA cat", "WidgetB cat", "More WidgetB cat",
47			// fish is in -focus but cat is in -skip
48			"SprocketA cat fish", "SprocketB cat fish", "WidgetA cat fish", "WidgetB cat fish", "More WidgetB cat fish",
49			// Tests labelled 'slow'
50			"WidgetB dog",
51			"SprocketB fish",
52			// _c is in -skip-file
53			"SprocketC cat", "SprocketC dog", "SprocketC cat fish", "SprocketC dog fish",
54			// lines in widget > 24 are not in --focus-file
55			"More WidgetA cat", "More WidgetA dog", "More WidgetA cat fish", "More WidgetA dog fish",
56		}
57		pendingSpecs := []string{
58			"SprocketA pending dog",
59		}
60
61		Ω(specs).Should(HaveLen(len(passedSpecs) + len(skippedSpecs) + len(pendingSpecs)))
62
63		for _, text := range passedSpecs {
64			Ω(specs.FindByFullText(text)).Should(HavePassed(), text)
65		}
66		for _, text := range skippedSpecs {
67			Ω(specs.FindByFullText(text)).Should(HaveBeenSkipped(), text)
68		}
69		for _, text := range pendingSpecs {
70			Ω(specs.FindByFullText(text)).Should(BePending(), text)
71		}
72	})
73
74	It("ignores empty filter flags", func() {
75		session := startGinkgo(fm.PathTo("filter"),
76			"--focus=", "--skip=",
77			"--json-report=report.json",
78		)
79		Eventually(session).Should(gexec.Exit(types.GINKGO_FOCUS_EXIT_CODE))
80		specs := Reports(fm.LoadJSONReports("filter", "report.json")[0].SpecReports)
81		for _, spec := range specs {
82			if strings.HasPrefix(spec.FullText(), "SprocketC") {
83				Ω(spec).Should(HavePassed())
84			} else {
85				Ω(spec).Should(Or(HaveBeenSkipped(), BePending()))
86			}
87		}
88	})
89
90	It("errors if the file-filter format is wrong", func() {
91		session := startGinkgo(fm.PathTo("filter"), "--focus-file=foo:bar", "--skip-file=")
92		Eventually(session).Should(gexec.Exit(1))
93		Ω(session).Should(gbytes.Say("Invalid File Filter"))
94		Ω(session).Should(gbytes.Say("Invalid File Filter"))
95	})
96
97	Describe("Listing labels", func() {
98		BeforeEach(func() {
99			fm.MountFixture("labels")
100		})
101
102		It("can list labels", func() {
103			session := startGinkgo(fm.TmpDir, "labels", "-r")
104			Eventually(session).Should(gexec.Exit(0))
105			Ω(session).Should(gbytes.Say(`filter: \["TopLevelLabel", "slow"\]`))
106			Ω(session).Should(gbytes.Say(`labels: \["beluga", "bird", "cat", "chicken", "cow", "dog", "giraffe", "koala", "monkey", "otter", "owl", "panda"\]`))
107			Ω(session).Should(gbytes.Say(`nolabels: No labels found`))
108			Ω(session).Should(gbytes.Say(`onepkg: \["beluga", "bird", "cat", "chicken", "cow", "dog", "giraffe", "koala", "monkey", "otter", "owl", "panda"\]`))
109		})
110	})
111})
112
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)