{"id":49269469,"url":"https://github.com/rocksolt/ruby_llm-test","last_synced_at":"2026-04-26T13:00:29.741Z","repository":{"id":353403923,"uuid":"1217440433","full_name":"RockSolt/ruby_llm-test","owner":"RockSolt","description":"Stub your RubyLLM calls to test application logic.","archived":false,"fork":false,"pushed_at":"2026-04-24T16:09:09.000Z","size":59,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-25T12:36:55.739Z","etag":null,"topics":["llm","ruby","ruby-llm","testing"],"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/RockSolt.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-21T22:18:26.000Z","updated_at":"2026-04-24T16:09:13.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/RockSolt/ruby_llm-test","commit_stats":null,"previous_names":["rocksolt/ruby_llm-test"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/RockSolt/ruby_llm-test","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RockSolt%2Fruby_llm-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RockSolt%2Fruby_llm-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RockSolt%2Fruby_llm-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RockSolt%2Fruby_llm-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RockSolt","download_url":"https://codeload.github.com/RockSolt/ruby_llm-test/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RockSolt%2Fruby_llm-test/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32297898,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T09:34:17.070Z","status":"ssl_error","status_checked_at":"2026-04-26T09:34:00.993Z","response_time":129,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["llm","ruby","ruby-llm","testing"],"created_at":"2026-04-25T12:36:52.381Z","updated_at":"2026-04-26T13:00:29.736Z","avatar_url":"https://github.com/RockSolt.png","language":"Ruby","readme":"# RubyLLM::Test\n\nThis gem provides testing utilities for RubyLLM, a Ruby library for working with large language models (LLMs). It enables calls to LLM's to be stubbed so that the surrounding application logic can be tested without making actual calls to the LLM. This is particularly useful for testing code that interacts with LLMs, as it allows developers to simulate responses from the LLM without incurring the cost, latency, or randomness of real API calls.\n\n```ruby\nRubyLLM::Test.stub_response(\"Outlook good\")\n\nchat = RubyLLM.chat\nresponse = chat.ask \"What are the odds this works?\"\n\nassert_equal \"Outlook good\", response.content\n```\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'ruby_llm-test'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install ruby_llm-test\n\n## Usage\n\nAdd the following lines to your `spec/spec_helper.rb` or `test/test_helper.rb`:\n\n```ruby\nrequire 'ruby_llm/test'\n\nRubyLLM::Models.singleton_class.prepend(RubyLLM::Test::ResolveWithTestProvider)\n```\n\nThen, in your tests, you can use the `stub_response` method to stub responses from the LLM. For example:\n\n```ruby\nit 'returns a stubbed response' do\n  RubyLLM::Test.stub_response('Hello, world!')\n\n  response = MyLLMClient.call('Hello?')\n  expect(response).to eq('Hello, world!')\nend\n```\n\nIf you make multiple calls to the LLM, you can call `stub_response` more than once or use method `stub_responses` to stub multiple responses at once. For example:\n\n```ruby\nit 'returns multiple stubbed responses' do\n  RubyLLM::Test.stub_responses('Hello, world!', 'How are you?')\n  response1 = MyLLMClient.call('Hello?')\n  response2 = MyLLMClient.call('How are you?')\n\n  expect(response1).to eq('Hello, world!')\n  expect(response2).to eq('How are you?')\nend\n```\n\n### Stubbing with a Message\n\nIf you stub with a string, it will be wrapped in a `RubyLLM::Message` with the role of `:assistant`. If you want more control over the message, you can stub with a `RubyLLM::Message` directly. For example:\n\n```ruby\nit 'returns a stubbed message' do\n  message = RubyLLM::Message.new(role: :assistant, content: 'Hello, world!')\n  RubyLLM::Test.stub_response(message)\n\n  response = MyLLMClient.call('Hello?')\n  expect(response).to eq(message)\nend\n```\n\n### Stubbing with a Hash Returns JSON\n\nIf you stub with a hash, it will be converted to a `RubyLLM::Message` with the content set to the JSON representation of the hash. For example:\n\n```ruby\nit 'returns a stubbed JSON message' do\n  hash = { key: 'value' }\n  RubyLLM::Test.stub_response(hash)\n\n  response = MyLLMClient.call('Hello?')\n  expect(response.content).to eq(hash.to_json)\nend\n```\n\n### Resetting Stubs\n\nMake sure to reset stubs after each test to avoid interference before or between tests.\n\n```ruby\nRubyLLM::Test.reset\n```\n\n### Stubbing with a Block\n\nYou can also stub responses in a block, which handles the setup and teardown of stubs automatically. For example:\n\n```ruby\n\nRubyLLM::Test.with_responses('Hello, world!') do\n  response = MyLLMClient.call('Hello?')\n  expect(response).to eq('Hello, world!')\nend\n```\n\n## Development\n\nAfter checking out 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\nTo install this gem onto your local machine, run `bundle exec rake install`. 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## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/RockSolt/ruby_llm-test.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frocksolt%2Fruby_llm-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frocksolt%2Fruby_llm-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frocksolt%2Fruby_llm-test/lists"}