Skip to content

Commit b0b6dbd

Browse files
committed
Bump to v1.27.7
1 parent 5eb11c4 commit b0b6dbd

11 files changed

+146
-55
lines changed

docs/Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ source "https://rubygems.org"
1212
gem "minima", "~> 2.5"
1313
# If you want to use GitHub Pages, remove the "gem "jekyll"" above and
1414
# uncomment the line below. To upgrade, run `bundle update github-pages`.
15-
gem "github-pages", "~> 227", group: :jekyll_plugins
15+
gem "github-pages", "~> 228", group: :jekyll_plugins
1616
# If you have any plugins, put them here!
1717
group :jekyll_plugins do
1818
gem "jekyll-feed", "~> 0.12"

docs/Gemfile.lock

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
activesupport (6.0.6)
4+
activesupport (6.0.6.1)
55
concurrent-ruby (~> 1.0, >= 1.0.2)
66
i18n (>= 0.7, < 2)
77
minitest (~> 5.1)
@@ -14,30 +14,30 @@ GEM
1414
execjs
1515
coffee-script-source (1.11.1)
1616
colorator (1.1.0)
17-
commonmarker (0.23.6)
18-
concurrent-ruby (1.1.10)
17+
commonmarker (0.23.9)
18+
concurrent-ruby (1.2.0)
1919
dnsruby (1.61.9)
2020
simpleidn (~> 0.1)
2121
em-websocket (0.5.3)
2222
eventmachine (>= 0.12.9)
2323
http_parser.rb (~> 0)
24-
ethon (0.15.0)
24+
ethon (0.16.0)
2525
ffi (>= 1.15.0)
2626
eventmachine (1.2.7)
2727
execjs (2.8.1)
28-
faraday (2.5.2)
28+
faraday (2.7.4)
2929
faraday-net_http (>= 2.0, < 3.1)
3030
ruby2_keywords (>= 0.0.4)
31-
faraday-net_http (3.0.0)
31+
faraday-net_http (3.0.2)
3232
ffi (1.15.5)
3333
forwardable-extended (2.6.0)
3434
gemoji (3.0.1)
35-
github-pages (227)
35+
github-pages (228)
3636
github-pages-health-check (= 1.17.9)
37-
jekyll (= 3.9.2)
37+
jekyll (= 3.9.3)
3838
jekyll-avatar (= 0.7.0)
3939
jekyll-coffeescript (= 1.1.1)
40-
jekyll-commonmark-ghpages (= 0.2.0)
40+
jekyll-commonmark-ghpages (= 0.4.0)
4141
jekyll-default-layout (= 0.1.4)
4242
jekyll-feed (= 0.15.1)
4343
jekyll-gist (= 1.5.0)
@@ -71,7 +71,7 @@ GEM
7171
jemoji (= 0.12.0)
7272
kramdown (= 2.3.2)
7373
kramdown-parser-gfm (= 1.1.0)
74-
liquid (= 4.0.3)
74+
liquid (= 4.0.4)
7575
mercenary (~> 0.3)
7676
minima (= 2.5.1)
7777
nokogiri (>= 1.13.6, < 2.0)
@@ -83,17 +83,17 @@ GEM
8383
octokit (~> 4.0)
8484
public_suffix (>= 3.0, < 5.0)
8585
typhoeus (~> 1.3)
86-
html-pipeline (2.14.2)
86+
html-pipeline (2.14.3)
8787
activesupport (>= 2)
8888
nokogiri (>= 1.4)
8989
http_parser.rb (0.8.0)
90-
i18n (0.9.5)
90+
i18n (1.12.0)
9191
concurrent-ruby (~> 1.0)
92-
jekyll (3.9.2)
92+
jekyll (3.9.3)
9393
addressable (~> 2.4)
9494
colorator (~> 1.0)
9595
em-websocket (~> 0.5)
96-
i18n (~> 0.7)
96+
i18n (>= 0.7, < 2)
9797
jekyll-sass-converter (~> 1.0)
9898
jekyll-watch (~> 2.0)
9999
kramdown (>= 1.17, < 3)
@@ -109,11 +109,11 @@ GEM
109109
coffee-script-source (~> 1.11.1)
110110
jekyll-commonmark (1.4.0)
111111
commonmarker (~> 0.22)
112-
jekyll-commonmark-ghpages (0.2.0)
113-
commonmarker (~> 0.23.4)
112+
jekyll-commonmark-ghpages (0.4.0)
113+
commonmarker (~> 0.23.7)
114114
jekyll (~> 3.9.0)
115115
jekyll-commonmark (~> 1.4.0)
116-
rouge (>= 2.0, < 4.0)
116+
rouge (>= 2.0, < 5.0)
117117
jekyll-default-layout (0.1.4)
118118
jekyll (~> 3.0)
119119
jekyll-feed (0.15.1)
@@ -201,25 +201,25 @@ GEM
201201
rexml
202202
kramdown-parser-gfm (1.1.0)
203203
kramdown (~> 2.0)
204-
liquid (4.0.3)
205-
listen (3.7.1)
204+
liquid (4.0.4)
205+
listen (3.8.0)
206206
rb-fsevent (~> 0.10, >= 0.10.3)
207207
rb-inotify (~> 0.9, >= 0.9.10)
208208
mercenary (0.3.6)
209209
minima (2.5.1)
210210
jekyll (>= 3.5, < 5.0)
211211
jekyll-feed (~> 0.9)
212212
jekyll-seo-tag (~> 2.1)
213-
minitest (5.16.3)
214-
nokogiri (1.13.10-x86_64-linux)
213+
minitest (5.17.0)
214+
nokogiri (1.14.3-x86_64-linux)
215215
racc (~> 1.4)
216216
octokit (4.25.1)
217217
faraday (>= 1, < 3)
218218
sawyer (~> 0.9)
219219
pathutil (0.16.2)
220220
forwardable-extended (~> 2.6)
221221
public_suffix (4.0.7)
222-
racc (1.6.1)
222+
racc (1.6.2)
223223
rb-fsevent (0.11.2)
224224
rb-inotify (0.10.1)
225225
ffi (~> 1.0)
@@ -249,14 +249,14 @@ GEM
249249
unf_ext
250250
unf_ext (0.0.8.2)
251251
unicode-display_width (1.8.0)
252-
webrick (1.7.0)
253-
zeitwerk (2.6.1)
252+
webrick (1.8.1)
253+
zeitwerk (2.6.6)
254254

