@@ -10,15 +10,19 @@ def body
1010 end
1111
1212 it 'works' do
13+ # Get empty tweets list
1314 get '/tweets' , headers : headers
1415 expect ( response ) . to be_success
1516 expect ( response ) . to have_http_status ( 200 )
16- expected = {
17- 'data' => [ ]
18- }
19- expect { JSONAPI . parse_response! ( body ) } . not_to raise_error
20- expect ( body ) . to eq ( expected )
17+ expect ( response . body ) . to be_valid_jsonapi
18+ expect ( response . body ) . to match_schema do
19+ required ( :data ) . value ( eql? : [ ] )
20+ required ( :meta ) . value ( eql? : { 'foo' => 'bar' } )
21+ required ( :jsonapi ) . value ( eql? : { 'version' => '1.0' } )
22+ required ( :links ) . value ( eql? : { 'self' => 'http://foo.bar' } )
23+ end
2124
25+ # Post first tweet
2226 params = {
2327 data : {
2428 type : 'tweets' ,
@@ -41,9 +45,21 @@ def body
4145 headers : headers . merge ( 'CONTENT_TYPE' => 'application/vnd.api+json' )
4246 expect ( response ) . to be_success
4347 expect ( response ) . to have_http_status ( 201 )
44- expect { JSONAPI . parse_response! ( body ) } . not_to raise_error
48+ expect ( response . body ) . to be_valid_jsonapi
49+ expect ( response . body ) . to match_schema do
50+ required ( :data ) . schema do
51+ required ( :type ) . value ( eql? : 'tweets' )
52+ required ( :attributes ) . schema do
53+ required ( :content ) . value ( eql? : 'foo' )
54+ end
55+ required ( :relationships ) . schema do
56+ required ( :author )
57+ end
58+ end
59+ end
4560 first_tweet = body
4661
62+ # Post second tweet
4763 params = {
4864 data : {
4965 type : 'tweets' ,
@@ -61,20 +77,23 @@ def body
6177 expect { JSONAPI . parse_response! ( body ) } . not_to raise_error
6278 second_tweet = body
6379
80+ # Get first tweet
6481 get "/tweets/#{ first_tweet [ 'data' ] [ 'id' ] } " , headers : headers
6582 expect ( response ) . to be_success
6683 expect ( response ) . to have_http_status ( 200 )
67- expect { JSONAPI . parse_response! ( body ) } . not_to raise_error
84+ expect ( response . body ) . to be_valid_jsonapi
6885 expect ( body ) . to eq ( first_tweet )
6986
87+ # Delete first tweet
7088 delete "/tweets/#{ first_tweet [ 'data' ] [ 'id' ] } "
7189 expect ( response ) . to be_success
7290 expect ( response ) . to have_http_status ( 204 )
7391
92+ # List remaining tweets
7493 get '/tweets'
7594 expect ( response ) . to be_success
7695 expect ( response ) . to have_http_status ( 200 )
77- expect { JSONAPI . parse_response! ( body ) } . not_to raise_error
96+ expect ( response . body ) . to be_valid_jsonapi
7897 expect ( body [ 'data' ] . first ) . to eq ( second_tweet [ 'data' ] )
7998 end
8099end
0 commit comments