{"id":13521410,"url":"https://github.com/shiroyasha/factory_bot_instruments","last_synced_at":"2025-08-03T15:30:51.216Z","repository":{"id":55981745,"uuid":"90152919","full_name":"shiroyasha/factory_bot_instruments","owner":"shiroyasha","description":"Instruments for benchmarking, tracing, and debugging Factory Girl models.","archived":false,"fork":false,"pushed_at":"2023-09-21T11:01:03.000Z","size":41,"stargazers_count":126,"open_issues_count":0,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-27T16:51:31.636Z","etag":null,"topics":["benchmark","factory-girl","rails","ruby","rubygems","testing","tracing"],"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/shiroyasha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2017-05-03T13:37:01.000Z","updated_at":"2025-05-22T23:21:05.000Z","dependencies_parsed_at":"2024-06-16T00:36:18.921Z","dependency_job_id":"67f8d2d4-350e-480f-bbd7-561d89c677ba","html_url":"https://github.com/shiroyasha/factory_bot_instruments","commit_stats":{"total_commits":23,"total_committers":3,"mean_commits":7.666666666666667,"dds":"0.13043478260869568","last_synced_commit":"1610c3e68c672840a34e3360d801cad9e080d8db"},"previous_names":["shiroyasha/factory_girl_instruments"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/shiroyasha/factory_bot_instruments","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shiroyasha%2Ffactory_bot_instruments","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shiroyasha%2Ffactory_bot_instruments/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shiroyasha%2Ffactory_bot_instruments/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shiroyasha%2Ffactory_bot_instruments/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shiroyasha","download_url":"https://codeload.github.com/shiroyasha/factory_bot_instruments/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shiroyasha%2Ffactory_bot_instruments/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267391334,"owners_count":24079899,"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","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["benchmark","factory-girl","rails","ruby","rubygems","testing","tracing"],"created_at":"2024-08-01T06:00:34.056Z","updated_at":"2025-08-03T15:30:50.885Z","avatar_url":"https://github.com/shiroyasha.png","language":"Ruby","funding_links":[],"categories":["Ruby","Tools"],"sub_categories":[],"readme":"# Factory Bot Instruments\n\n[![Gem Version](https://badge.fury.io/rb/factory_bot_instruments.svg)](https://badge.fury.io/rb/factory_bot_instruments)\n\nInstruments for benchmarking, tracing, and debugging\n[Factory Bot](https://github.com/thoughtbot/factory_bot) models.\n\nTable of content:\n\n- [Setup](#setup)\n- [Benchmark one Factory](#benchmarking-one-factory-bot-model)\n- [Benchmark all Factories](#benchmarking-all-factory-bot-models)\n- [Trace Factory Bot calls](#tracing-factory-bot-calls)\n\n## Purpose of this gem\n\nFactory Bot is probably the base of your Rails test suite, but how deeply you\nunderstand the models and the associations that are created in your tests?\n\nFactory Bot Instruments help in these three aspects:\n\n1. Slow test suites: Factory Bot is used for the bulk of tests in Rails. Even a\n   small performance improvement in one of your factories can dramatically\n   improve the speed of your overall test suite.\n\n   Hint: Run `FactoryBot.benchmark_all`.\n\n2. Deeper understanding of the database state: By tracing factory bot and SQL\n   calls you can get a deeper understanding of what is actually created in your\n   tests, helping you to debug the issues faster.\n\n   Hint: Run `FactoryBot.trace { FactoryBot.create(:user) }`.\n\n3. Find issues with missconfigured factories: When a factory is properly set up\n   it is a bliss to work with it. However, if there is a hidden deep in the\n   association chain debugging the created model can be a hellish experience.\n\n   Hint: Run `FactoryBot.trace { FactoryBot.create(:user) }` and observe the\n   chain of calls.\n\n## Install\n\nAdd the following to your Gemfile:\n\n```ruby\ngem 'factory_bot_instruments'\n```\n\nand run `bundle install` from your shell.\n\nTo install the gem manually from your shell, run:\n\n``` ruby\ngem install factory_bot_instruments\n```\n\n## Documentation\n\n### Benchmarking one Factory Bot model\n\nIf you have a `user` factory, you can benchmark it with:\n\n``` ruby\nFactoryBot.benchmark(:user)\n```\n\nBy default, the `FactoryBot.create(\u003cmodel\u003e)` is called. You can pass `:method`\nto override this:\n\n``` ruby\nFactoryBot.benchmark(:user, :method =\u003e :build_stubbed)\n```\n\nThe above snippet will call `FactoryBot.build_stubbed(:user)`.\n\n### Benchmarking all Factory Bot models\n\nTo collect benchmarking information from all Factory Bot models:\n\n``` ruby\nFactoryBot.benchmark_all\n```\n\nTo skip a factory, pass the `:except` options:\n\n``` ruby\nFactoryBot.benchmark_all(:except =\u003e [:user])\n```\n\nBy default, benchmarks for `FactoryBot.create(\u003cmodel\u003e)`,\n`FactoryBot.build(\u003cmodel\u003e)`, `FactoryBot.build_stubbed(\u003cmodel\u003e)` are\ncollected. You can override this by passing an array of methods:\n\n``` ruby\nFactoryBot.benchmark_all(:methods =\u003e [:create]) # benchmark only :create\n```\n\n### Tracing Factory Bot calls\n\nTo trace factory Bot actions, wrap your call in the `FactoryBot.trace` method:\n\n``` ruby\nFactoryBot.trace do\n  FactoryBot.create(:comment)\nend\n```\n\nThe above snippet will output the following tree:\n\n``` txt\n┌ (start) create :comment\n|  ┌ (start) create :user\n|  |  (0.1ms)  begin transaction\n|  |  (0.4ms)  INSERT INTO \"users\" (\"name\", \"username\") VALUES (?, ?)  [[\"name\", \"Peter Parker\"], [\"username\", \"spiderman\"]]\n|  |  (2.3ms)  commit transaction\n|  └ (finish) create :user [0.010s]\n|  ┌ (start) create :article\n|  |  ┌ (start) create :user\n|  |  |  (0.1ms)  begin transaction\n|  |  |  (0.3ms)  INSERT INTO \"users\" (\"name\", \"username\") VALUES (?, ?)  [[\"name\", \"Peter Parker\"], [\"username\", \"spiderman\"]]\n|  |  |  (1.8ms)  commit transaction\n|  |  └ (finish) create :user [0.007s]\n|  |  (0.1ms)  begin transaction\n|  |  (0.2ms)  INSERT INTO \"articles\" (\"title\", \"content\", \"user_id\") VALUES (?, ?, ?)  [[\"title\", \"New Article\"], [\"content\", \"article content\"], [\"user_id\", \"121\"]]\n|  |  (1.5ms)  commit transaction\n|  └ (finish) create :article [0.021s]\n|  (0.1ms)  begin transaction\n|  (0.2ms)  INSERT INTO \"comments\" (\"content\", \"user_id\", \"article_id\") VALUES (?, ?, ?)  [[\"content\", \"First!\"], [\"user_id\", \"120\"], [\"article_id\", \"61\"]]\n|  (1.5ms)  commit transaction\n└ (finish) create :comment [0.046s]\n```\n\nTo trace without SQL logs, use the following:\n\n``` ruby\nFactoryBot.trace(sql: false) do\n  FactoryBot.create(:comment)\nend\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then,\nrun `rake spec` to run the tests. You can also run `bin/console` for an\ninteractive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`.\nTo release a new version, update the version number in `version.rb`, and then\nrun `bundle exec rake release`, which will create a git tag for the version,\npush git commits and tags, and push the `.gem` file\nto [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at\nhttps://github.com/shiroyasha/factory_girl_instruments. This project is intended\nto be a safe, welcoming space for collaboration, and contributors are expected\nto adhere to the [Contributor Covenant](http://contributor-covenant.org) code\nof conduct.\n\n## License\n\nThe gem is available as open source under the terms of\nthe [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshiroyasha%2Ffactory_bot_instruments","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshiroyasha%2Ffactory_bot_instruments","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshiroyasha%2Ffactory_bot_instruments/lists"}