255255
PLATFORMS
256256
x86_64-linux
257257

258258
DEPENDENCIES
259-
github-pages (~> 227)
259+
github-pages (~> 228)
260260
jekyll-feed (~> 0.12)
261261
minima (~> 2.5)
262262
tzinfo (~> 1.2)

docs/index.md

+55-4
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ To use Gomega with Golang's XUnit style tests:
6060

6161
```go
6262
func TestFarmHasCow(t *testing.T) {
63-
g := NewGomegaWithT(t)
63+
g := NewWithT(t)
6464

6565
f := farm.New([]string{"Cow", "Horse"})
6666
g.Expect(f.HasCow()).To(BeTrue(), "Farm should have cow")
6767
}
6868
```
6969

70-
`NewGomegaWithT(t)` wraps a `*testing.T` and returns a struct that supports `Expect`, `Eventually`, and `Consistently`.
70+
`NewWithT(t)` wraps a `*testing.T` and returns a struct that supports `Expect`, `Eventually`, and `Consistently`.
7171

7272
## Making Assertions
7373

@@ -607,7 +607,24 @@ var _ = Describe("Turbo-encabulator", func() {
607607

608608
This makes your tests more expressive and reduces boilerplate. However, when an assertion in the helper fails the line numbers provided by Gomega are unhelpful. Instead of pointing you to the line in your test that failed, they point you the line in the helper.
609609

610-
To get around this, Gomega provides versions of `Expect`, `Eventually` and `Consistently` named `ExpectWithOffset`, `EventuallyWithOffset` and `ConsistentlyWithOffset` that allow you to specify an *offset* in the call stack. The offset is the first argument to these functions.
610+
To fix this, Ginkgo and Gomega provide two options. If you are on a recent version of Ginkgo you can register your helper with Ginkgo via `GinkgoHelper()`:
611+
612+
```go
613+
func assertTurboEncabulatorContains(components ...string) {
614+
GinkgoHelper()
615+
teComponents, err := turboEncabulator.GetComponents()
616+
Expect(err).NotTo(HaveOccurred())
617+
618+
Expect(teComponents).To(HaveLen(components))
619+
for _, component := range components {
620+
Expect(teComponents).To(ContainElement(component))
621+
}
622+
}
623+
```
624+
625+
now, line numbers generated by Ginkgo will skip `assertTurboEncabulatorContains` and point to the calling site instead. `GinkgoHelper()` is the recommended way to solve this problem as it allows for straightforward nesting and reuse of helper functions.
626+
627+
If, for some reason, you can't use `GinkgoHelper()` Gomega does provide an alternative: versions of `Expect`, `Eventually` and `Consistently` named `ExpectWithOffset`, `EventuallyWithOffset` and `ConsistentlyWithOffset` that allow you to specify an *offset* in the call stack. The offset is the first argument to these functions.
611628

612629
With this, we can rewrite our helper as:
613630

@@ -639,6 +656,8 @@ func assertTurboEncabulatorContains(components ...string) {
639656
}
640657
```
641658

659+
Again, we recommend using `GinkgoHelper()` instead of `WithOffset(...)`.
660+
642661
## Provided Matchers
643662

644663
Gomega comes with a bunch of `GomegaMatcher`s. They're all documented here. If there's one you'd like to see written either [send a pull request or open an issue](http://github.com/onsi/gomega).
@@ -804,7 +823,7 @@ succeeds if `ACTUAL` is a non-nil `error` that matches `EXPECTED`. `EXPECTED` mu
804823
- `errors.Is(ACTUAL, EXPECTED)` returns `true`
805824
- `ACTUAL` or any of the errors it wraps (directly or indirectly) equals `EXPECTED` in terms of `reflect.DeepEqual()`.
806825

807-
Any other type for `EXPECTED` is an error.
826+
Any other type for `EXPECTED` is an error. It is also an error for `ACTUAL` to be nil.
808827

809828
### Working with Channels
810829

@@ -1196,6 +1215,38 @@ is the only element passed in to `ConsistOf`:
11961215

11971216
Note that Go's type system does not allow you to write this as `ConsistOf([]string{"FooBar", "Foo"}...)` as `[]string` and `[]interface{}` are different types - hence the need for this special rule.
11981217

1218+
#### HaveExactElements(element ...interface{})
1219+
1220+
```go
1221+
Expect(ACTUAL).To(HaveExactElements(ELEMENT1, ELEMENT2, ELEMENT3, ...))
1222+
```
1223+
1224+
or
1225+
1226+
```go
1227+
Expect(ACTUAL).To(HaveExactElements([]SOME_TYPE{ELEMENT1, ELEMENT2, ELEMENT3, ...}))
1228+
```
1229+
1230+
succeeds if `ACTUAL` contains precisely the elements and ordering passed into the matchers.
1231+
1232+
By default `HaveExactElements()` uses `Equal()` to match the elements, however custom matchers can be passed in instead. Here are some examples:
1233+
1234+
```go
1235+
Expect([]string{"Foo", "FooBar"}).To(HaveExactElements("Foo", "FooBar"))
1236+
Expect([]string{"Foo", "FooBar"}).To(HaveExactElements("Foo", ContainSubstring("Bar")))
1237+
Expect([]string{"Foo", "FooBar"}).To(HaveExactElements(ContainSubstring("Foo"), ContainSubstring("Foo")))
1238+
```
1239+
1240+
Actual must be an `array` or `slice`.
1241+
1242+
You typically pass variadic arguments to `HaveExactElements` (as in the examples above). However, if you need to pass in a slice you can provided that it
1243+
is the only element passed in to `HaveExactElements`:
1244+
1245+
```go
1246+
Expect([]string{"Foo", "FooBar"}).To(HaveExactElements([]string{"FooBar", "Foo"}))
1247+
```
1248+
1249+
Note that Go's type system does not allow you to write this as `HaveExactElements([]string{"FooBar", "Foo"}...)` as `[]string` and `[]interface{}` are different types - hence the need for this special rule.
11991250

12001251
#### HaveEach(element ...interface{})
12011252

format/format.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var CharactersAroundMismatchToInclude uint = 5
5252
var contextType = reflect.TypeOf((*context.Context)(nil)).Elem()
5353
var timeType = reflect.TypeOf(time.Time{})
5454

55-
//The default indentation string emitted by the format package
55+
// The default indentation string emitted by the format package
5656
var Indent = " "
5757

5858
var longFormThreshold = 20
@@ -258,7 +258,11 @@ Set PrintContextObjects to true to print the content of objects implementing con
258258
func Object(object interface{}, indentation uint) string {
259259
indent := strings.Repeat(Indent, int(indentation))
260260
value := reflect.ValueOf(object)
261-
return fmt.Sprintf("%s<%s>: %s", indent, formatType(value), formatValue(value, indentation))
261+
commonRepresentation := ""
262+
if err, ok := object.(error); ok {
263+
commonRepresentation += "\n" + IndentString(err.Error(), indentation) + "\n" + indent
264+
}
265+
return fmt.Sprintf("%s<%s>: %s%s", indent, formatType(value), commonRepresentation, formatValue(value, indentation))
262266
}
263267

264268
/*

gcustom/make_matcher.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ func MakeMatcher(matchFunc any, args ...any) CustomGomegaMatcher {
9797
finalMatchFunc = reflect.MakeFunc(reflect.TypeOf(finalMatchFunc),
9898
func(args []reflect.Value) []reflect.Value {
9999
actual := args[0].Interface()
100-
if reflect.TypeOf(actual).AssignableTo(t.In(0)) {
100+
if actual == nil && reflect.TypeOf(actual) == reflect.TypeOf(nil) {
101+
return matchFuncValue.Call([]reflect.Value{reflect.New(t.In(0)).Elem()})
102+
} else if reflect.TypeOf(actual).AssignableTo(t.In(0)) {
101103
return matchFuncValue.Call([]reflect.Value{reflect.ValueOf(actual)})
102104
} else {
103105
return []reflect.Value{

gomega_dsl.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"github.com/bsm/gomega/types"
2323
)
2424

25-
const GOMEGA_VERSION = "1.26.0"
25+
const GOMEGA_VERSION = "1.27.7"
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().
@@ -204,7 +204,7 @@ func Ω(actual interface{}, extra ...interface{}) Assertion {
204204
// All subsequent arguments will be required to be nil/zero.
205205
//
206206
// This is convenient if you want to make an assertion on a method/function that returns
207-
// a value and an error - a common patter in Go.
207+
// a value and an error - a common pattern in Go.
208208
//
209209
// For example, given a function with signature:
210210
//

internal/async_assertion.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ func (assertion *AsyncAssertion) match(matcher types.GomegaMatcher, desiredMatch
412412
message += format.Object(attachment.Object, 1)
413413
}
414414
} else {
415-
message = preamble + "\n" + err.Error() + "\n" + format.Object(err, 1)
415+
message = preamble + "\n" + format.Object(err, 1)
416416
}
417417
return message
418418
}
@@ -425,10 +425,18 @@ func (assertion *AsyncAssertion) match(matcher types.GomegaMatcher, desiredMatch
425425

426426
if actualErr == nil {
427427
if matcherErr == nil {
428-
if desiredMatch {
429-
message += matcher.FailureMessage(actual)
428+
if desiredMatch != matches {
429+
if desiredMatch {
430+
message += matcher.FailureMessage(actual)
431+
} else {
432+
message += matcher.NegatedFailureMessage(actual)
433+
}
430434
} else {
431-
message += matcher.NegatedFailureMessage(actual)
435+
if assertion.asyncType == AsyncAssertionTypeConsistently {
436+
message += "There is no failure as the matcher passed to Consistently has not yet failed"
437+
} else {
438+
message += "There is no failure as the matcher passed to Eventually succeeded on its most recent iteration"
439+
}
432440
}
433441
} else {
434442
var fgErr formattedGomegaError

matchers.go

+21-4
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,17 @@ func Succeed() types.GomegaMatcher {
7676
return &matchers.SucceedMatcher{}
7777
}
7878

79-
// MatchError succeeds if actual is a non-nil error that matches the passed in string/error.
79+
// MatchError succeeds if actual is a non-nil error that matches the passed in
80+
// string, error, or matcher.
8081
//
8182
// These are valid use-cases:
8283
//
83-
// Expect(err).Should(MatchError("an error")) //asserts that err.Error() == "an error"
84-
// Expect(err).Should(MatchError(SomeError)) //asserts that err == SomeError (via reflect.DeepEqual)
84+
// Expect(err).Should(MatchError("an error")) //asserts that err.Error() == "an error"
85+
// Expect(err).Should(MatchError(SomeError)) //asserts that err == SomeError (via reflect.DeepEqual)
86+
// Expect(err).Should(MatchError(ContainsSubstring("sprocket not found"))) // asserts that edrr.Error() contains substring "sprocket not found"
8587
//
86-
// It is an error for err to be nil or an object that does not implement the Error interface
88+
// It is an error for err to be nil or an object that does not implement the
89+
// Error interface
8790
func MatchError(expected interface{}) types.GomegaMatcher {
8891
return &matchers.MatchErrorMatcher{
8992
Expected: expected,
@@ -320,6 +323,20 @@ func ConsistOf(elements ...interface{}) types.GomegaMatcher {
320323
}
321324
}
322325

326+
// HaveExactElemets succeeds if actual contains elements that precisely match the elemets passed into the matcher. The ordering of the elements does matter.
327+
// By default HaveExactElements() uses Equal() to match the elements, however custom matchers can be passed in instead. Here are some examples:
328+
//
329+
// Expect([]string{"Foo", "FooBar"}).Should(HaveExactElements("Foo", "FooBar"))
330+
// Expect([]string{"Foo", "FooBar"}).Should(HaveExactElements("Foo", ContainSubstring("Bar")))
331+
// Expect([]string{"Foo", "FooBar"}).Should(HaveExactElements(ContainSubstring("Foo"), ContainSubstring("Foo")))
332+
//
333+
// Actual must be an array or slice.
334+
func HaveExactElements(elements ...interface{}) types.GomegaMatcher {
335+
return &matchers.HaveExactElementsMatcher{
336+
Elements: elements,
337+
}
338+
}
339+
323340
// ContainElements succeeds if actual contains the passed in elements. The ordering of the elements does not matter.
324341
// By default ContainElements() uses Equal() to match the elements, however custom matchers can be passed in instead. Here are some examples:
325342
//

0 commit comments

Comments
 (0)