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
+12-13Lines changed: 12 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -694,8 +694,7 @@ Ginkgo will emit a warning if it detects this.
694
694
695
695
#### Avoid Spec Pollution: Don't Initialize Variables in Container Nodes
696
696
697
-
We've covered this already but it bears repeating: **"Declare in container nodes, initialize in setup nodes"**. Since container nodes are only invoked once during the tree construction phase you should declare closure variables in container nodes but always initialize them in setup nodes. The following is
698
-
invalid can potentially infuriating to debug:
697
+
We've covered this already but it bears repeating: **"Declare in container nodes, initialize in setup nodes"**. Since container nodes are only invoked once during the tree construction phase you should declare closure variables in container nodes but always initialize them in setup nodes. The following is invalid and can potentially be infuriating to debug:
699
698
700
699
```go
701
700
/* === INVALID === */
@@ -1010,7 +1009,7 @@ Describe("Reporting book weight", func() {
1010
1009
1011
1010
That's better. The specs will now clean up after themselves correctly.
1012
1011
1013
-
One quick note before we move on, you may have caught that `book.HumanReadableWeight()` returns _two_ values - a `weight` string and an `error`. This is common pattern and Gomega has first class support for it. The assertion:
1012
+
One quick note before we move on, you may have caught that `book.HumanReadableWeight()` returns _two_ values - a `weight` string and an `error`. This is a common pattern and Gomega has first class support for it. The assertion:
@@ -1020,7 +1019,7 @@ is actually making two assertions under the hood. That the first value returned
1020
1019
1021
1020
#### Cleaning up our Cleanup code: DeferCleanup
1022
1021
1023
-
Setup and cleanup patterns like the one above are common in Ginkgo suites. While powerful, however, `AfterEach` nodes have a tendency to separate cleanup code from setup code. We had to create an `originalWeightUnits` closure variable to keep track of the original environment variable in the `BeforeEach` and pass it to the `AfterEach` - this feels noisy and potential error-prone.
1022
+
Setup and cleanup patterns like the one above are common in Ginkgo suites. While powerful, however, `AfterEach` nodes tend to separate cleanup code from setup code. We had to create an `originalWeightUnits` closure variable to keep track of the original environment variable in the `BeforeEach` and pass it to the `AfterEach` - this feels noisy and potential error-prone.
1024
1023
1025
1024
Ginkgo provides the `DeferCleanup()` function to help solve for this usecase and bring spec setup closer to spec cleanup. Here's what our example looks like with `DeferCleanup()`:
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:
1691
+
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 syntactic sugar around Ginkgo's existing DSL. The above example is identical to:
1693
1692
1694
1693
```go
1695
1694
@@ -1933,7 +1932,7 @@ Finally, if your specs need to _generate_ random numbers you can seed your pseud
1933
1932
1934
1933
### Spec Parallelization
1935
1934
1936
-
As spec suites grow in size and complexity they have a tendency to get slower. Thankfully the vast majority of modern computers ship with multiple CPU cores. Ginkgo helps you use those cores to speed up your suites by running specs in parallel. This is _especially_ useful when running large, complex, and slow integration suites where the only means to speed things up is to embrace parallelism.
1935
+
As spec suites grow in size and complexity they tend to get slower. Thankfully the vast majority of modern computers ship with multiple CPU cores. Ginkgo helps you use those cores to speed up your suites by running specs in parallel. This is _especially_ useful when running large, complex, and slow integration suites where the only means to speed things up is to embrace parallelism.
1937
1936
1938
1937
To run a Ginkgo suite in parallel you simply pass the `-p` flag to `ginkgo`:
1939
1938
@@ -2612,7 +2611,7 @@ To build on our example above, here are some label filter queries and their beha
2612
2611
|`ginkgo --label-filter="integration"`| Match any specs with the `integration` label |
2613
2612
|`ginkgo --label-filter="!slow"`| Avoid any specs labelled `slow`|
2614
2613
|`ginkgo --label-filter="network && !slow"`| Run specs labelled `network` that aren't `slow`|
2615
-
| `ginkgo --label-filter=/library/` | Run specs with labels matching the regular expression `library` - this will match the three library-related specs in our example.
2614
+
|`ginkgo --label-filter=/library/`| Run specs with labels matching the regular expression `library` - this will match the three library-related specs in our example.|
2616
2615
2617
2616
##### Label Sets
2618
2617
@@ -3453,7 +3452,7 @@ The two verbose settings are most helpful when debugging spec suites. They make
3453
3452
3454
3453
Very-verbose mode contains additional information over verbose mode. In particular, `-vv` timelines indicate when individual nodes start and end and also include the full failure descriptions for _every_ failure encountered by the spec. Verbose mode does not include the node start/end events (though this can be turned on with `--show-node-events`) and does not include detailed failure information for anything other than the first (primary) failure. (Additional/subsequent failures typically occur in clean-up nodes and are not as relevant as the primary failure that occurs in a subject or setup node).
3455
3454
3456
-
When you [filter specs](#filtering-specs) using Ginkgo's various filtering mechanism Ginkgo usually emits a single cyan `S` for each skipped spec. If you run with the very-verbose setting, however, Ginkgo will emit the description and location information of every skipped spec. This can be useful if you need to debug your filter queries and can be paired with `--dry-run`.
3455
+
When you [filter specs](#filtering-specs) using Ginkgo's various filtering mechanisms Ginkgo usually emits a single cyan `S` for each skipped spec. If you run with the very-verbose setting, however, Ginkgo will emit the description and location information of every skipped spec. This can be useful if you need to debug your filter queries and can be paired with `--dry-run`.
The closure passed to `ReportBeforeSuite` is called exactly once at the beginning of the suite before any `BeforeSuite` nodes or specs run have run. The closure passed to `ReportAfterSuite` is called exactly once at the end of the suite after any `AfterSuite` nodes have run.
3649
3648
3650
-
Finally, and most importantly, when running in parallel both `ReportBeforeSuite` and `ReportAfterSuite`**only run on process #1**. Gingko guarantess that no other processes will start running their specs until after `ReportBeforeSuite` on process #1 has completed. Similarly, Ginkgo will only run `ReportAfterSuite` on process #1 after all other processes have finished and exited. Ginkgo provides a single `Report` that aggregates the `SpecReports` from all processes. This allows you to perform any custom suite reporting in one place after all specs have run and not have to worry about aggregating information across multiple parallel processes.
3649
+
Finally, and most importantly, when running in parallel both `ReportBeforeSuite` and `ReportAfterSuite`**only run on process #1**. Gingko guarantees that no other processes will start running their specs until after `ReportBeforeSuite` on process #1 has completed. Similarly, Ginkgo will only run `ReportAfterSuite` on process #1 after all other processes have finished and exited. Ginkgo provides a single `Report` that aggregates the `SpecReports` from all processes. This allows you to perform any custom suite reporting in one place after all specs have run and not have to worry about aggregating information across multiple parallel processes.
3651
3650
3652
3651
Given all this, we can rewrite our invalid `ReportAfterEach` example from above into a valid `ReportAfterSuite` example:
3653
3652
@@ -4932,7 +4931,7 @@ here we've assumed the `client` can take and restore a snapshot of the database.
4932
4931
4933
4932
With this approach each parallel process has its own dedicated database so there is no chance for cross-spec pollution when running in parallel. Within each parallel process the dedicated database is cleared out between specs so there's no chance for spec pollution from one spec to the next.
4934
4933
4935
-
This all works if you have the ability to spin up a local copy of the database. But there are times when you must rely on an external stateful singleton resource and need to test against it. We'll explore patterns for testing those next.
4934
+
This all works if you can spin up a local copy of the database. But there are times when you must rely on an external stateful singleton resource and need to test against it. We'll explore patterns for testing those next.
4936
4935
4937
4936
#### Patterns for Testing against Singletons
4938
4937
There are times when your spec suite must run against a stateful shared singleton system. Perhaps it is simply too expensive to spin up multiple systems (e.g. each "system" is actually a memory-hungry cluster of distributed systems; or, perhaps, you are testing against a real-life instance of a service and can't spin up another instance).
@@ -5372,7 +5371,7 @@ Currently none of these decorators can be applied to container nodes.
5372
5371
5373
5372
## Ginkgo CLI Overview
5374
5373
5375
-
This chapter provides a quick overview and tour of the Ginkgo CLI. For comprehensive details about all of the Ginkgo CLI's flags, run `ginkgo help`. To get information about Ginkgo's implicit `run`command (i.e. what you get when you just run `ginkgo`) run `ginkgo help run`.
5374
+
This chapter provides a quick overview and tour of the Ginkgo CLI. For comprehensive details of Ginkgo CLI's flags, run `ginkgo help`. To get information about Ginkgo's implicit `run`command (i.e. what you get when you just run `ginkgo`) run `ginkgo help run`.
5376
5375
5377
5376
The Ginkgo CLI is the recommended and supported tool forrunning Ginkgo suites. While you _can_ run Ginkgo suites with `go test` you must use the CLI to run suitesin parallel and to aggregate profiles. There are also a (small) number of `go test` flags that Ginkgo does not support - an error will be emitted if you attempt to use these (for example, `go test -count=N`, use `ginkgo -repeat=N` instead).
5378
5377
@@ -5497,7 +5496,7 @@ This generates an outline in a comma-separated-values (CSV) format. Column heade
5497
5496
5498
5497
Name,Text,Start,End,Spec,Focused,Pending,Labels
5499
5498
Describe,Book,124,973,false,false,false,""
5500
-
BeforeEach,,217,507,false,false,false,""
5499
+
BeforeEach,217,507,false,false,false,""
5501
5500
Describe,Categorizing book length,513,970,false,false,false,""
5502
5501
Context,With more than 300 pages,567,753,false,false,false,""
5503
5502
It,should be a novel,624,742,true,false,false,""
@@ -5629,6 +5628,6 @@ Set the `GINKGO_PRESERVE_CACHE` environment variable to `true` in order to
5629
5628
skip the `os.Getwd()` call. This may affect the reporter output.
5630
5629
5631
5630
### The ginkgolinter
5632
-
The [ginkgolinter](https://github.com/nunnatsa/ginkgolinter) enforces several patterns of using ginkgo and gomega. It can run as an independent executable or as part of the [golangci-lint](https://golangci-lint.run/) linter. See the ginkgolinter [READMY](https://github.com/nunnatsa/ginkgolinter#readme) for more details.
5631
+
The [ginkgolinter](https://github.com/nunnatsa/ginkgolinter) enforces several patterns of using ginkgo and gomega. It can run as an independent executable or as part of the [golangci-lint](https://golangci-lint.run/) linter. See the ginkgolinter [README](https://github.com/nunnatsa/ginkgolinter#readme) for more details.
0 commit comments