{"id":13463373,"url":"https://github.com/markburns/to_factory","last_synced_at":"2025-12-17T14:32:21.847Z","repository":{"id":137244157,"uuid":"2238290","full_name":"markburns/to_factory","owner":"markburns","description":"Auto generate factories from data","archived":false,"fork":false,"pushed_at":"2022-12-31T09:19:20.000Z","size":269,"stargazers_count":113,"open_issues_count":1,"forks_count":17,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-25T06:33:55.666Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/markburns.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2011-08-20T08:43:34.000Z","updated_at":"2023-05-05T16:28:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"a668a915-d457-4b20-af57-77c28464a99c","html_url":"https://github.com/markburns/to_factory","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/markburns/to_factory","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markburns%2Fto_factory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markburns%2Fto_factory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markburns%2Fto_factory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markburns%2Fto_factory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markburns","download_url":"https://codeload.github.com/markburns/to_factory/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markburns%2Fto_factory/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27783730,"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-12-17T02:00:08.291Z","response_time":55,"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":[],"created_at":"2024-07-31T13:00:52.246Z","updated_at":"2025-12-17T14:32:21.812Z","avatar_url":"https://github.com/markburns.png","language":"Ruby","readme":"ToFactory :wrench:\n=========\n\n[![Maintainability](https://api.codeclimate.com/v1/badges/34f4377c5b911bcb4433/maintainability)](https://codeclimate.com/github/markburns/to_factory/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/34f4377c5b911bcb4433/test_coverage)](https://codeclimate.com/github/markburns/to_factory/test_coverage)\n[![Gem Version](http://img.shields.io/gem/v/to_factory.svg)](https://rubygems.org/gems/to_factory)\n[![License](http://img.shields.io/:license-mit-blue.svg)](http://markburns.mit-license.org)\n\nEasily add factories with valid data for an existing project.\n\nIf you find yourself retro-fitting tests this gem will save you some of the legwork.\n\n* auto-generate all factories\n* adhoc generate from existing records\n* unintrusively update factory files in place\n* display factory definition for a record\n* parse and write `FactoryBot` syntax\n\nTested against Ruby 1.8.7, 1.9.2, 1.9.3, 2.0.0,  2.1.x, 2.2.x\n\n## Warning :warning:\n`ToFactory` writes into the `spec/factories` folder. Whilst it\nis tested and avoids overwriting existing factories,\nit is recommended that you execute after committing or when in a known\nsafe state.\n\n\n\n\n## Installation :file_folder:\n\n```ruby\n\n#Gemfile\n#add to whichever environments you want to generate data from\ngroup :test, :development do\n  gem 'to_factory'\nend\n```\n\n\n```bash\ngit add spec/factories\ngit commit -m \"I know what I am doing\"\nrails c\n\u003eToFactory()\n```\n## Example :computer:\n\n```ruby\n#Generate all factories\nToFactory()\n#outputs the first record of each ActiveRecord::Base subclass in the models folder\n#to spec/factories\n\n#Choose input/output directories\nToFactory.models    = \"models/this/subfolder/only\" #default \"./app/models\"\nToFactory.factories = \"spec/support/factories\"     #default \"./spec/factories\"\nToFactory()\n\n#Exclude classes\nToFactory(exclude: [User, Project])\n\n#Use Adhoc instances from the console\nToFactory User.last\n\n#writes to spec/factories/user.rb\nFactoryBot.define\n  factory(:user) do |u|\n    email \"test@example.com\"\n    name \"Mike\"\n  end\nend\n\n#List defined factory names\nToFactory.definitions\n#=\u003e [:user, :admin, :project]\n\n#Display definition from record\nToFactory.definition_for @user\n\n#Display existing definition from name\nToFactory.definition_for :admin\n\n#doesn't overwrite existing factories\nToFactory User.last\n#Exception =\u003e\n#ToFactory::AlreadyExists: an item for each of the following keys :user already exists\n\n#Choose specific name\nToFactory :admin =\u003e User.last\n#appends to spec/factories/user.rb\n\n```\n\n### Other useful projects\n\nIf you are adding specs to an existing project you may want to look at:\n\n* [rspec-kickstarter](https://github.com/seratch/rspec-kickstarter) (auto generate specs)\n* [rspec-kickstarter-vintage](https://github.com/ifad/rspec-kickstarter-vintage) (for Ruby 1.8/Rspec 1.x)\n* [hash_syntax](https://github.com/michaeledgar/hash_syntax) (convert 1.8 syntax to 1.9 and vice-versa)\n* [transpec](https://github.com/yujinakayama/transpec) (convert old rspec syntax to new expect syntax)\n\n","funding_links":[],"categories":["Testing","Ruby"],"sub_categories":["Rails Fixture Replacement"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkburns%2Fto_factory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkburns%2Fto_factory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkburns%2Fto_factory/lists"}