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
will poll the channel repeatedly until it is closed. In this example `Eventually` will block until either the specified timeout of 50ms has elapsed or the channel is closed, whichever comes first.
298
298
299
-
Several Gomega libraries allow you to use Eventually in this way. For example, the `gomega/gexec` package allows you to block until a `*gexec.Session` exits successfuly via:
299
+
Several Gomega libraries allow you to use Eventually in this way. For example, the `gomega/gexec` package allows you to block until a `*gexec.Session` exits successfully via:
300
300
301
301
```go
302
302
Eventually(session).Should(gexec.Exit(0))
@@ -368,7 +368,7 @@ You can poll this function like so:
`WithArguments()` supports multiple arugments as well as variadic arguments.
371
+
`WithArguments()` supports multiple arguments as well as variadic arguments.
372
372
373
373
It is important to note that the function passed into Eventually is invoked **synchronously** when polled. `Eventually` does not (in fact, it cannot) kill the function if it takes longer to return than `Eventually`'s configured timeout. This is where using a `context.Context` can be helpful. Here is an example that leverages Gingko's support for interruptible nodes and spec timeouts:
374
374
@@ -407,13 +407,13 @@ It("adds a few books and checks the count", func(ctx SpecContext) {
407
407
}, SpecTimeout(time.Second * 5))
408
408
```
409
409
410
-
In addition, Gingko's `SpecContext` allows Gomega to tell Ginkgo about the status of a currently running `Eventually` whenever a Progress Report is generated. So, if a spec times out while running an `Eventually` Ginkgo will not only show you which `Eventually` was running when the timeout occured, but will also include the failure the `Eventually` was hitting when the timeout occurred.
410
+
In addition, Gingko's `SpecContext` allows Gomega to tell Ginkgo about the status of a currently running `Eventually` whenever a Progress Report is generated. So, if a spec times out while running an `Eventually` Ginkgo will not only show you which `Eventually` was running when the timeout occurred, but will also include the failure the `Eventually` was hitting when the timeout occurred.
411
411
412
412
#### Category 3: Making assertions _in_ the function passed into `Eventually`
413
413
414
414
When testing complex systems it can be valuable to assert that a *set* of assertions passes `Eventually`. `Eventually` supports this by accepting functions that take **a single `Gomega` argument** and **return zero or more values**.
415
415
416
-
Here's an example that makes some asssertions and returns a value and error:
416
+
Here's an example that makes some assertions and returns a value and error:
417
417
418
418
```go
419
419
Eventually(func(gGomega) (Widget, error) {
@@ -442,7 +442,7 @@ Eventually(func(g Gomega) {
442
442
443
443
will rerun the function until all assertions pass.
444
444
445
-
You can also pass additional arugments to functions that take a Gomega. The only rule is that the Gomega argument must be first. If you also want to pass the context attached to `Eventually` you must ensure that is the second argument. For example:
445
+
You can also pass additional arguments to functions that take a Gomega. The only rule is that the Gomega argument must be first. If you also want to pass the context attached to `Eventually` you must ensure that is the second argument. For example:
@@ -800,7 +800,7 @@ succeeds if `ACTUAL` is a non-nil `error` that matches `EXPECTED`. `EXPECTED` mu
800
800
801
801
- A string, in which case `ACTUAL.Error()` will be compared against `EXPECTED`.
802
802
- A matcher, in which case `ACTUAL.Error()` is tested against the matcher.
803
-
- An error, in which case anyo of the following is satisfied:
803
+
- An error, in which case any of the following is satisfied:
804
804
-`errors.Is(ACTUAL, EXPECTED)` returns `true`
805
805
-`ACTUAL` or any of the errors it wraps (directly or indirectly) equals `EXPECTED` in terms of `reflect.DeepEqual()`.
806
806
@@ -1641,7 +1641,7 @@ type GomegaMatcher interface {
1641
1641
1642
1642
For the simplest cases, new matchers can be [created by composition](#composing-matchers). Please also take a look at the [Building Custom Matchers](https://onsi.github.io/ginkgo/#building-custom-matchers) section of the Ginkgo and Gomega patterns chapter in the Ginkgo docs for additional examples.
1643
1643
1644
-
In addition to composition, however, it is fairly straightforward to build domain-specific custom matchers. You can create new types that satisfy the `GomegaMatcher`interace*or* you can use the `gcustom` package to build matchers out of simple functions.
1644
+
In addition to composition, however, it is fairly straightforward to build domain-specific custom matchers. You can create new types that satisfy the `GomegaMatcher`interface*or* you can use the `gcustom` package to build matchers out of simple functions.
1645
1645
1646
1646
Let's work through an example and illustrate both approaches.
1647
1647
@@ -1711,7 +1711,7 @@ Let's break this down:
1711
1711
- It is guaranteed that `FailureMessage` and `NegatedFailureMessage` will only be called *after*`Match`, so you can save off any state you need to compute the messages in `Match`.
1712
1712
- Finally, it is common for matchers to make extensive use of the `reflect` library to interpret the generic inputs they receive. In this case, the `representJSONMatcher` goes through some `reflect` gymnastics to create a pointer to a new object with the same type as the `expected` object, read and decode JSON from `actual` into that pointer, and then deference the pointer and compare the result to the `expected` object.
1713
1713
1714
-
### gcustom: A convenient mechanism for buildling custom matchers
1714
+
### gcustom: A convenient mechanism for building custom matchers
1715
1715
1716
1716
[`gcustom`](https://github.com/onsi/gomega/tree/master/gcustom) is a package that makes building custom matchers easy. Rather than define new types, you can simply provide `gcustom.MakeMatcher` with a function. The [godocs](https://pkg.go.dev/github.com/onsi/gomega/gcustom) for `gcustom` have all the details but here's how `RepresentJSONifiedObject` could be implemented with `gcustom`:
1717
1717
@@ -1903,7 +1903,7 @@ type inner interface {
1903
1903
}
1904
1904
```
1905
1905
1906
-
The `Inner()` method must return the actual `gomega.Default`. For Gomega to function properly your wrapper methods must call the same method on the real `gomega.Default` This allows you to wrap every Goemga method call (e.g. `Expect()`) with your own code across your test suite. You can use this to add random delays, additional logging, or just for tracking the number of `Expect()` calls made.
1906
+
The `Inner()` method must return the actual `gomega.Default`. For Gomega to function properly your wrapper methods must call the same method on the real `gomega.Default` This allows you to wrap every Gomega method call (e.g. `Expect()`) with your own code across your test suite. You can use this to add random delays, additional logging, or just for tracking the number of `Expect()` calls made.
1907
1907
1908
1908
```go
1909
1909
funcinit() {
@@ -2467,7 +2467,7 @@ AfterSuite(func() {
2467
2467
})
2468
2468
```
2469
2469
2470
-
> By default, `gexec.Build` uses the GOPATH specified in your environment. You can also use `gexec.BuildIn(gopath string, packagePath string)` to specify a custom GOPATH for the build command. This is useful to, for example, build a binary against its vendored Godeps.
2470
+
> By default, `gexec.Build` uses the GOPATH specified in your environment. You can also use `gexec.BuildIn(gopath string, packagePath string)` to specify a custom GOPATH for the build command. This is useful to, for example, build a binary against its vendored Go dependencies.
2471
2471
2472
2472
> You can specify arbitrary environment variables for the build command – such as GOOS and GOARCH for building on other platforms – using `gexec.BuildWithEnvironment(packagePath string, envs []string)`.
`gmeasure` provides support for measuring and recording benchmarks of your code and tests. It can be used as a simple standalone benchmarking framework, or as part of your code's test suite. `gmeasure` integrates cleanly with Ginkgo V2 to enable rich benchmarking of code alognside your tests.
2822
+
`gmeasure` provides support for measuring and recording benchmarks of your code and tests. It can be used as a simple standalone benchmarking framework, or as part of your code's test suite. `gmeasure` integrates cleanly with Ginkgo V2 to enable rich benchmarking of code alongside your tests.
2823
2823
2824
2824
### A Mental Model for `gmeasure`
2825
2825
@@ -3158,7 +3158,7 @@ This simple connection point ensures that the output is appropriately formatted
3158
3158
3159
3159
### Caching Experiments
3160
3160
3161
-
`gmeasure` supports caching experiments to local disk. Experiments can be stored and retreived from the cache by name and version number. Caching allows you to skip rerunning expensive experiments and versioned caching allows you to bust the cache by incrementing the version number. Under the hood, the cache is simply a set of files in a directory. Each file contains a JSON encoded header with the experiment's name and version number followed by the JSON-encoded experiment. The various cache methods are documented over at [pkg.go.dev](https://pkg.go.dev/github.com/onsi/gomega/gmeasure#ExperimentCache).
3161
+
`gmeasure` supports caching experiments to local disk. Experiments can be stored and retrieved from the cache by name and version number. Caching allows you to skip rerunning expensive experiments and versioned caching allows you to bust the cache by incrementing the version number. Under the hood, the cache is simply a set of files in a directory. Each file contains a JSON encoded header with the experiment's name and version number followed by the JSON-encoded experiment. The various cache methods are documented over at [pkg.go.dev](https://pkg.go.dev/github.com/onsi/gomega/gmeasure#ExperimentCache).
3162
3162
3163
3163
Using an `ExperimentCache` with Ginkgo takes a little bit of wiring. Here's an example:
3164
3164
@@ -3358,7 +3358,7 @@ results in one or more goroutines. The ordering of the goroutines does not
3358
3358
matter.
3359
3359
3360
3360
`HaveLeaked` always takes the built-in list of well-known good goroutines into
3361
-
consideration and this list can neither be overriden nor disabled. Additional
3361
+
consideration and this list can neither be overridden nor disabled. Additional
3362
3362
known non-leaky goroutines `NONLEAKY1`, ... can be passed to `HaveLeaks` either
3363
3363
in form of `GomegaMatcher`s or in shorthand notation:
3364
3364
@@ -3435,11 +3435,11 @@ goroutine(s) as non-leaky. `IgnoringGoroutines` compares goroutines by their
MakeMatcher builds a Gomega-compatible matcher from a function (the matchFunc).
43
43
44
-
matchFunc must return (bool, error) and take a single argument. If you want to perform type-checking yourself pass in a matchFunc of type `func(actual any) (bool, error)`. If you want to only operate on a specific type, pass in `func(actual DesiredType) (bool, error)`; MakeMatcher will take care of checking typues for you and notifying the user if they use the matcher with an invalid type.
44
+
matchFunc must return (bool, error) and take a single argument. If you want to perform type-checking yourself pass in a matchFunc of type `func(actual any) (bool, error)`. If you want to only operate on a specific type, pass in `func(actual DesiredType) (bool, error)`; MakeMatcher will take care of checking types for you and notifying the user if they use the matcher with an invalid type.
45
45
46
46
MakeMatcher(matchFunc) builds a matcher with generic failure messages that look like:
47
47
@@ -68,7 +68,7 @@ where templateString is a string that is compiled by WithTemplate into a matcher
68
68
69
69
template, err = gcustom.ParseTemplate(templateString) //use gcustom's ParseTemplate to get some additional functions mixed in
When a simple message string is provided the positive failure message will look like:
74
74
@@ -161,25 +161,25 @@ Templates are provided the following variables and functions:
161
161
{{.To}} - is set to "to" if this is a positive failure message and "not to" if this is a negated failure message
162
162
{{.Actual}} - the actual passed in to the matcher
163
163
{{.FormattedActual}} - a string representing the formatted actual. This can be multiple lines and is always generated with an indentation of 1
164
-
{{format <object> <optional-indentaiton}} - a function that allows you to use Gomega's default formatting from within the template. The passed-in <object> is formatted and <optional-indentation> can be set to an integer to control indentation.
164
+
{{format <object> <optional-indentation}} - a function that allows you to use Gomega's default formatting from within the template. The passed-in <object> is formatted and <optional-indentation> can be set to an integer to control indentation.
165
165
166
166
In addition, you can provide custom data to the template by calling WithTemplate(templateString, data) (where data can be anything). This is provided to the template as {{.Data}}.
167
167
168
168
Here's a simple example of all these pieces working together:
0 commit comments