You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/index.md
+104-1
Original file line number
Diff line number
Diff line change
@@ -1378,7 +1378,7 @@ DescribeTable("Extracting the author's first and last name",
1378
1378
You'll be notified with a clear message at runtime if the parameter types don't match the spec closure signature.
1379
1379
1380
1380
#### Mental Model: Table Specs are just Syntactic Sugar
1381
-
`DescribeTable` is simply providing syntactic sugar to convert its Ls into a set of standard Ginkgo nodes. During the [Tree Construction Phase](#mental-model-how-ginkgo-traverses-the-spec-hierarchy)`DescribeTable` is generating a single container node that contains one subject node per table entry. The description for the container node will be the description passed to `DescribeTable` and the descriptions for the subject nodes will be the descriptions passed to the `Entry`s. During the Run Phase, when specs run, each subject node will simply invoke the spec closure passed to `DescribeTable`, passing in the parameters associated with the `Entry`.
1381
+
`DescribeTable` is simply providing syntactic sugar to convert its entries into a set of standard Ginkgo nodes. During the [Tree Construction Phase](#mental-model-how-ginkgo-traverses-the-spec-hierarchy)`DescribeTable` is generating a single container node that contains one subject node per table entry. The description for the container node will be the description passed to `DescribeTable` and the descriptions for the subject nodes will be the descriptions passed to the `Entry`s. During the Run Phase, when specs run, each subject node will simply invoke the spec closure passed to `DescribeTable`, passing in the parameters associated with the `Entry`.
1382
1382
1383
1383
To put it another way, the table test above is equivalent to:
1384
1384
@@ -1629,6 +1629,86 @@ var _ = Describe("Math", func() {
As we've seen `DescribeTable` takes a function and interprets it as the body of a single `It` function. Sometimes, however, you may want to run a collection of specs for a given table entry. You can do this with `DescribeTableSubtree`:
1635
+
1636
+
```go
1637
+
DescribeTableSubtree("handling requests",
1638
+
func(urlstring, codeint, messagestring) {
1639
+
varresp *http.Response
1640
+
BeforeEach(func() {
1641
+
varerrerror
1642
+
resp, err = http.Get(url)
1643
+
Expect(err).NotTo(HaveOccurred())
1644
+
DeferCleanup(resp.Body.Close)
1645
+
})
1646
+
1647
+
It("should return the expected status code", func() {
now the body function passed to the table is invoked during the Tree Construction Phase to generate a set of specs for each entry. Each body function is invoked within the context of a new container so that setup nodes will only run for the specs defined in the body function. As with `DescribeTable` this is simply synctactic sugar around Ginkgo's existing DSL. The above example is identical to:
1664
+
1665
+
```go
1666
+
1667
+
Describe("handling requests", func() {
1668
+
Describe("default response", func() {
1669
+
varresp *http.Response
1670
+
BeforeEach(func() {
1671
+
varerrerror
1672
+
resp, err = http.Get("example.com/response")
1673
+
Expect(err).NotTo(HaveOccurred())
1674
+
DeferCleanup(resp.Body.Close)
1675
+
})
1676
+
1677
+
It("should return the expected status code", func() {
1678
+
Expect(resp.StatusCode).To(Equal(http.StatusOK))
1679
+
})
1680
+
1681
+
It("should return the expected message", func() {
1682
+
body, err:= ioutil.ReadAll(resp.Body)
1683
+
Expect(err).NotTo(HaveOccurred())
1684
+
Expect(string(body)).To(Equal("hello world"))
1685
+
})
1686
+
})
1687
+
1688
+
Describe("missing response", func() {
1689
+
varresp *http.Response
1690
+
BeforeEach(func() {
1691
+
varerrerror
1692
+
resp, err = http.Get("example.com/missing")
1693
+
Expect(err).NotTo(HaveOccurred())
1694
+
DeferCleanup(resp.Body.Close)
1695
+
})
1696
+
1697
+
It("should return the expected status code", func() {
all the infrastructure around generating table entry descriptions applies here as well - though the description will be the title of the generatd container. Note that you **must** add subject nodes in the body function if you want `DescribeHandleSubtree` to add specs.
1711
+
1632
1712
### Alternatives to Dot-Importing Ginkgo
1633
1713
1634
1714
As shown throughout this documentation, Ginkgo users are encouraged to dot-import the Ginkgo DSL into their test suites to effectively extend the Go language with Ginkgo's expressive building blocks:
It is common, especially in integration suites, to be testing behaviors that occur asynchronously (either within the same process or, in the case of distributed systems, outside the current test process in some combination of external systems). Ginkgo and Gomega provide the building blocks you need to write effective asynchronous specs efficiently.
0 commit comments