From dd826c83aa4e76a88fd70f8fe0c51b1b7829c6e4 Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Mon, 30 Oct 2017 22:07:26 +0000 Subject: [PATCH] Add a When() synonym for Context() (#348) --- ginkgo_dsl.go | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/ginkgo_dsl.go b/ginkgo_dsl.go index 7e63bd21a..a3bbc436e 100644 --- a/ginkgo_dsl.go +++ b/ginkgo_dsl.go @@ -275,9 +275,9 @@ func GinkgoRecover() { //Describe blocks allow you to organize your specs. A Describe block can contain any number of //BeforeEach, AfterEach, JustBeforeEach, It, and Measurement blocks. // -//In addition you can nest Describe and Context blocks. Describe and Context blocks are functionally +//In addition you can nest Describe, Context and When blocks. Describe, Context and When blocks are functionally //equivalent. The difference is purely semantic -- you typical Describe the behavior of an object -//or method and, within that Describe, outline a number of Contexts. +//or method and, within that Describe, outline a number of Contexts and Whens. func Describe(text string, body func()) bool { globalSuite.PushContainerNode(text, body, types.FlagTypeNone, codelocation.New(1)) return true @@ -304,9 +304,9 @@ func XDescribe(text string, body func()) bool { //Context blocks allow you to organize your specs. A Context block can contain any number of //BeforeEach, AfterEach, JustBeforeEach, It, and Measurement blocks. // -//In addition you can nest Describe and Context blocks. Describe and Context blocks are functionally +//In addition you can nest Describe, Context and When blocks. Describe and Context blocks are functionally //equivalent. The difference is purely semantic -- you typical Describe the behavior of an object -//or method and, within that Describe, outline a number of Contexts. +//or method and, within that Describe, outline a number of Contexts and Whens. func Context(text string, body func()) bool { globalSuite.PushContainerNode(text, body, types.FlagTypeNone, codelocation.New(1)) return true @@ -330,6 +330,35 @@ func XContext(text string, body func()) bool { return true } +//When blocks allow you to organize your specs. A When block can contain any number of +//BeforeEach, AfterEach, JustBeforeEach, It, and Measurement blocks. +// +//In addition you can nest Describe, Context and When blocks. Describe, Context and When blocks are functionally +//equivalent. The difference is purely semantic -- you typical Describe the behavior of an object +//or method and, within that Describe, outline a number of Contexts and Whens. +func When(text string, body func()) bool { + globalSuite.PushContainerNode("when "+text, body, types.FlagTypeNone, codelocation.New(1)) + return true +} + +//You can focus the tests within a describe block using FWhen +func FWhen(text string, body func()) bool { + globalSuite.PushContainerNode("when "+text, body, types.FlagTypeFocused, codelocation.New(1)) + return true +} + +//You can mark the tests within a describe block as pending using PWhen +func PWhen(text string, body func()) bool { + globalSuite.PushContainerNode("when "+text, body, types.FlagTypePending, codelocation.New(1)) + return true +} + +//You can mark the tests within a describe block as pending using XWhen +func XWhen(text string, body func()) bool { + globalSuite.PushContainerNode("when "+text, body, types.FlagTypePending, codelocation.New(1)) + return true +} + //It blocks contain your test code and assertions. You cannot nest any other Ginkgo blocks //within an It block. //