jsonapi-rspec

RSpec matchers for JSON API.

Status

Gem Version Build Status Gitter chat

Resources

Installation

Add the following to your application’s Gemfile:

“by gem ‘jsonapi-rspec’

“nd then execute:

“ bundle

Add to your spec/spec_helpers.rb:

“by

spec/spec_helpers.rb

RSpec.configure do |config| # … config.include JSONAPI::RSpec end

Usage and documentation

Available matchers:

  • expect(document['data']).to have_id('12')
  • expect(document['data']).to have_type('users')
  • expect(document['data']).to have_attributes(:name, :email)
  • expect(document['data']).to have_attribute(:name).with_value('Lucas')
  • expect(document['data']).to have_relationships(:posts, :comments)
  • expect(document['data']).to have_relationship(:posts).with_data([{ 'id' => '1', 'type' => 'posts' }])
  • expect(document['data']['relationships']['posts']).to have_links(:self, :related)
  • expect(document['data']).to have_link(:self).with_value('http://api.example.com/users/12')
  • expect(document).to have_meta
  • expect(document).to have_meta('foo' => 'bar')
  • expect(document).to have_jsonapi_object
  • expect(document).to have_jsonapi_object('version' => '1.0')

Advanced examples

Checking for an included resource:

“by expect(response_body[included]) .to include(have_type(‘posts’).and have_id(‘1’))

License

jsonapi-rspec is released under the MIT License.