WebMock::Twirp
Twirp support for WebMock. All our favorite http request stubbing for Twirp RPCs - message and error serialization done automatically.
require "webmock/twirp"
it "stubs twirp calls" do
stub_twirp_request
client.my_rpc_method(request)
end
it "matches calls from specific twirp clients and rpc methods" do
stub_twirp_request(MyTwirpClient, :optional_rpc_method)
end
# match parameters
stub_twirp_request.with(my_request_message: /^foo/)
# or use block mode
stub_twirp_request.with do |request|
request # the Twirp request, aka. proto message, used to initiate the request
request. == "hello"
end
# stub responses
stub_twirp_request.and_return(return_message: "yo yo")
stub_twirp_request.and_return(404) # results in a Twirp::Error.not_found
# or use block mode
stub_twirp_request.and_return do |request|
{ response_message: "oh hi" } # will get properly packaged up
end
Contributing
Yes please :)
- Fork it
- Create your feature branch (
git checkout -b my-feature) - Ensure the tests pass (
bundle exec rspec) - Commit your changes (
git commit -am 'awesome new feature') - Push your branch (
git push origin my-feature) - Create a Pull Request