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

fix transformation error reporting #479

Merged
merged 1 commit into from Nov 2, 2021
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
2 changes: 1 addition & 1 deletion matchers.go
Expand Up @@ -492,7 +492,7 @@ func Not(matcher types.GomegaMatcher) types.GomegaMatcher {
// Expect(1).To(WithTransform(plus1, Equal(2))
//
// var failingplus1 = func(i int) (int, error) { return 42, "this does not compute" }
// Expect(1).To(WithTrafo(failingplus1, Equal(2)))
// Expect(1).To(WithTransform(failingplus1, Equal(2)))
//
//And(), Or(), Not() and WithTransform() allow matchers to be composed into complex expressions.
func WithTransform(transform interface{}, matcher types.GomegaMatcher) types.GomegaMatcher {
Expand Down
2 changes: 1 addition & 1 deletion matchers/with_transform.go
Expand Up @@ -64,7 +64,7 @@ func (m *WithTransformMatcher) Match(actual interface{}) (bool, error) {
result := fn.Call([]reflect.Value{param})
if len(result) == 2 {
if !result[1].IsNil() {
return false, fmt.Errorf("Transform function failed: %e", result[1].Interface())
return false, fmt.Errorf("Transform function failed: %s", result[1].Interface().(error).Error())
}
}
m.transformedValue = result[0].Interface() // expect exactly one value
Expand Down
2 changes: 1 addition & 1 deletion matchers/with_transform_test.go
Expand Up @@ -132,7 +132,7 @@ var _ = Describe("WithTransformMatcher", func() {
success, err := WithTransform(trafo, Equal(actual)).Match(actual)
Expect(success).To(BeFalse())
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("that does not transform"))
Expect(err.Error()).To(MatchRegexp(": that does not transform$"))
})
})

Expand Down