{"id":13877988,"url":"https://github.com/clarkedb/grift","last_synced_at":"2026-01-04T00:19:57.812Z","repository":{"id":36968940,"uuid":"416333153","full_name":"clarkedb/grift","owner":"clarkedb","description":"Mocking and spying in Ruby's MiniTest framework","archived":false,"fork":false,"pushed_at":"2025-07-11T13:24:33.000Z","size":374,"stargazers_count":11,"open_issues_count":3,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-11T15:46:36.989Z","etag":null,"topics":["minitest","minitest-plugins","mock","mocking","ruby","testing","testing-tools","unit-testing"],"latest_commit_sha":null,"homepage":"https://clarkedb.github.io/grift","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/clarkedb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["clarkedb"]}},"created_at":"2021-10-12T12:43:05.000Z","updated_at":"2025-07-11T13:24:43.000Z","dependencies_parsed_at":"2024-01-13T09:14:45.395Z","dependency_job_id":"608ac7f2-1fea-4f98-8037-aaa29571daaf","html_url":"https://github.com/clarkedb/grift","commit_stats":{"total_commits":120,"total_committers":3,"mean_commits":40.0,"dds":"0.33333333333333337","last_synced_commit":"2709f1330feac50ba8f797b092f929b54735c2c0"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/clarkedb/grift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarkedb%2Fgrift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarkedb%2Fgrift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarkedb%2Fgrift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarkedb%2Fgrift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clarkedb","download_url":"https://codeload.github.com/clarkedb/grift/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarkedb%2Fgrift/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264851372,"owners_count":23673235,"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":["minitest","minitest-plugins","mock","mocking","ruby","testing","testing-tools","unit-testing"],"created_at":"2024-08-06T08:01:36.813Z","updated_at":"2026-01-04T00:19:57.767Z","avatar_url":"https://github.com/clarkedb.png","language":"Ruby","readme":"# Grift\n\n[![gem version](https://badge.fury.io/rb/grift.svg)](https://rubygems.org/gems/grift)\n[![build](https://github.com/clarkedb/grift/actions/workflows/ci.yml/badge.svg)](https://github.com/clarkedb/grift/actions?query=workflow%3ACI)\n[![codecov](https://codecov.io/gh/clarkedb/grift/branch/main/graph/badge.svg)](https://codecov.io/gh/clarkedb/grift)\n\nMocking and spying in Ruby's MiniTest framework\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'grift'\n```\n\nAnd then execute:\n\n```shell\nbundle install\n```\n\nOr install it yourself as:\n\n```shell\ngem install grift\n```\n\n### MiniTest Plugin\n\nWe recommend using the plugin so that mocks are cleaned up after each test automatically. To enable the plugin, add the following lines of code to your `test_helper` file.\n\n```ruby\nclass Minitest::Test\n  include Grift::MinitestPlugin\nend\n```\n\nOr for Ruby on Rails:\n\n```ruby\nclass ActiveSupport::TestCase\n  include Grift::MinitestPlugin\nend\n```\n\n## Usage\n\nFor complete usage guide, see the [docs](https://clarkedb.github.io/grift/).\n\n### Spy\n\nTo \"mock\" a method and spy on its call args and results without changing the behavior of the method:\n\n```ruby\nmy_mock = Grift.spy_on(MyClass, :my_method)\n```\n\n### Mock\n\nTo mock a method and its return value:\n\n```ruby\nmy_mock = Grift.mock(MyClass, :my_method, return_value)\n\nmy_spy = Grift.spy_on(MyClass, :my_method)\nmy_spy.mock_return_value(return_value)\n```\n\nTo mock the implementation:\n\n```ruby\nmy_spy = Grift.spy_on(MyClass, :my_method)\nmy_spy.mock_implementation do |arg1, arg2|\n    x = do_something(arg1, arg2)\n    do_something_else(x) # the last line will be returned\nend\n```\n\nor for a method taking keyword arguments:\n\n```ruby\nmy_spy = Grift.spy_on(MyClass, :my_method)\nmy_spy.mock_implementation do |arg1, arg2, **kwargs|\n    x = do_something(arg1, arg2, kwargs[:arg3], kwargs[:arg4])\n    do_something_else(x) # the last line will be returned\nend\n```\n\n### Chaining\n\nYou can chain `mock_return_value` and `mock_implementation` after initializing the mock.\n\n```ruby\nmy_mock = Grift.spy_on(MyClass, :my_method).mock_implementation do |*args, **kwargs|\n    do_something(*args, **kwargs)\nend\n#=\u003e Grift::MockMethod object is returned\n```\n\n### Results\n\nTo get the results and details of the calls, call `calls` or `results` on your mock method object.\n\n```ruby\n# get the number of times the mocked method has been called\nmy_mock.count\n#=\u003e 2\n\n# get args for each call to the method while mocked\nmy_mock.calls[0].args\n#=\u003e ['first_arg1', 'second_arg1']\n\n# get kwargs for each call to the method while mocked\nmy_mock.calls[0].kwargs\n#=\u003e { first_arg1: 'value' }\n\n# get results (return value) for each call to the method while mocked\nmy_mock.results\n#=\u003e ['result1', 'result2']\n```\n\n## Requirements\n\nGrift supports all Ruby versions \u003e= 2.7 (including 3.4).\n\n## Development\n\nAfter forking the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nWhen developing, to install Grift whith your changes onto your local machine, run `bundle exec rake install` . For those with write access: to release a new version, update the version number in `version.rb` , and then run `bundle exec rake release` , which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n### Docs\n\nThe docs are generated using YARD. To build the docs, first `gem install yard` . Then run `yardoc` to build the new docs. This is always done before a release to update the docs that get published and made available with the gem.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at [clarkedb/grift](https://github.com/clarkedb/grift). Before submitting a pull request, see [CONTRIBUTING](.github/CONTRIBUTING.md).\n","funding_links":["https://github.com/sponsors/clarkedb"],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclarkedb%2Fgrift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclarkedb%2Fgrift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclarkedb%2Fgrift/lists"}