{"id":15459180,"url":"https://github.com/andriy-baran/rspec_request_helpers","last_synced_at":"2025-08-13T21:42:07.612Z","repository":{"id":32652507,"uuid":"138601905","full_name":"andriy-baran/rspec_request_helpers","owner":"andriy-baran","description":"A set of helpers for testing with RSpec","archived":false,"fork":false,"pushed_at":"2023-01-20T04:19:29.000Z","size":54,"stargazers_count":4,"open_issues_count":9,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-18T19:32:37.301Z","etag":null,"topics":["dsl","hacktoberfest","rails","rspec","ruby","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/andriy-baran.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-25T13:54:21.000Z","updated_at":"2022-11-21T16:52:31.000Z","dependencies_parsed_at":"2023-02-11T23:35:19.081Z","dependency_job_id":null,"html_url":"https://github.com/andriy-baran/rspec_request_helpers","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andriy-baran%2Frspec_request_helpers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andriy-baran%2Frspec_request_helpers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andriy-baran%2Frspec_request_helpers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andriy-baran%2Frspec_request_helpers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andriy-baran","download_url":"https://codeload.github.com/andriy-baran/rspec_request_helpers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235285115,"owners_count":18965279,"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":["dsl","hacktoberfest","rails","rspec","ruby","testing"],"created_at":"2024-10-01T23:05:16.970Z","updated_at":"2025-01-24T22:57:59.309Z","avatar_url":"https://github.com/andriy-baran.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rspec Request Helpers\n\nThis gem provides few helpers for request testing\n\nThis rules were influenced by real projects experience so\nIn order to use it for your `rspec/requests` specs you need to follow convention\n\n```ruby\n  RSpec.describe 'Some API' do\n    path { '/api/v1/posts' }\n    headers do\n      {\n        'Content-Type' =\u003e 'application/json',\n        'Accept' =\u003e 'application/json',\n        'X-App-Token' =\u003e user.api_key\n      }\n    end\n    params do\n      {\n        name: name,\n        description: description,\n        author_id: author_id\n      }\n    end\n    response do\n      { id: 123, name: name, description: description, author: 'Bob Poster' }\n    end\n\n    it `creates post` do\n      # Ex. do_post_and_assert_201_json_parsed\n    end\n  end\n```\n\nSo what you'll got for that? - Few handy methods for the testing routine\n\n| Action | Meaning | RSpec Example |\n|---|---|---|\n| `do_get`, `do_post`, `do_put`, `do_delete`, `do_patch` | Sends apropriate request to endpoint with valid params and headers | `get(path, params, headers)` |\n| `assert_201_json`, `assert_404_xml`, `assert_422_json` etc | Assert response status code and mime type (Dynamicly generated based on config ) | `expect(response).to have_http_status(status)`\u003cbr\u003e`expect(response.content_type).to eq mime_type` |\n| `assert_200_json_raw`, `assert_201_json_hash`, `assert_201_json_object` | Same as above plus check against raw, hash or object presentation of response | `expect(response_body).to eq(expected_response)`\n| `do_post_and_assert_201_json_parsed` | Shorthand for asserting content type, HTTP status code and if parsed body of the response is equal to | `expect(response_hash).to eq(expected_response)` |\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'rspec_request_helpers'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install rspec_request_helpers\n\nIn project directory run\n\n    $ rails g rspec_request_helpers:install\n\n## Configuration\n\nInclude helpers into RSpec\n\n```ruby\n# spec/rails_helper.rb\n\nRSpec.configure do |config|\n  config.include RspecRequestHelpers\n\n  # This will tell RSpec to collect all failures in test example\n  config.define_derived_metadata do |meta|\n    meta[:aggregate_failures] = true if meta[:type] == :request\n  end\nend\n```\n\nCreate file `config/initializers/rspec_request_helpers.rb`\n\n```ruby\nRspecRequestHelpers.configure do |config|\n  # Supporded content types\n  config.content_types = { json: 'application/json' }\n\n  # Supported status codes\n  config.status_codes  = [404, 401, 422, 200, 201]\nend\n```\n## Usage\n\n### Generate new rspec file for API endpoint\n\n    $ rails g rspec:endpoint \u003caction name\u003e\n\n    Example:\n\n    $ rails g rspec:endpoint api/v1/users/show\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/andriy-baran/rspec_request_helpers. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the RspecRequestHelpers project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/andriy-baran/rspec_request_helpers/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandriy-baran%2Frspec_request_helpers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandriy-baran%2Frspec_request_helpers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandriy-baran%2Frspec_request_helpers/lists"}