{"id":13778151,"url":"https://github.com/davydovanton/rspec-hanami","last_synced_at":"2025-04-12T03:30:54.903Z","repository":{"id":56892876,"uuid":"59657468","full_name":"davydovanton/rspec-hanami","owner":"davydovanton","description":"RSpec Matchers for Hanami","archived":false,"fork":false,"pushed_at":"2020-10-10T20:23:18.000Z","size":57,"stargazers_count":46,"open_issues_count":7,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-25T23:15:08.229Z","etag":null,"topics":["hanami","matchers","rspec"],"latest_commit_sha":null,"homepage":null,"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/davydovanton.png","metadata":{"files":{"readme":"README.md","changelog":"Changes.md","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}},"created_at":"2016-05-25T11:27:33.000Z","updated_at":"2023-01-01T00:44:38.000Z","dependencies_parsed_at":"2022-08-21T01:20:46.586Z","dependency_job_id":null,"html_url":"https://github.com/davydovanton/rspec-hanami","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davydovanton%2Frspec-hanami","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davydovanton%2Frspec-hanami/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davydovanton%2Frspec-hanami/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davydovanton%2Frspec-hanami/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davydovanton","download_url":"https://codeload.github.com/davydovanton/rspec-hanami/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248512485,"owners_count":21116612,"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":["hanami","matchers","rspec"],"created_at":"2024-08-03T18:00:51.620Z","updated_at":"2025-04-12T03:30:54.617Z","avatar_url":"https://github.com/davydovanton.png","language":"Ruby","funding_links":[],"categories":["Hanami Gem List"],"sub_categories":["Testing"],"readme":"# RSpec::Hanami\n\n[![Build Status](https://travis-ci.org/davydovanton/rspec-hanami.svg?branch=master)](https://travis-ci.org/davydovanton/rspec-hanami) [![Coverage Status](https://coveralls.io/repos/github/davydovanton/rspec-hanami/badge.svg?branch=master)](https://coveralls.io/github/davydovanton/rspec-hanami?branch=master)\n\n**rspec-hanami** is a testing framework for [hanami](http://hanamirb.org)\n\n## Installation\nAdd this line to your application's Gemfile:\n\n```ruby\ngroup :test do\n  gem 'rspec-hanami'\nend\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install rspec-hanami\n\nAfter that require gem to `spec_helper.rb` and include matchers to rspec:\n\n```ruby\nrequire 'rspec/hanami'\n\nRSpec.configure do |config|\n  config.include RSpec::Hanami::Matchers\n\n  # ...\nend\n```\n\n### Capybara\nCheck your `spec/features_helper.rb` and `spec/support/Capybara.rb` files. If you find something like this:\n\n```ruby\nCapybara.app = Hanami::Container.new\n# or\nCapybara.app = Hanami::App.new\n```\n\nPlease change this line to:\n```ruby\nCapybara.app = ::Hanami::Container.new\n# or\nCapybara.app = ::Hanami::App.new\n```\n\nFor more information see [this issue](https://github.com/davydovanton/rspec-hanami/issues/1)\n\n## Supported matchers\n### Request helpers\nYou can use familiar request helpers like `#get`, `#post`, etc.\nThese methods make full hanami app request and return env (array with 3 elements).\n\nFor using these helpers include `RSpec::Hanami::RequestHelpers` to your `spec_helper.rb` file:\n\n```ruby\nconfig.include RSpec::Hanami::RequestHelpers\n```\n\nAfter that you can call any method:\n```ruby\nit { expect(get('/')).to be_success }\nit { expect(post('/tasks')).to redirect_to('/tasks') }\n```\n\n### Controller Specs\n#### `have_http_status`\nPasses if `response` has a matching HTTP status code.\n\nThe following symbolic status codes are allowed:\n  - `:error`\n  - `:missing`\n  - `:redirect`\n  - `:success`\n  - `Rack::Utils::SYMBOL_TO_STATUS_CODE`\n\n``` ruby\nresponse = action.call(params)\nexpect(response).to have_http_status(404)\nexpect(response).to have_http_status(:created)\nexpect(response).to have_http_status(:success)\nexpect(response).to have_http_status(:error)\nexpect(response).to have_http_status(:missing)\nexpect(response).to have_http_status(:redirect)\n```\n\n#### `be_success`\nPasses if `response` has a not 4xx and 5xx error code.\n\n``` ruby\nresponse = action.call(params)\nexpect(response).to be_success\n````\n\n#### `redirect_to`\nPasses if `response` has a redirect to special url\n\n``` ruby\nresponse = action.call(params)\nexpect(response).to redirect_to('site.com')\n```\n\n#### `match_in_body`\nPasses if `body` matches with argument\n\n``` ruby\nresponse = action.call(params)\nexpect(response).to match_in_body('Tittle')\nexpect(response).to match_in_body(/Tittle\\s\\d+/)\n```\n\n#### `include_json`\nPasses if `json` string in the body matches with hash arg\n\n``` ruby\nresponse = action.call(params)\nexpect(response).to include_json(name: 'Anton')\nexpect(response).to include_json(user: { name: 'Anton })\n```\n\n### Views Specs\n#### `have_form_action`\nPasses if form object has an action\n\n``` ruby\nexpect(view.form).to     have_form_action('/users')\nexpect(view.form).to_not have_form_action('/books')\n```\n\n#### `have_method`\nPasses if form object has a method\n\n``` ruby\nexpect(view.form).to     have_method('POST')\nexpect(view.form).to     have_method(:post)\nexpect(view.form).to_not have_method(:put)\n```\n\n#### `have_form_field`\nPasses if form object has a field with wanted params\n\n``` ruby\nexpect(view.form).to have_form_field(node: 'input', type: 'text', id: 'user-first-name')\n```\n\n### Entity specs\nPasses if argument type has a matching with type.\nYou can use `Hanami::Entity::Types` for compare.\n\n#### `have_attribute`\nPasses if `:name` has `Types::String` type:\n\n``` ruby\nit { expect(User).to have_attribute(:name, Types::String) }\n```\n\n#### `have_attributes`\nPasses if `:name` has `Types::String` type and `:age` has `Types::Int` type:\n\n``` ruby\nit { expect(User).to have_attributes(name: Types::String, age: Types::Int) }\n```\n\n## Also see\n\n* \u003chttps://github.com/rspec/rspec\u003e\n* \u003chttps://github.com/rspec/rspec-core\u003e\n* \u003chttps://github.com/rspec/rspec-expectations\u003e\n* \u003chttps://github.com/rspec/rspec-mocks\u003e\n\n## Feature Requests \u0026 Bugs\n\nSee \u003chttp://github.com/davydovanton/rspec-hanami/issues\u003e\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavydovanton%2Frspec-hanami","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavydovanton%2Frspec-hanami","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavydovanton%2Frspec-hanami/lists"}