{"id":16748335,"url":"https://github.com/ganmacs/grpc_mock","last_synced_at":"2025-04-07T07:11:21.610Z","repository":{"id":38707689,"uuid":"139967822","full_name":"ganmacs/grpc_mock","owner":"ganmacs","description":"Library for stubbing gRPC requests in Ruby.","archived":false,"fork":false,"pushed_at":"2024-05-18T01:04:55.000Z","size":87,"stargazers_count":45,"open_issues_count":5,"forks_count":19,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-14T02:12:22.867Z","etag":null,"topics":["grpc","grpc-ruby","ruby","stubbing-requests"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ganmacs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-06T10:01:30.000Z","updated_at":"2024-09-23T22:45:01.000Z","dependencies_parsed_at":"2024-10-25T18:35:32.248Z","dependency_job_id":"cacef8b0-3609-4aa0-b817-dac9428bcc96","html_url":"https://github.com/ganmacs/grpc_mock","commit_stats":{"total_commits":79,"total_committers":11,"mean_commits":7.181818181818182,"dds":"0.30379746835443033","last_synced_commit":"f19c080596fe991c721b2df81dadbe2018c04856"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ganmacs%2Fgrpc_mock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ganmacs%2Fgrpc_mock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ganmacs%2Fgrpc_mock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ganmacs%2Fgrpc_mock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ganmacs","download_url":"https://codeload.github.com/ganmacs/grpc_mock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247608153,"owners_count":20965952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["grpc","grpc-ruby","ruby","stubbing-requests"],"created_at":"2024-10-13T02:12:22.986Z","updated_at":"2025-04-07T07:11:21.589Z","avatar_url":"https://github.com/ganmacs.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GrpcMock [![Build Status](https://github.com/ganmacs/grpc_mock/actions/workflows/ci.yml/badge.svg)](https://github.com/ganmacs/grpc_mock/actions/workflows/ci.yml)\n\nLibrary for stubbing grpc in Ruby.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'grpc_mock'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install grpc_mock\n\n## Usage\n\nIf you use [RSpec](https://github.com/rspec/rspec), add the following code to spec/spec_helper.rb:\n\n```ruby\nrequire 'grpc_mock/rspec'\n```\n\n## Examples\n\nSee definition of protocol buffers and gRPC generated code in [spec/examples/hello](https://github.com/ganmacs/grpc_mock/tree/master/spec/examples/hello)\n\n### Stubbed request based on path and with the default response\n\n```ruby\nGrpcMock.stub_request(\"/hello.hello/Hello\").to_return(Hello::HelloResponse.new(msg: 'test'))\n\nclient = Hello::Hello::Stub.new('localhost:8000', :this_channel_is_insecure)\nclient.hello(Hello::HelloRequest.new(msg: 'hi')) # =\u003e Hello::HelloResponse.new(msg: 'test')\n```\n\n### Stubbing requests based on path and request\n\n```ruby\nGrpcMock.stub_request(\"/hello.hello/Hello\").with(Hello::HelloRequest.new(msg: 'hi')).to_return(Hello::HelloResponse.new(msg: 'test'))\n\nclient = Hello::Hello::Stub.new('localhost:8000', :this_channel_is_insecure)\nclient.hello(Hello::HelloRequest.new(msg: 'hello')) # =\u003e send a request to server\nclient client.hello(Hello::HelloRequest.new(msg: 'hi'))    # =\u003e Hello::HelloResponse.new(msg: 'test') (without any requests to server)\n```\n\n### Responding dynamically to the stubbed requests\n\n```ruby\nGrpcMock.stub_request(\"/hello.hello/Hello\").to_return do |req, call|\n  Hello::HelloResponse.new(msg: \"#{req.msg} too\")\nend\n\nclient = Hello::Hello::Stub.new('localhost:8000', :this_channel_is_insecure)\nclient.hello(Hello::HelloRequest.new(msg: 'hi'))    # =\u003e Hello::HelloResponse.new(msg: 'hi too')\n```\n\n### Real requests to network can be allowed or disabled\n\n```ruby\nclient = Hello::Hello::Stub.new('localhost:8000', :this_channel_is_insecure)\n\nGrpcMock.disable_net_connect!\nclient.hello(Hello::HelloRequest.new(msg: 'hello')) # =\u003e Raise NetConnectNotAllowedError error\n\nGrpcMock.allow_net_connect!\nHello::Hello::Stub.new('localhost:8000', :this_channel_is_insecure) # =\u003e send a request to server\n```\n\n### Raising errors\n\n**Exception declared by class**\n\n```ruby\nGrpcMock.stub_request(\"/hello.hello/Hello\").to_raise(StandardError)\n\nclient = Hello::Hello::Stub.new('localhost:8000', :this_channel_is_insecure)\nclient.hello(Hello::HelloRequest.new(msg: 'hi')) # =\u003e Raise StandardError\n```\n\n**or by exception instance**\n\n```ruby\nGrpcMock.stub_request(\"/hello.hello/Hello\").to_raise(StandardError.new(\"Some error\"))\n```\n\n**or by string**\n\n```ruby\nGrpcMock.stub_request(\"/hello.hello/Hello\").to_raise(\"Some error\")\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/ganmacs/grpc_mock. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fganmacs%2Fgrpc_mock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fganmacs%2Fgrpc_mock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fganmacs%2Fgrpc_mock/lists"}