jsonapi-rspec 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/jsonapi/rspec/attributes.rb +39 -5
- data/lib/jsonapi/rspec/relationships.rb +8 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5cb345693bd692513446e88fa4d1713b7927afa9b3a3033270ac26daefe3c07f
|
4
|
+
data.tar.gz: 8bc079f20dc7cd85e29b2a51f2d44e511d09153809507dbc4f361b55d79caf8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15c13b39490b4a72ef66e1aeed229665aacf8b98a0b3f2dfc8063d4b9dfa18190edb2c9a783cf921f23c0f5553d408065626669f4c39b7fa4cbdfb991e2e559e
|
7
|
+
data.tar.gz: e82b0d326630160bf704058b38068de72521670715280fbdf1539d17b725cb1e721167ff5e2ed830f73baa45bf100ed1f999589ef7392a0b19254bbb500b87f3
|
data/README.md
CHANGED
@@ -37,6 +37,7 @@ Available matchers:
|
|
37
37
|
* `expect(document['data']).to have_jsonapi_attributes(:name, :email, :country).exactly`
|
38
38
|
* `expect(document['data']).to have_attribute(:name).with_value('Lucas')`
|
39
39
|
* `expect(document['data']).to have_relationships(:posts, :comments)`
|
40
|
+
* `expect(document['data']).to have_relationships(:posts, :comments, :likes).exactly`
|
40
41
|
* `expect(document['data']).to have_relationship(:posts).with_data([{ 'id' => '1', 'type' => 'posts' }])`
|
41
42
|
* `expect(document['data']['relationships']['posts']).to have_links(:self, :related)`
|
42
43
|
* `expect(document['data']).to have_link(:self).with_value('http://api.example.com/users/12')`
|
@@ -4,14 +4,48 @@ module JSONAPI
|
|
4
4
|
::RSpec::Matchers.define :have_attribute do |attr|
|
5
5
|
match do |actual|
|
6
6
|
actual = JSONAPI::RSpec.as_indifferent_hash(actual)
|
7
|
-
|
8
|
-
|
7
|
+
@attributes_node = actual['attributes']
|
8
|
+
|
9
|
+
return false unless @attributes_node
|
10
|
+
|
11
|
+
@has_attribute = @attributes_node.key?(attr.to_s)
|
12
|
+
if @has_attribute && @should_match_value
|
13
|
+
@actual_value = @attributes_node[attr.to_s]
|
14
|
+
|
15
|
+
# Work nicely with diffable
|
16
|
+
@actual = @actual_value
|
17
|
+
@expected = @expected_value
|
18
|
+
|
19
|
+
return @actual == @expected
|
20
|
+
end
|
21
|
+
@has_attribute
|
9
22
|
end
|
10
23
|
|
11
|
-
chain :with_value do |
|
12
|
-
@
|
13
|
-
@
|
24
|
+
chain :with_value do |expected_value|
|
25
|
+
@should_match_value = true
|
26
|
+
@expected_value = expected_value
|
14
27
|
end
|
28
|
+
|
29
|
+
description do
|
30
|
+
result = "have attribute #{attr.inspect}"
|
31
|
+
if @should_match_value
|
32
|
+
result << " with value #{@expected_value.inspect}"
|
33
|
+
end
|
34
|
+
result
|
35
|
+
end
|
36
|
+
|
37
|
+
failure_message do |_actual|
|
38
|
+
if @has_attribute
|
39
|
+
"expected `#{attr}` attribute " \
|
40
|
+
"to have value `#{@expected}` but was `#{@actual}`"
|
41
|
+
else
|
42
|
+
"expected attributes to include `#{attr}`. " \
|
43
|
+
"Actual attributes were #{@attributes_node.keys}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
diffable
|
48
|
+
attr_reader :actual, :expected
|
15
49
|
end
|
16
50
|
|
17
51
|
::RSpec::Matchers.define :have_jsonapi_attributes do |*attrs|
|
@@ -29,7 +29,14 @@ module JSONAPI
|
|
29
29
|
actual = JSONAPI::RSpec.as_indifferent_hash(actual)
|
30
30
|
return false unless actual.key?('relationships')
|
31
31
|
|
32
|
-
rels.
|
32
|
+
counted = (rels.size == actual['relationships'].keys.size) if @exactly
|
33
|
+
|
34
|
+
rels.map(&:to_s).all? { |rel| actual['relationships'].key?(rel) } \
|
35
|
+
&& (counted == @exactly)
|
36
|
+
end
|
37
|
+
|
38
|
+
chain :exactly do
|
39
|
+
@exactly = true
|
33
40
|
end
|
34
41
|
end
|
35
42
|
end
|
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.7
|
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-07-
|
11
|
+
date: 2020-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-core
|