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

any thoughts on adapting gomega matchers to gomock.Matcher interface #451

Open
cadina opened this issue Jun 16, 2021 · 5 comments
Open

any thoughts on adapting gomega matchers to gomock.Matcher interface #451

cadina opened this issue Jun 16, 2021 · 5 comments

Comments

@cadina
Copy link

cadina commented Jun 16, 2021

so we can use them as gomock EXPECT arguments. the original matchers of gomock is too weak when dealing with complex types and assertions.

@cadina
Copy link
Author

cadina commented Jun 16, 2021

now i'm using a simple wrapper like:

type GomegaMatcher interface {
	Match(actual interface{}) (success bool, err error)
	FailureMessage(actual interface{}) (message string)
}

type matcher struct {
	GomegaMatcher
	x interface{}
}

func (m matcher) Matches(x interface{}) bool {
	m.x = x
	result, _ := m.Match(x)
	return result
}

func (m matcher) String() string {
	return m.FailureMessage(m.x)
}

func m(gmather GomegaMatcher) gomock.Matcher {
	return matcher{gmather, nil}
}

@onsi
Copy link
Owner

onsi commented Jun 16, 2021

I was going to ask if a wrapper was working. That would be what I would recommend and how I would approach it.

I could see adding a gomock adapter extension to gomega (something like gomega/extensions/gomockadaptor) - but i'd prefer not making this part of the core DSL or gomega matcher interface.

@cadina
Copy link
Author

cadina commented Jun 16, 2021

I was going to ask if a wrapper was working. That would be what I would recommend and how I would approach it.

I could see adding a gomock adapter extension to gomega (something like gomega/extensions/gomockadaptor) - but i'd prefer not making this part of the core DSL or gomega matcher interface.

that would be perfect.

i'm also thinking about taking full advantage of mockgen or something like that. just like how it generates mock recorders, we should be able to extract struct types from input and output arguments and generate strong typed structure matchers. that will be a lot better than the map we used for MatchAllFields.

@onsi
Copy link
Owner

onsi commented Jun 16, 2021

i'm heads down working on ginkgo 2.0 these days but making it easier to build custom marchers in gomega is something i'm interested in working on next. if you have bandwidth and are up for a PR I'd be happy to to pull in a gomock adapter and to take a look at a matcher generator with you!

@cadina
Copy link
Author

cadina commented Jun 17, 2021

@onsi sure. i will take some time to walk through the codebase and see what i can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants