GrpcMock Build Status

Library for stubbing grpc in Ruby.


Add this line to your application's Gemfile:

gem 'grpc_mock'

And then execute:

$ bundle

Or install it yourself as:

$ gem install grpc_mock


If you use RSpec, add the following code to spec/spec_helper.rb:

require 'grpc_mock/rspec'


See definition of protocol buffers and gRPC generated code in spec/exmaples/hello

Stubbed request based on path and with the default response
GrpcMock.stub_request("/hello.hello/Hello").to_return( 'test'))

client ='localhost:8000', :this_channel_is_insecure)
client = client.hello( 'hi')) # => 'test')
Stubbing requests based on path and request
GrpcMock.stub_request("/hello.hello/Hello").with( 'hi')).to_return( 'test'))

client ='localhost:8000', :this_channel_is_insecure)
client = client.hello( 'hello')) # => send a request to server
client = client.hello( 'hi'))    # => 'test') (without any requests to server)
Real requests to network can be allowed or disabled
client ='localhost:8000', :this_channel_is_insecure)

client = client.hello( 'hello')) # => Raise NetConnectNotAllowedError error

client ='localhost:8000', :this_channel_is_insecure) # => send a request to server


Bug reports and pull requests are welcome on GitHub at This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.


The gem is available as open source under the terms of the MIT License.