Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Prepend 'when' when using When
  • Loading branch information
onsi committed Apr 26, 2022
1 parent a7bd1fe commit efce903
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
18 changes: 17 additions & 1 deletion core_dsl.go
Expand Up @@ -421,7 +421,23 @@ var XDescribe = PDescribe
var Context, FContext, PContext, XContext = Describe, FDescribe, PDescribe, XDescribe

/* When is an alias for Describe - it generates the exact same kind of Container node */
var When, FWhen, PWhen, XWhen = Describe, FDescribe, PDescribe, XDescribe
func When(text string, args ...interface{}) bool {
return pushNode(internal.NewNode(deprecationTracker, types.NodeTypeContainer, "when "+text, args...))
}

/* When is an alias for Describe - it generates the exact same kind of Container node */
func FWhen(text string, args ...interface{}) bool {
args = append(args, internal.Focus)
return pushNode(internal.NewNode(deprecationTracker, types.NodeTypeContainer, "when "+text, args...))
}

/* When is an alias for Describe - it generates the exact same kind of Container node */
func PWhen(text string, args ...interface{}) bool {
args = append(args, internal.Pending)
return pushNode(internal.NewNode(deprecationTracker, types.NodeTypeContainer, "when "+text, args...))
}

var XWhen = PWhen

/*
It nodes are Subject nodes that contain your spec code and assertions.
Expand Down
2 changes: 1 addition & 1 deletion integration/progress_test.go
Expand Up @@ -56,7 +56,7 @@ var _ = Describe("Emitting progress", func() {
Ω(session).Should(gbytes.Say(`\[BeforeEach\] Inner Context`))
Ω(session).Should(gbytes.Say(`>inner before<`))

Ω(session).Should(gbytes.Say(`\[BeforeEach\] Inner When`))
Ω(session).Should(gbytes.Say(`\[BeforeEach\] when Inner When`))
Ω(session).Should(gbytes.Say(`>inner before<`))

Ω(session).Should(gbytes.Say(`\[JustBeforeEach\] ProgressFixture`))
Expand Down
6 changes: 6 additions & 0 deletions internal/suite_test.go
Expand Up @@ -384,5 +384,11 @@ var _ = Describe("Suite", func() {
})
})
})

When("using when", func() {
It("prepends 'when' to the test name", func() {
Ω(CurrentSpecReport().FullText()).Should(ContainSubstring(" when using when prepends"))
})
})
})
})

0 comments on commit efce903

Please sign in to comment.