Skip to content

Commit bf817a4

Browse files
committed
v1.23.0
1 parent 7b8b801 commit bf817a4

File tree

2 files changed

+68
-35
lines changed

2 files changed

+68
-35
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff 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]
20+
121
## 1.22.1
222

323
## Fixes

gomega_dsl.go

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"github.com/onsi/gomega/types"
2323
)
2424

25-
const GOMEGA_VERSION = "1.22.1"
25+
const GOMEGA_VERSION = "1.23.0"
2626

2727
const nilGomegaPanic = `You are trying to make an assertion, but haven't registered Gomega's fail handler.
2828
If you're using Ginkgo then you probably forgot to put your assertion in an It().
@@ -86,12 +86,12 @@ func internalGomega(g Gomega) *internal.Gomega {
8686
// NewWithT takes a *testing.T and returns a `gomega.WithT` allowing you to use `Expect`, `Eventually`, and `Consistently` along with
8787
// Gomega's rich ecosystem of matchers in standard `testing` test suits.
8888
//
89-
// func TestFarmHasCow(t *testing.T) {
90-
// g := gomega.NewWithT(t)
89+
// func TestFarmHasCow(t *testing.T) {
90+
// g := gomega.NewWithT(t)
9191
//
92-
// f := farm.New([]string{"Cow", "Horse"})
93-
// g.Expect(f.HasCow()).To(BeTrue(), "Farm should have cow")
94-
// }
92+
// f := farm.New([]string{"Cow", "Horse"})
93+
// g.Expect(f.HasCow()).To(BeTrue(), "Farm should have cow")
94+
// }
9595
func NewWithT(t types.GomegaTestingT) *WithT {
9696
return internal.NewGomega(internalGomega(Default).DurationBundle).ConfigureWithT(t)
9797
}
@@ -171,7 +171,8 @@ func ensureDefaultGomegaIsConfigured() {
171171
}
172172

173173
// Ω wraps an actual value allowing assertions to be made on it:
174-
// Ω("foo").Should(Equal("foo"))
174+
//
175+
// Ω("foo").Should(Equal("foo"))
175176
//
176177
// If Ω is passed more than one argument it will pass the *first* argument to the matcher.
177178
// All subsequent arguments will be required to be nil/zero.
@@ -180,10 +181,13 @@ func ensureDefaultGomegaIsConfigured() {
180181
// a value and an error - a common patter in Go.
181182
//
182183
// For example, given a function with signature:
183-
// func MyAmazingThing() (int, error)
184+
//
185+
// func MyAmazingThing() (int, error)
184186
//
185187
// Then:
186-
// Ω(MyAmazingThing()).Should(Equal(3))
188+
//
189+
// Ω(MyAmazingThing()).Should(Equal(3))
190+
//
187191
// Will succeed only if `MyAmazingThing()` returns `(3, nil)`
188192
//
189193
// Ω and Expect are identical
@@ -193,7 +197,8 @@ func Ω(actual interface{}, extra ...interface{}) Assertion {
193197
}
194198

195199
// Expect wraps an actual value allowing assertions to be made on it:
196-
// Expect("foo").To(Equal("foo"))
200+
//
201+
// Expect("foo").To(Equal("foo"))
197202
//
198203
// If Expect is passed more than one argument it will pass the *first* argument to the matcher.
199204
// All subsequent arguments will be required to be nil/zero.
@@ -202,10 +207,13 @@ func Ω(actual interface{}, extra ...interface{}) Assertion {
202207
// a value and an error - a common patter in Go.
203208
//
204209
// For example, given a function with signature:
205-
// func MyAmazingThing() (int, error)
210+
//
211+
// func MyAmazingThing() (int, error)
206212
//
207213
// Then:
208-
// Expect(MyAmazingThing()).Should(Equal(3))
214+
//
215+
// Expect(MyAmazingThing()).Should(Equal(3))
216+
//
209217
// Will succeed only if `MyAmazingThing()` returns `(3, nil)`
210218
//
211219
// Expect and Ω are identical
@@ -215,7 +223,8 @@ func Expect(actual interface{}, extra ...interface{}) Assertion {
215223
}
216224

217225
// 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"))
219228
//
220229
// Unlike `Expect` and `Ω`, `ExpectWithOffset` takes an additional integer argument
221230
// 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
241250
242251
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:
243252
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())
247256
248257
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.
249258
250259
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:
251260
252-
Eventually(session).Should(gexec.Exit(0))
261+
Eventually(session).Should(gexec.Exit(0))
253262
254263
And the gomega/gbytes package allows you to monitor a streaming *gbytes.Buffer until a given string is seen:
255264
@@ -270,26 +279,30 @@ Eventually can be passed functions that **return at least one value**. When con
270279
271280
For example:
272281
273-
Eventually(func() int {
274-
return client.FetchCount()
275-
}).Should(BeNumerically(">=", 17))
282+
Eventually(func() int {
283+
return client.FetchCount()
284+
}).Should(BeNumerically(">=", 17))
276285
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)))
278287
279288
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.
280289
281290
For example, consider a method that returns a value and an error:
282-
func FetchFromDB() (string, error)
291+
292+
func FetchFromDB() (string, error)
283293
284294
Then
285-
Eventually(FetchFromDB).Should(Equal("got it"))
295+
296+
Eventually(FetchFromDB).Should(Equal("got it"))
286297
287298
will pass only if and when the returned error is nil *and* the returned string satisfies the matcher.
288299
289300
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:
301+
290302
func FetchFullName(userId int) (string, error)
291303
292304
You can poll this function like so:
305+
293306
Eventually(FetchFullName).WithArguments(1138).Should(Equal("Wookie"))
294307
295308
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
326339
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.
327340
For example:
328341
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())
336349
337350
will rerun the function until all assertions pass.
338351
@@ -353,7 +366,7 @@ Finally, in addition to passing timeouts and a context to Eventually you can be
353366
354367
is equivalent to
355368
356-
Eventually(...).WithTimeout(time.Second).WithPolling(2*time.Second).WithContext(ctx).Should(...)
369+
Eventually(...).WithTimeout(time.Second).WithPolling(2*time.Second).WithContext(ctx).Should(...)
357370
*/
358371
func Eventually(args ...interface{}) AsyncAssertion {
359372
ensureDefaultGomegaIsConfigured()
@@ -385,7 +398,7 @@ Consistently accepts the same three categories of actual as Eventually, check th
385398
386399
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:
387400
388-
Consistently(channel, "200ms").ShouldNot(Receive())
401+
Consistently(channel, "200ms").ShouldNot(Receive())
389402
390403
This will block for 200 milliseconds and repeatedly check the channel and ensure nothing has been received.
391404
*/
@@ -481,8 +494,8 @@ func SetDefaultConsistentlyPollingInterval(t time.Duration) {
481494
//
482495
// Example:
483496
//
484-
// Eventually(myChannel).Should(Receive(), "Something should have come down the pipe.")
485-
// Consistently(myChannel).ShouldNot(Receive(), func() string { return "Nothing should have come down the pipe." })
497+
// Eventually(myChannel).Should(Receive(), "Something should have come down the pipe.")
498+
// Consistently(myChannel).ShouldNot(Receive(), func() string { return "Nothing should have come down the pipe." })
486499
type AsyncAssertion = types.AsyncAssertion
487500

488501
// GomegaAsyncAssertion is deprecated in favor of AsyncAssertion, which does not stutter.
@@ -504,7 +517,7 @@ type GomegaAsyncAssertion = types.AsyncAssertion
504517
//
505518
// Example:
506519
//
507-
// Ω(farm.HasCow()).Should(BeTrue(), "Farm %v should have a cow", farm)
520+
// Ω(farm.HasCow()).Should(BeTrue(), "Farm %v should have a cow", farm)
508521
type Assertion = types.Assertion
509522

510523
// GomegaAssertion is deprecated in favor of Assertion, which does not stutter.

0 commit comments

Comments
 (0)