From 02e8706354ce9b25c178f841102f76dca6479326 Mon Sep 17 00:00:00 2001 From: thediveo Date: Thu, 18 Apr 2024 14:17:21 +0200 Subject: [PATCH] docs: Receive(POINTER, MATCHER) Signed-off-by: thediveo --- docs/index.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 05a747546..063ab7313 100644 --- a/docs/index.md +++ b/docs/index.md @@ -877,7 +877,7 @@ Finally, as a corollary: it is an error to check whether or not a send-only chan #### Receive() ```go -Ω(ACTUAL).Should(Receive()) +Ω(ACTUAL).Should(Receive(, )) ``` succeeds if there is a message to be received on actual. Actual must be a channel (and cannot be a send-only channel) -- anything else is an error. @@ -930,6 +930,14 @@ Eventually(bagelChan).Should(Receive(&receivedBagel)) Of course, this could have been written as `receivedBagel := <-bagelChan` - however using `Receive` makes it easy to avoid hanging the test suite should nothing ever come down the channel. The pointer can point to any variable whose type is assignable from the channel element type, or if the channel type is an interface and the underlying type is assignable to the pointer. +Sometimes, you might need to *grab* the object that *matches* certain criteria: + +```go +var receivedBagel Bagel +Eventually(bagelChan).Should(Receive(&receivedBagel, HaveField("Kind", "sesame"))) +Ω(receivedBagel.Contents()).Should(ContainElement("cream cheese")) +``` + Finally, `Receive` *never* blocks. `Eventually(c).Should(Receive())` repeatedly polls `c` in a non-blocking fashion. That means that you cannot use this pattern to verify that a *non-blocking send* has occurred on the channel - [more details at this GitHub issue](https://github.com/onsi/gomega/issues/82). #### BeSent(value interface{})