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: CHANGELOG.md
+20Lines changed: 20 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,23 @@
1
+
## 1.23.0
2
+
3
+
### Features
4
+
- Custom formatting on a per-type basis can be provided using `format.RegisterCustomFormatter()` -- see the docs [here](https://onsi.github.io/gomega/#adjusting-output)
5
+
6
+
- Substantial improvement have been made to `StopTrying()`:
7
+
- Users can now use `StopTrying().Wrap(err)` to wrap errors and `StopTrying().Attach(description, object)` to attach arbitrary objects to the `StopTrying()` error
8
+
-`StopTrying()` is now always interpreted as a failure. If you are an early adopter of `StopTrying()` you may need to change your code as the prior version would match against the returned value even if `StopTrying()` was returned. Going forward the `StopTrying()` api should remain stable.
9
+
-`StopTrying()` and `StopTrying().Now()` can both be used in matchers - not just polled functions.
10
+
11
+
-`TryAgainAfter(duration)` is used like `StopTrying()` but instructs `Eventually` and `Consistently` that the poll should be tried again after the specified duration. This allows you to dynamically adjust the polling duration.
12
+
13
+
-`ctx` can now be passed-in as the first argument to `Eventually` and `Consistently`.
14
+
15
+
## Maintenance
16
+
17
+
- Bump github.com/onsi/ginkgo/v2 from 2.3.0 to 2.3.1 (#597) [afed901]
18
+
- Bump nokogiri from 1.13.8 to 1.13.9 in /docs (#599) [7c691b3]
19
+
- Bump github.com/google/go-cmp from 0.5.8 to 0.5.9 (#587) [ff22665]
// ExpectWithOffset wraps an actual value allowing assertions to be made on it:
218
-
// ExpectWithOffset(1, "foo").To(Equal("foo"))
226
+
//
227
+
// ExpectWithOffset(1, "foo").To(Equal("foo"))
219
228
//
220
229
// Unlike `Expect` and `Ω`, `ExpectWithOffset` takes an additional integer argument
221
230
// that is used to modify the call-stack offset when computing line numbers. It is
@@ -241,15 +250,15 @@ Eventually works with any Gomega compatible matcher and supports making assertio
241
250
242
251
There are several examples of values that can change over time. These can be passed in to Eventually and will be passed to the matcher repeatedly until a match occurs. For example:
243
252
244
-
c := make(chan bool)
245
-
go DoStuff(c)
246
-
Eventually(c, "50ms").Should(BeClosed())
253
+
c := make(chan bool)
254
+
go DoStuff(c)
255
+
Eventually(c, "50ms").Should(BeClosed())
247
256
248
257
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.
249
258
250
259
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:
251
260
252
-
Eventually(session).Should(gexec.Exit(0))
261
+
Eventually(session).Should(gexec.Exit(0))
253
262
254
263
And the gomega/gbytes package allows you to monitor a streaming *gbytes.Buffer until a given string is seen:
255
264
@@ -270,26 +279,30 @@ Eventually can be passed functions that **return at least one value**. When con
270
279
271
280
For example:
272
281
273
-
Eventually(func() int {
274
-
return client.FetchCount()
275
-
}).Should(BeNumerically(">=", 17))
282
+
Eventually(func() int {
283
+
return client.FetchCount()
284
+
}).Should(BeNumerically(">=", 17))
276
285
277
-
will repeatedly poll client.FetchCount until the BeNumerically matcher is satisfied. (Note that this example could have been written as Eventually(client.FetchCount).Should(BeNumerically(">=", 17)))
286
+
will repeatedly poll client.FetchCount until the BeNumerically matcher is satisfied. (Note that this example could have been written as Eventually(client.FetchCount).Should(BeNumerically(">=", 17)))
278
287
279
288
If multiple values are returned by the function, Eventually will pass the first value to the matcher and require that all others are zero-valued. This allows you to pass Eventually a function that returns a value and an error - a common pattern in Go.
280
289
281
290
For example, consider a method that returns a value and an error:
282
-
func FetchFromDB() (string, error)
291
+
292
+
func FetchFromDB() (string, error)
283
293
284
294
Then
285
-
Eventually(FetchFromDB).Should(Equal("got it"))
295
+
296
+
Eventually(FetchFromDB).Should(Equal("got it"))
286
297
287
298
will pass only if and when the returned error is nil *and* the returned string satisfies the matcher.
288
299
289
300
Eventually can also accept functions that take arguments, however you must provide those arguments using .WithArguments(). For example, consider a function that takes a user-id and makes a network request to fetch a full name:
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. A common practice here is to use a context. Here's an example that combines Ginkgo's spec timeout support with Eventually:
@@ -326,13 +339,13 @@ will pass only if all the assertions in the polled function pass and the return
326
339
Eventually also supports a special case polling function that takes a single Gomega argument and returns no values. Eventually assumes such a function is making assertions and is designed to work with the Succeed matcher to validate that all assertions have passed.
327
340
For example:
328
341
329
-
Eventually(func(g Gomega) {
330
-
model, err := client.Find(1138)
331
-
g.Expect(err).NotTo(HaveOccurred())
332
-
g.Expect(model.Reticulate()).To(Succeed())
333
-
g.Expect(model.IsReticulated()).To(BeTrue())
334
-
g.Expect(model.Save()).To(Succeed())
335
-
}).Should(Succeed())
342
+
Eventually(func(g Gomega) {
343
+
model, err := client.Find(1138)
344
+
g.Expect(err).NotTo(HaveOccurred())
345
+
g.Expect(model.Reticulate()).To(Succeed())
346
+
g.Expect(model.IsReticulated()).To(BeTrue())
347
+
g.Expect(model.Save()).To(Succeed())
348
+
}).Should(Succeed())
336
349
337
350
will rerun the function until all assertions pass.
338
351
@@ -353,7 +366,7 @@ Finally, in addition to passing timeouts and a context to Eventually you can be
@@ -385,7 +398,7 @@ Consistently accepts the same three categories of actual as Eventually, check th
385
398
386
399
Consistently is useful in cases where you want to assert that something *does not happen* for a period of time. For example, you may want to assert that a goroutine does *not* send data down a channel. In this case you could write:
0 commit comments