newAftSuite := func(text string, fail bool) leafnodes.SuiteNode { return leafnodes.NewAfterSuiteNode(func() { writer.AddEvent(text) thingsThatRan = append(thingsThatRan, text) if fail { failer.Fail(text, codelocation.New(0)) } }, codelocation.New(0), 0, failer) } newSpec := func(text string, flag types.FlagType, fail bool) *spec.Spec { subject := leafnodes.NewItNode(text, func() { writer.AddEvent(text) thingsThatRan = append(thingsThatRan, text) if fail { failer.Fail(text, codelocation.New(0)) } }, flag, codelocation.New(0), 0, failer, 0) return spec.New(subject, []*containernode.ContainerNode{}) } newSpecWithBody := func(text string, body interface{}) *spec.Spec { subject := leafnodes.NewItNode(text, body, noneFlag, codelocation.New(0), 0, failer, 0) return spec.New(subject, []*containernode.ContainerNode{}) } newRunner := func(config config.GinkgoConfigType, beforeSuiteNode leafnodes.SuiteNode, afterSuiteNode leafnodes.SuiteNode, specs ...*spec.Spec) *SpecRunner { return New("description", beforeSuiteNode, spec.NewSpecs(specs), afterSuiteNode, []reporters.Reporter{reporter1, reporter2}, writer, config)
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/internal/spec" . "github.com/onsi/gomega" "github.com/onsi/ginkgo/internal/codelocation" "github.com/onsi/ginkgo/internal/containernode" "github.com/onsi/ginkgo/internal/leafnodes" "github.com/onsi/ginkgo/types" ) var _ = Describe("Specs", func() { var specs *Specs newSpec := func(text string, flag types.FlagType) *Spec { subject := leafnodes.NewItNode(text, func() {}, flag, codelocation.New(0), 0, nil, 0) return New(subject, []*containernode.ContainerNode{}) } newMeasureSpec := func(text string, flag types.FlagType) *Spec { subject := leafnodes.NewMeasureNode(text, func(Benchmarker) {}, flag, codelocation.New(0), 0, nil, 0) return New(subject, []*containernode.ContainerNode{}) } newSpecs := func(args ...interface{}) *Specs { specs := []*Spec{} for index := 0; index < len(args)-1; index += 2 { specs = append(specs, newSpec(args[index].(string), args[index+1].(types.FlagType))) } return NewSpecs(specs) }
nodesThatRan []string spec *Spec buffer *gbytes.Buffer ) newBody := func(text string, fail bool) func() { return func() { nodesThatRan = append(nodesThatRan, text) if fail { failer.Fail(text, codeLocation) } } } newIt := func(text string, flag types.FlagType, fail bool) *leafnodes.ItNode { return leafnodes.NewItNode(text, newBody(text, fail), flag, codeLocation, 0, failer, 0) } newItWithBody := func(text string, body interface{}) *leafnodes.ItNode { return leafnodes.NewItNode(text, body, noneFlag, codeLocation, 0, failer, 0) } newMeasure := func(text string, flag types.FlagType, fail bool, samples int) *leafnodes.MeasureNode { return leafnodes.NewMeasureNode(text, func(Benchmarker) { nodesThatRan = append(nodesThatRan, text) if fail { failer.Fail(text, codeLocation) } }, flag, codeLocation, samples, failer, 0) }
func (suite *Suite) PushItNode(text string, body interface{}, flag types.FlagType, codeLocation types.CodeLocation, timeout time.Duration) { if suite.running { suite.failer.Fail("You may only call It from within another It/Measure/BeforeEach/JustBeforeEach/AfterEach", codeLocation) } suite.currentContainer.PushSubjectNode(leafnodes.NewItNode(text, body, flag, codeLocation, timeout, suite.failer, suite.containerIndex)) }
It("can append setup nodes of various types and fetch them by type", func() { befA := leafnodes.NewBeforeEachNode(func() {}, codelocation.New(0), 0, nil, 0) befB := leafnodes.NewBeforeEachNode(func() {}, codelocation.New(0), 0, nil, 0) aftA := leafnodes.NewAfterEachNode(func() {}, codelocation.New(0), 0, nil, 0) aftB := leafnodes.NewAfterEachNode(func() {}, codelocation.New(0), 0, nil, 0) jusBefA := leafnodes.NewJustBeforeEachNode(func() {}, codelocation.New(0), 0, nil, 0) jusBefB := leafnodes.NewJustBeforeEachNode(func() {}, codelocation.New(0), 0, nil, 0) container.PushSetupNode(befA) container.PushSetupNode(befB) container.PushSetupNode(aftA) container.PushSetupNode(aftB) container.PushSetupNode(jusBefA) container.PushSetupNode(jusBefB) subject := leafnodes.NewItNode("subject", func() {}, types.FlagTypeNone, codelocation.New(0), 0, nil, 0) container.PushSubjectNode(subject) Ω(container.SetupNodesOfType(types.SpecComponentTypeBeforeEach)).Should(Equal([]leafnodes.BasicNode{befA, befB})) Ω(container.SetupNodesOfType(types.SpecComponentTypeAfterEach)).Should(Equal([]leafnodes.BasicNode{aftA, aftB})) Ω(container.SetupNodesOfType(types.SpecComponentTypeJustBeforeEach)).Should(Equal([]leafnodes.BasicNode{jusBefA, jusBefB})) Ω(container.SetupNodesOfType(types.SpecComponentTypeIt)).Should(BeEmpty()) //subjects are not setup nodes }) }) Context("With appended containers and subject nodes", func() { var ( itA, itB, innerItA, innerItB leafnodes.SubjectNode innerContainer *ContainerNode )
func (suite *Suite) PushItNode(text string, body interface{}, flag types.FlagType, codeLocation types.CodeLocation, timeout time.Duration) { if suite.running { suite.failer.Fail("You may only call It from within a Describe or Context", codeLocation) } suite.currentContainer.PushSubjectNode(leafnodes.NewItNode(text, body, flag, codeLocation, timeout, suite.failer, suite.containerIndex)) }
func (suite *Suite) PushItNode(text string, body interface{}, flag types.FlagType, codeLocation types.CodeLocation, timeout time.Duration) { suite.currentContainer.PushSubjectNode(leafnodes.NewItNode(text, body, flag, codeLocation, timeout, suite.failer, suite.containerIndex)) }
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/internal/spec" . "github.com/onsi/gomega" "github.com/onsi/ginkgo/internal/codelocation" "github.com/onsi/ginkgo/internal/containernode" "github.com/onsi/ginkgo/internal/leafnodes" "github.com/onsi/ginkgo/types" ) var _ = Describe("Specs", func() { var specs *Specs newSpec := func(text string, flag types.FlagType) *Spec { subject := leafnodes.NewItNode(text, func() {}, flag, codelocation.New(0), 0, nil, 0) return New(subject, []*containernode.ContainerNode{}, false) } newMeasureSpec := func(text string, flag types.FlagType) *Spec { subject := leafnodes.NewMeasureNode(text, func(Benchmarker) {}, flag, codelocation.New(0), 0, nil, 0) return New(subject, []*containernode.ContainerNode{}, false) } newSpecs := func(args ...interface{}) *Specs { specs := []*Spec{} for index := 0; index < len(args)-1; index += 2 { specs = append(specs, newSpec(args[index].(string), args[index+1].(types.FlagType))) } return NewSpecs(specs) }