11# jsonapi-rspec
2-
32RSpec matchers for [ JSON API] ( http://jsonapi.org ) .
43
54## Resources
6-
75* Chat: [ gitter] ( http://gitter.im/jsonapi-rb )
86* Twitter: [ @jsonapirb ] ( http://twitter.com/jsonapirb )
97
108## Installation
11-
129Add the following to your application's Gemfile:
1310``` ruby
1411gem ' jsonapi-rspec'
1512```
16- And then execute:
13+ then execute:
1714```
1815$ bundle
1916```
20-
21- Add to your ` spec/spec_helpers.rb ` :
22-
17+ and add ` jsonapi/rspec ` to your ` spec/spec_helpers.rb ` :
2318``` ruby
2419# spec/spec_helpers.rb
2520require ' jsonapi/rspec'
@@ -29,17 +24,17 @@ RSpec.configure do |config|
2924 config.include JSONAPI ::RSpec
3025end
3126```
32-
3327## Usage and documentation
3428
35- Available matchers:
29+ ### Available matchers:
3630
3731* ` expect(document['data']).to have_id('12') `
3832* ` expect(document['data']).to have_type('users') `
3933* ` expect(document['data']).to have_jsonapi_attributes(:name, :email) `
4034* ` expect(document['data']).to have_jsonapi_attributes(:name, :email, :country).exactly `
4135* ` expect(document['data']).to have_attribute(:name).with_value('Lucas') `
4236* ` expect(document['data']).to have_relationships(:posts, :comments) `
37+ * ` expect(document['data']).to have_relationship(:posts).with_data({ id: '1', type: 'posts' }) `
4338* ` expect(document['data']).to have_relationship(:posts).with_data([{ 'id' => '1', 'type' => 'posts' }]) `
4439* ` expect(document['data']['relationships']['posts']).to have_links(:self, :related) `
4540* ` expect(document['data']).to have_link(:self).with_value('http://api.example.com/users/12') `
@@ -48,10 +43,20 @@ Available matchers:
4843* ` expect(document).to have_jsonapi_object `
4944* ` expect(document).to have_jsonapi_object('version' => '1.0') `
5045
51- ## Advanced examples
46+ ### Indifferent Matching
47+ ``` ruby
48+ # spec/spec_helpers.rb
49+ require ' jsonapi/rspec'
5250
53- Checking for an included resource:
51+ RSpec .configure do |config |
52+ # ...
53+ config.allow_symbolized_jsonapi = true
54+ end
55+ ```
56+ The configuration above allows the RSpec matchers to work with a symbolized jsonapi source document.
5457
58+ ## Advanced examples
59+ Checking for an included resource:
5560``` ruby
5661expect(response_body[' included' ])
5762 .to include (have_type(' posts' ).and have_id(' 1' ))
@@ -67,4 +72,4 @@ contributors are expected to adhere to the
6772
6873## License
6974
70- jsonapi-rspec is released under the [ MIT License] ( http://www.opensource.org/licenses/MIT ) .
75+ jsonapi-rspec is released under the [ MIT License] ( http://www.opensource.org/licenses/MIT ) .
0 commit comments