{"id":15759303,"url":"https://github.com/midwire/jsonapi_rspec","last_synced_at":"2026-05-05T18:32:02.006Z","repository":{"id":26048589,"uuid":"107196789","full_name":"midwire/jsonapi_rspec","owner":"midwire","description":"Provides RSpec matcher for json:api related specs and compares jsonapi rack response to instantiated objects.","archived":false,"fork":false,"pushed_at":"2024-02-20T18:11:47.000Z","size":42,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-04T05:15:41.230Z","etag":null,"topics":["json","json-api","jsonapi","jsonapi-expectations","jsonapi-rb","jsonapi-rspec","jsonapi-testing","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/midwire.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-17T00:14:02.000Z","updated_at":"2024-02-20T17:01:24.000Z","dependencies_parsed_at":"2024-10-31T00:47:19.000Z","dependency_job_id":null,"html_url":"https://github.com/midwire/jsonapi_rspec","commit_stats":{"total_commits":25,"total_committers":3,"mean_commits":8.333333333333334,"dds":"0.19999999999999996","last_synced_commit":"0ea234964c939dc86f5d858aaade95faea7a35ae"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/midwire/jsonapi_rspec","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midwire%2Fjsonapi_rspec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midwire%2Fjsonapi_rspec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midwire%2Fjsonapi_rspec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midwire%2Fjsonapi_rspec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/midwire","download_url":"https://codeload.github.com/midwire/jsonapi_rspec/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midwire%2Fjsonapi_rspec/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32662855,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-05T11:29:49.557Z","status":"ssl_error","status_checked_at":"2026-05-05T11:29:48.587Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["json","json-api","jsonapi","jsonapi-expectations","jsonapi-rb","jsonapi-rspec","jsonapi-testing","rspec"],"created_at":"2024-10-04T10:04:38.876Z","updated_at":"2026-05-05T18:32:01.988Z","avatar_url":"https://github.com/midwire.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JsonapiRspec\n\n[![Gem Version](https://badge.fury.io/rb/jsonapi_rspec.svg)](https://badge.fury.io/rb/jsonapi_rspec)\n[![Build Status](https://travis-ci.org/midwire/jsonapi_rspec.svg?branch=master)](https://travis-ci.org/midwire/jsonapi_rspec)\n\nMatch json:api formatted Rack::Response (or Rails controller response) to an instantiated object or ActiveRecord/ActiveModel object.\n\nThis project started because I wanted to be able to easily compare a json:api response to a model in my Rails API controllers, across several projects. Finding myself copying the code between projects, I decided to put it all in a gem.\n\nAs such, it may not strictly suit your needs, but if you let me know I'll do my best to accommodate, and [pull requests](https://github.com/midwire/jsonapi_rspec/pulls) are always welcome.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngroup :test do\n  gem 'jsonapi_rspec'\nend\n```\n\nAnd then execute:\n\n    $ bundle\n\n## Usage\n\nIn your controller specs:\n\n```ruby\ndescribe 'GET index' do\n  before do\n    get :index\n  end\n\n  it 'returns a json:api response' do\n    expect(response).to be_jsonapi_response\n  end\nend\n```\n\n```ruby\ndescribe 'POST create' do\n  context 'with valid content data' do\n    it 'responds with valid json' do\n      post :create, params: valid_params\n      expect(response).to be_jsonapi_response_for(Content.last)\n    end\n  end\nend\n```\n\nIt currently tests for compliant json:api sections and matching attributes for the passed model instance.\n```\n{\n  \"jsonapi\": \"version 1.1\", // does not check\n  \"data\":{                  // checks if exists and is a hash\n    \"id\":\"123\",             // checks if this matches the object.id\n    \"type\":\"tags\",          // checks if exists and is the matching type for object\n    \"attributes\":{          // checks each attr. against object attributes\n      \"string_attribute\":\"Category\",\n      \"datetime_attribute\":\"2017-10-13T19:33:54+00:00\",\n      \"time_attribute\":\"2017-10-14 17:12:45 -0500\",\n      \"true_attribute\":true,\n      \"false_attribute\":false,\n      \"nil_attribute\":null,\n      \"fixnum_attribute\":11,\n      \"float_attribute\":11.11,\n      \"bignum_attribute\":9999999999999999999999999999999,\n      \"links\":{             // does not check\n        \"self\":\"http://test.host/api/v1/tag_types.123\"\n      }\n    }\n  },\n  \"included\": [{            // does not check\n    \"type\": \"users\",\n    \"id\": 9,\n    \"attributes\": {\n      \"first-name\": \"Dan\",\n      \"last-name\": \"Gebhardt\",\n      \"twitter\": \"dgeb\"\n    },\n    \"links\": {\n      \"self\": \"http://example.com/users/9\"\n    }\n  }],\n  \"meta\":{                  // checks are configurable\n    \"copyright\":\"Copyright 2017 Chris Blackburn\",\n    \"version\":\"v1\"\n  }\n}\n```\n\n### Checks\n\n* Empty response - `response.empty?`\n* Nil response - `response.nil?`\n* Error response - catches if the response is an error when expecting a matching object response.\n* Missing a required top level section - must include 'data', 'errors' or 'meta'\n* Conflicting top level section - 'included' is invalid without a 'data' section\n* Unexpected top level key - catches invalid top level keys\n* Invalid data section - 'data' section must be an Array (collection) or Hash (single-object)\n* Data type mismatch - 'data:type' doesn't match the object type\n* Object ID mismatch - 'data:id' doesn't match the object ID\n* Missing meta - if configured (see Configuration below) reports missing 'meta' section\n* Validates data attributes - checks for matching data attributes including their variable types. For example if an Integer is expected, a String fails.\n\n### Possible Failure Messages\n\n[See failure_messages.rb](https://github.com/midwire/jsonapi_rspec/blob/develop/lib/jsonapi_rspec/failure_messages.rb).\n\n[See the specs](https://github.com/midwire/jsonapi_rspec/blob/develop/spec/lib/jsonapi_rspec/be_json_api_response_for_spec.rb) for more details.\n\n### Configuration\n\nThis is the only configuration option at the moment:\n\n    JsonapiRspec.configure do |config|\n      config.meta_required = false # default\n    end\n\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/midwire/jsonapi_rspec.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmidwire%2Fjsonapi_rspec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmidwire%2Fjsonapi_rspec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmidwire%2Fjsonapi_rspec/lists"}