jsonapi-rspec 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/lib/jsonapi/rspec.rb +15 -0
- data/lib/jsonapi/rspec/attributes.rb +2 -0
- data/lib/jsonapi/rspec/id.rb +3 -1
- data/lib/jsonapi/rspec/jsonapi_object.rb +4 -2
- data/lib/jsonapi/rspec/links.rb +2 -0
- data/lib/jsonapi/rspec/meta.rb +4 -2
- data/lib/jsonapi/rspec/relationships.rb +4 -2
- data/lib/jsonapi/rspec/type.rb +3 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c6811a07f15a3e68d69b7ba45fc6df97c649d21e3b2a8df38fb493c6a20b615
|
4
|
+
data.tar.gz: da564714ee866647007b624ec7c871c2834949ec6a5d7987622f39df15e72458
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25715dae1b5adfcfc2e2e327d7042ee035efbd7123dd3bb36be939ff1e412a16bda3765f304ecc6304f446eab52a3584954cc0f0334fff4501143f06f450f81d
|
7
|
+
data.tar.gz: f95632ad22f0b9b74fd5315e39f2ea800c7c1062b53845357d7312f3d1d7831faae4e476c2981d59acef81c2bc510200ecbd33bbced0bdf21a9ccba18f1da8a7
|
data/README.md
CHANGED
@@ -25,10 +25,11 @@ Add to your `spec/spec_helpers.rb`:
|
|
25
25
|
require 'jsonapi/rspec'
|
26
26
|
|
27
27
|
RSpec.configure do |config|
|
28
|
-
# ...
|
29
28
|
config.include JSONAPI::RSpec
|
29
|
+
|
30
|
+
# Support for documents with mixed string/symbol keys. Disabled by default.
|
31
|
+
config.jsonapi_indifferent_hash = true
|
30
32
|
end
|
31
|
-
```
|
32
33
|
|
33
34
|
## Usage and documentation
|
34
35
|
|
data/lib/jsonapi/rspec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'json'
|
1
2
|
require 'rspec/matchers'
|
2
3
|
require 'jsonapi/rspec/id'
|
3
4
|
require 'jsonapi/rspec/type'
|
@@ -7,6 +8,10 @@ require 'jsonapi/rspec/links'
|
|
7
8
|
require 'jsonapi/rspec/meta'
|
8
9
|
require 'jsonapi/rspec/jsonapi_object'
|
9
10
|
|
11
|
+
RSpec.configure do |c|
|
12
|
+
c.add_setting :jsonapi_indifferent_hash, default: false
|
13
|
+
end
|
14
|
+
|
10
15
|
module JSONAPI
|
11
16
|
module RSpec
|
12
17
|
include Id
|
@@ -16,5 +21,15 @@ module JSONAPI
|
|
16
21
|
include Links
|
17
22
|
include Meta
|
18
23
|
include JsonapiObject
|
24
|
+
|
25
|
+
def self.as_indifferent_hash(doc)
|
26
|
+
return doc unless ::RSpec.configuration.jsonapi_indifferent_hash
|
27
|
+
|
28
|
+
if doc.respond_to?(:with_indifferent_access)
|
29
|
+
return doc.with_indifferent_access
|
30
|
+
end
|
31
|
+
|
32
|
+
JSON.parse(JSON.generate(doc))
|
33
|
+
end
|
19
34
|
end
|
20
35
|
end
|
@@ -3,6 +3,7 @@ module JSONAPI
|
|
3
3
|
module Attributes
|
4
4
|
::RSpec::Matchers.define :have_attribute do |attr|
|
5
5
|
match do |actual|
|
6
|
+
actual = JSONAPI::RSpec.as_indifferent_hash(actual)
|
6
7
|
(actual['attributes'] || {}).key?(attr.to_s) &&
|
7
8
|
(!@val_set || actual['attributes'][attr.to_s] == @val)
|
8
9
|
end
|
@@ -15,6 +16,7 @@ module JSONAPI
|
|
15
16
|
|
16
17
|
::RSpec::Matchers.define :have_jsonapi_attributes do |*attrs|
|
17
18
|
match do |actual|
|
19
|
+
actual = JSONAPI::RSpec.as_indifferent_hash(actual)
|
18
20
|
return false unless actual.key?('attributes')
|
19
21
|
|
20
22
|
counted = (attrs.size == actual['attributes'].size) if @exactly
|
data/lib/jsonapi/rspec/id.rb
CHANGED
@@ -3,8 +3,10 @@ module JSONAPI
|
|
3
3
|
module JsonapiObject
|
4
4
|
::RSpec::Matchers.define :have_jsonapi_object do |val|
|
5
5
|
match do |actual|
|
6
|
-
actual.
|
7
|
-
|
6
|
+
actual = JSONAPI::RSpec.as_indifferent_hash(actual)
|
7
|
+
val = JSONAPI::RSpec.as_indifferent_hash(val)
|
8
|
+
|
9
|
+
actual.key?('jsonapi') && (!val || actual['jsonapi'] == val)
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|
data/lib/jsonapi/rspec/links.rb
CHANGED
@@ -3,6 +3,7 @@ module JSONAPI
|
|
3
3
|
module Links
|
4
4
|
::RSpec::Matchers.define :have_link do |link|
|
5
5
|
match do |actual|
|
6
|
+
actual = JSONAPI::RSpec.as_indifferent_hash(actual)
|
6
7
|
actual.key?('links') && actual['links'].key?(link.to_s) &&
|
7
8
|
(!@val_set || actual['links'][link.to_s] == @val)
|
8
9
|
end
|
@@ -15,6 +16,7 @@ module JSONAPI
|
|
15
16
|
|
16
17
|
::RSpec::Matchers.define :have_links do |*links|
|
17
18
|
match do |actual|
|
19
|
+
actual = JSONAPI::RSpec.as_indifferent_hash(actual)
|
18
20
|
return false unless actual.key?('links')
|
19
21
|
|
20
22
|
links.all? { |link| actual['links'].key?(link.to_s) }
|
data/lib/jsonapi/rspec/meta.rb
CHANGED
@@ -3,8 +3,10 @@ module JSONAPI
|
|
3
3
|
module Meta
|
4
4
|
::RSpec::Matchers.define :have_meta do |val|
|
5
5
|
match do |actual|
|
6
|
-
actual.
|
7
|
-
|
6
|
+
actual = JSONAPI::RSpec.as_indifferent_hash(actual)
|
7
|
+
val = JSONAPI::RSpec.as_indifferent_hash(val)
|
8
|
+
|
9
|
+
actual.key?('meta') && (!val || actual['meta'] == val)
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|
@@ -3,6 +3,7 @@ module JSONAPI
|
|
3
3
|
module Relationships
|
4
4
|
::RSpec::Matchers.define :have_relationship do |rel|
|
5
5
|
match do |actual|
|
6
|
+
actual = JSONAPI::RSpec.as_indifferent_hash(actual)
|
6
7
|
return false unless (actual['relationships'] || {}).key?(rel.to_s)
|
7
8
|
|
8
9
|
!@data_set || actual['relationships'][rel.to_s]['data'] == @data_val
|
@@ -10,7 +11,7 @@ module JSONAPI
|
|
10
11
|
|
11
12
|
chain :with_data do |val|
|
12
13
|
@data_set = true
|
13
|
-
@data_val = val
|
14
|
+
@data_val = JSONAPI::RSpec.as_indifferent_hash(val)
|
14
15
|
end
|
15
16
|
|
16
17
|
failure_message do |actual|
|
@@ -25,9 +26,10 @@ module JSONAPI
|
|
25
26
|
|
26
27
|
::RSpec::Matchers.define :have_relationships do |*rels|
|
27
28
|
match do |actual|
|
29
|
+
actual = JSONAPI::RSpec.as_indifferent_hash(actual)
|
28
30
|
return false unless actual.key?('relationships')
|
29
31
|
|
30
|
-
rels.all? { |rel| actual['relationships'].key?(rel) }
|
32
|
+
rels.map(&:to_s).all? { |rel| actual['relationships'].key?(rel) }
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
data/lib/jsonapi/rspec/type.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Hosseini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-expectations
|
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '0'
|
117
117
|
requirements: []
|
118
|
-
rubygems_version: 3.
|
118
|
+
rubygems_version: 3.1.2
|
119
119
|
signing_key:
|
120
120
|
specification_version: 4
|
121
121
|
summary: RSpec matchers for JSON API.
|