{"id":13880500,"url":"https://github.com/stephencelis/minifacture","last_synced_at":"2025-03-16T17:35:19.746Z","repository":{"id":782550,"uuid":"475083","full_name":"stephencelis/minifacture","owner":"stephencelis","description":"factory_girl for minitest","archived":false,"fork":false,"pushed_at":"2015-07-07T20:06:29.000Z","size":230,"stargazers_count":69,"open_issues_count":1,"forks_count":10,"subscribers_count":4,"default_branch":"gem","last_synced_at":"2025-02-24T10:49:34.578Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://gist.github.com/273579","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/stephencelis.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-01-16T16:58:57.000Z","updated_at":"2022-05-11T12:37:07.000Z","dependencies_parsed_at":"2022-07-14T18:47:06.307Z","dependency_job_id":null,"html_url":"https://github.com/stephencelis/minifacture","commit_stats":null,"previous_names":["stephencelis/miniskirt"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephencelis%2Fminifacture","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephencelis%2Fminifacture/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephencelis%2Fminifacture/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephencelis%2Fminifacture/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stephencelis","download_url":"https://codeload.github.com/stephencelis/minifacture/tar.gz/refs/heads/gem","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243823367,"owners_count":20353658,"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":[],"created_at":"2024-08-06T08:03:05.176Z","updated_at":"2025-03-16T17:35:19.415Z","avatar_url":"https://github.com/stephencelis.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# Minifacture\n\n[factory_girl][1] for [minitest][2].\n\n[1]: https://github.com/thoughtbot/factory_girl\n[2]: https://github.com/seattlerb/minitest\n\n``` ruby\nFactory.define :user do |f|\n  f.name 'John Doe'                            # String.\n  f.login 'john%d'                             # Sequence.\n  f.email '%{login}@example.com'               # Interpolate.\n  f.password f.password_confirmation('foobar') # Chain.\n  f.active { [true,false].sample }             # Block.\n  f.status { |f| f.active ? \"On\" : \"Off\" }     # Block with object parameter.\nend\n\nFactory.define :post do |f|\n  f.user { Factory :user }                     # Association.\nend\n```\n\n\n## Install\n\n``` ruby\n# Gemfile\ngroup :test do\n  gem 'minifacture'\nend\n```\n\n``` sh\n$ bundle\n```\n\n``` ruby\n# test/test_helper.rb\nrequire 'factories' # If you define your factories in test/factories.rb\n```\n\n\n## Use\n\nTo get a `User` instance that's not saved:\n\n``` ruby\nu = Factory.build :user\n```\n\nTo get a `User` instance that's saved:\n\n``` ruby\nu = Factory.create :user\n```\n\nShorthand for create:\n\n``` ruby\nu = Factory :user\n```\n\n\n### Methods\n\nMethods can customize a factory's object as it is being built.\n\nTake a simple class:\n\n``` ruby\nclass User\n  attr_accessor :name\n  attr_accessor :email\nend\n```\n\nAnd a simple factory:\n\n``` ruby\nFactory.define :user do\nend\n```\n\nUse:\n\n``` ruby\nu = Factory :user, name: 'Alice', email: 'alice@example.com'\nu.name  # =\u003e \"Alice\"\nu.email # =\u003e \"alice@example.com\"\n```\n\nThis initializes the object, then calls the object's `name=` method and\n`email=` method.\n\n\n### Blocks\n\nBlocks can use any Ruby code:\n\n``` ruby\nFactory.define :user do |f|\n  f.name { %w[Alice Bob Carol].sample }\n  f.email { \"#{%w[alice bob carol].sample}@example.com\" }\nend\n```\n\nUse:\n\n``` ruby\nu = Factory :user\nu.name  # =\u003e \"Bob\"\nu.email # =\u003e \"carol@example.com\"\n```\n\nBlocks can use a parameter to access the object as it is being built:\n\n``` ruby\nFactory.define :user do |f|\n  f.name { %w[Alice Bob Carol].choice }\n  f.email { |u| \"#{u.name.downcase}@example.com\" }\nend\n```\n\nUse:\n\n``` ruby\nu = Factory :user\nu.name  # =\u003e \"Bob\"\nu.email # =\u003e \"bob@example.com\"\n```\n\n\n### Methods + Blocks\n\nWhen you use methods and blocks together, the methods are called, then the\nblocks:\n\n``` ruby\nuser = Factory :user, name: 'Eve'\nuser.name  # =\u003e \"Eve\"\nuser.email # =\u003e \"eve@example.com\"\n```\n\nThis initializes the object, then calls the object's `name=` method, then\nprocesses the factory attribute `email` which calls the block.\n\n\n### Namespacing\n\nIf your model is namespaced, or does not correspond directly with the symbol,\nyou can explicitly declare which class to use:\n\n```ruby\nFactory.define :post, class: BlogEngine::Post do\n  # ...\nend\n```\n\n### Parent\n\nA factory can use a parent factory:\n\n```ruby\nFactory.define :user, do |f|\n  f.name \"Alice\"\nend\n\nFactory.define :admin, :parent =\u003e :user do |f|\n  f.role \"Administrator\"\nend\n```\n\nWhen you use the factory, the result combines the parent factory settings:\n\n```ruby\nFactory :admin\n=\u003e User with name=\"Alice\" and role=\"Administrator\"\n```\n\nThe factory can overwrite the parent attributes:\n\n```ruby\nFactory.define :user, do |f|\n  f.name \"Alice\"\n  f.role \"Guest\"\nend\n\nFactory.define :admin, :parent =\u003e :user do |f|\n  f.role \"Administrator\"  # Replaces the parent factory role\nend\n```\n\n\n## License\n\n(The MIT License)\n\n© 2010–2014 Stephen Celis \u003cstephen@stephencelis.com\u003e.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephencelis%2Fminifacture","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstephencelis%2Fminifacture","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephencelis%2Fminifacture/lists"}