{"id":13880279,"url":"https://github.com/calebhearth/formulaic","last_synced_at":"2025-04-04T09:10:02.624Z","repository":{"id":9076955,"uuid":"10849992","full_name":"calebhearth/formulaic","owner":"calebhearth","description":"Simplify form filling with Capybara","archived":false,"fork":false,"pushed_at":"2024-05-21T22:32:05.000Z","size":131,"stargazers_count":552,"open_issues_count":8,"forks_count":29,"subscribers_count":38,"default_branch":"main","last_synced_at":"2024-10-30T03:41:28.164Z","etag":null,"topics":["now","rails","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/calebhearth.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","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},"funding":{"github":"calebhearth","ko_fi":"calebhearth"}},"created_at":"2013-06-21T18:54:58.000Z","updated_at":"2024-08-26T16:24:35.000Z","dependencies_parsed_at":"2022-09-10T18:40:42.522Z","dependency_job_id":"29b85075-45e0-4c53-9e1d-b2bfd42bd1a3","html_url":"https://github.com/calebhearth/formulaic","commit_stats":{"total_commits":92,"total_committers":26,"mean_commits":"3.5384615384615383","dds":0.4347826086956522,"last_synced_commit":"3a59c2683a35af60479a7d42744c34f2ad435ecd"},"previous_names":["thoughtbot/formulaic"],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calebhearth%2Fformulaic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calebhearth%2Fformulaic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calebhearth%2Fformulaic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calebhearth%2Fformulaic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/calebhearth","download_url":"https://codeload.github.com/calebhearth/formulaic/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247149505,"owners_count":20891954,"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":["now","rails","testing"],"created_at":"2024-08-06T08:02:54.677Z","updated_at":"2025-04-04T09:10:02.602Z","avatar_url":"https://github.com/calebhearth.png","language":"Ruby","readme":"# Formulaic\n\n[![Build Status](https://travis-ci.org/calebhearth/formulaic.png?branch=master)](https://travis-ci.org/calebhearth/formulaic)\n[![Code Climate](https://codeclimate.com/github/calebhearth/formulaic.png)](https://codeclimate.com/github/calebhearth/formulaic)\n\nRemove the tedium of formulaic form filling with Capybara.\n\nFormulaic allows you to specify a hash of attributes to be input rather than\nprocedurally calling Capybara’s DSL methods.\n\n## Usage\n```ruby\n  gem 'formulaic', group: :test\n```\n\n```ruby\nfeature 'New user registration' do\n  scenario 'successfull sign up' do\n    visit sign_in_path\n\n    fill_form(:user, { name: 'Caleb', email: 'caleb@thoughtbot.com', 'Terms of Service' =\u003e true })\n    click_on submit(:user)\n\n    expect(page).to have_content t('user.create.success')\n  end\nend\n```\n\n\n### `fill_form`\n\n```ruby\nfill_form(model_name, :new, attributes)\n```\n\n`fill_form` provides an interface to completely filling out a form. Provide the\n`model_name` as a symbol and `attributes` as a hash of\n`column name =\u003e database value` or `label string =\u003e database value`.\n\nIf an `attributes` key is a `String`, it will be used as the literal label.\nFor `Symbol` we will attempt to translate, fall back to `human_attribute_name`\nif available, then call `to_s`.\n\n### `input`\n\n```ruby\ninput(model_name, field)\n```\n\n`input` gives an easy way to find the translated text of an input. It is\nprimarily used internally to fill `\u003cinput\u003e`s, but is provided in the public API\nas it could be useful.\n\n### `submit`\n\n```ruby\nsubmit(model_name, :create)\n```\n\n`submit` functions like [`input`](#input), but finds the translation for the\nsubmit button of the form. `model_name` should be the same as what you provide\nto [`fill_form`](#fill\\_form). Typically, the return value of `submit` will be\npassed directly to Capybara’s `click_on` method.\n\nIf you are submitting a form that is not for the `create` action, you may need\nto pass the action:\n\n```ruby\nsubmit(:user, :update)\n```\n\nThe `model_name` and `action` should match up to the\n`helpers.submit.\u003cmodel_name\u003e.\u003caction\u003e` translations.\n\n### `fill_form_and_submit`\n\n```ruby\nfill_form_and_submit(:user, :new, attributes)\n```\n\nEffectively a `fill_form` followed by `click_on submit`, but smart enough to\n`fill_form` with `:new` and `submit` with `:create` and the edit/update cousin.\n\n### Nested Forms\n\nIf you have nested forms, through `fields_for` (or any variant), you are able to\nfill them with an extra call to `fill_form`.\n\n```ruby\nfill_form(main_model_name, main_model_attributes)\nfill_form(nested_model_name, nested_model_attributes)\n```\n\n### Integration with RSpec:\n\n```ruby\n# spec/spec_helper.rb\n\nRSpec.configure do |config|\n  config.include Formulaic::Dsl, type: :feature\nend\n```\n\n### Integration with Minitest or Test::Unit:\n\n```ruby\n# test/test_helper.rb\n\nclass ActionDispatch::IntegrationTest\n  include Capybara::DSL\n  include Formulaic::Dsl\nend\n```\n\n### Integration with [Factory Bot](https://github.com/thoughtbot/factory_bot)\n\n```ruby\nfill_form(:user, attributes_for(:user))\n```\n\nYou may have attributes included in your `User` factory that don’t pertain to\nsign up:\n\n```ruby\nfill_form(:user, attributes_for(:user).slice(*sign_up_attributes))\n\n# ...\ndef sign_up_attributes\n  [:name, :email, :terms_of_service]\nend\n```\n\n### Integration with [Capybara::TestHelper](https://github.com/ElMassimo/capybara_test_helpers)\n\n```ruby\nclass BaseTestHelper \u003c Capybara::TestHelper\n  include Formulaic::Dsl\nend\n```\n\nor alternatively delegate the needed methods:\n\n```ruby\nclass FormTestHelper \u003c BaseTestHelper\n  delegate_to_test_context(:fill_form, :input, :submit, :fill_form_and_submit)\nend\n```\n\n## Assumptions\n\nFormulaic relies pretty heavily on the assumption that your application is using\ntranslations for SimpleForm and input helpers, using the\n`simple_form.labels.\u003cmodel\u003e.\u003cattribute\u003e` and `helpers.submit.\u003cmodel\u003e.\u003caction\u003e`\nconventions.\n\nYou can still use Formulaic by using strings as keys instead of symbols, which\nit knows to pass directly to `fill_in` rather than trying to find a translation.\nYou’ll need to find submit buttons yourself since `submit` is a thin wrapper\naround `I18n.t`.\n\nFormulaic assumes your forms don't use AJAX, setting the wait time to 0. This can be configured using:\n```ruby\nFormulaic.default_wait_time = 5\n```\n\n## Known Limitations\n\n* Formulaic currently supports the following mappings from the `#class` of the\n  attribute values to Capybara method calls:\n\n  | Classes                               | Formulaic’s action               |\n  | --------------------------------------|----------------------------------|\n  | `String`                              | `fill_in`, `choose`, or `select` |\n  | `Date`, `ActiveSupport::TimeWithZone` | `select` year, month, and day    |\n  | `TrueClass`                           | `check`                          |\n  | `FalseClass`                          | `uncheck`                        |\n  | `Array`                               | `check` or `select` each array member, which should all be strings. If not all items can be selected or checked, an error will be thrown.|\n  | `File`                                | `attach_file` with `File#path`   |\n\n* Formulaic is currently tied to `simple_form` translations and field structure.\n  If you pass a string for the attribute, we’ll try to fill the input that\n  relates to that label. We would be happy to work with you to add support for\n  other form builders.\n* Formulaic currently does not support forms with duplicate labels, as it is\n  designed to be as similar as possible to a user completing a form—it looks at\n  the labels to determine where to fill what data.\n* Formulaic can’t figure out how to fill fields with HTML labels:\n  `page.fill_in('\u003cstrong\u003eText\u003c/strong\u003e here', with: 'something')` doesn’t work\n  with Capybara. The usual workaround is to pass a CSS selector (which you can\n  do by passing a string as the attribute key).\n* Formulaic can't handle multiple file attachments on the same input.\n\n## About\n\nFormulaic is maintained by [Caleb Hearth][caleb] and formerly thoughtbot with\nthe help of community [contributors]. Thank you!\n\n[caleb]: http://github.com/calebhearth\n[contributors]: http://github.com/thoughtbot/calebhearth/contributors\n","funding_links":["https://github.com/sponsors/calebhearth","https://ko-fi.com/calebhearth"],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcalebhearth%2Fformulaic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcalebhearth%2Fformulaic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcalebhearth%2Fformulaic/lists"}