Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

documentation updates for BeKeyOf and well-known non-leaky goroutines #592

Merged
merged 1 commit into from Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 19 additions & 2 deletions docs/index.md
Expand Up @@ -970,10 +970,25 @@ succeeds if `ACTUAL` equals one of the elements passed into the matcher. When a
#### BeKeyOf(m interface{})

```go
Ω(ACTUAL).Should(BeKeyOf(ELEMENT))
Ω(ACTUAL).Should(BeKeyOf(MAP))
```

succeeds if `ACTUAL` equals one of the keys of the map passed into the matcher. `BeKeyOf` always uses the `Equal()` matcher under the hood to assert equality with a map key.
succeeds if `ACTUAL` equals one of the keys of `MAP`. It is an error for `MAP` to be of any type other than a map. `BeKeyOf` always uses the `Equal()` matcher under the hood to assert equality of `ACTUAL` with a map key.

`BeKeyOf` can be used in situations where it is not possible to rewrite an assertion to use the more idiomatic `HaveKey`: one use is in combination with `ContainElement` doubling as a filter. For instance, the following example asserts that all expected specific sprockets are present in a larger list of sprockets:

```go
var names = map[string]struct {
detail string
}{
"edgy_emil": {detail: "sprocket_project_A"},
"furious_freddy": {detail: "sprocket_project_B"},
}

var canaries []Sprocket
Expect(projects).To(ContainElement(HaveField("Name", BeKeyOf(names)), &canaries))
Expect(canaries).To(HaveLen(len(names)))
```

#### ConsistOf(element ...interface{})

Expand Down Expand Up @@ -3264,6 +3279,8 @@ names of the topmost functions on their stacks (backtraces):
inner functions),
- the anonymous inner functions of
`github.com/onsi/ginkgo/v2/internal/interrupt_handler.(*InterruptHandler).registerForInterrupts`,
- the creators `github.com/onsi/ginkgo/v2/internal.(*genericOutputInterceptor).ResumeIntercepting` and `github.com/onsi/ginkgo/v2/internal.(*genericOutputInterceptor).ResumeIntercepting...`,
- the creator `github.com/onsi/ginkgo/v2/internal.RegisterForProgressSignal`,
- and finally
`github.com/onsi/ginkgo/internal/specrunner.(*SpecRunner).registerForInterrupts`
(for v1 support).
Expand Down
2 changes: 1 addition & 1 deletion matchers.go
Expand Up @@ -318,7 +318,7 @@ func BeElementOf(elements ...interface{}) types.GomegaMatcher {
}

// BeKeyOf succeeds if actual is contained in the keys of the passed in map.
// BeKeyOf() always uses Equal() to perform the match.
// BeKeyOf() always uses Equal() to perform the match between actual and the map keys.
//
// Expect("foo").Should(BeKeyOf(map[string]bool{"foo": true, "bar": false}))
func BeKeyOf(element interface{}) types.GomegaMatcher {
Expand Down