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

Usage experience of with #21

Open
phunehehe opened this issue Oct 31, 2023 · 0 comments
Open

Usage experience of with #21

phunehehe opened this issue Oct 31, 2023 · 0 comments

Comments

@phunehehe
Copy link

Hi! First of all thanks for making this library!

This is not really an issue...
I'm not sure what I'm trying to suggest, just want to put this out here in case it helps someone somehow.

I found the following pattern (from the README) surprisingly frustrating to maintain:

GrpcMock.
  stub_request("/hello.hello/Hello").
  with(Hello::HelloRequest.new(msg: 'hi')).
  to_return(Hello::HelloResponse.new(msg: 'test'))

It reads nicely and it works well, but the wrinkle comes when the matcher doesn't work for some reason (most likely it's because I'm making changes to the request). Then it doesn't match and I get a confusing error saying real requests are not allowed. Even if I know what it's about and try to investigate, there's no way to inspect the request as written.

I find myself using the following pattern more:

GrpcMock.
  stub_request("/hello.hello/Hello").
  to_return do |request|
    expect(request).to eq(Hello::HelloRequest.new(msg: 'hi'))
    Hello::HelloResponse.new(msg: 'test')
  end

It's slightly longer, but when something goes wrong it tells me exactly where.

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

No branches or pull requests

1 participant