jsonapi-rspec 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa7320e501ff0cc08655a6e935589d300bedef20bc70add21f64d91d2e053a36
4
- data.tar.gz: 1d31cafea53bb133cc8c62c274403bad9aaaa7dfcf4834679bd4cf2dbd246a8c
3
+ metadata.gz: 5cb345693bd692513446e88fa4d1713b7927afa9b3a3033270ac26daefe3c07f
4
+ data.tar.gz: 8bc079f20dc7cd85e29b2a51f2d44e511d09153809507dbc4f361b55d79caf8e
5
5
  SHA512:
6
- metadata.gz: 727c5d55cfa976e4961dfe9798d1767bde29b364d7e4ff33dd52541a12c719c45f67bc021fd179432bd37ae60d26bc8477dce288eadb4b6365d0575570d3c6f0
7
- data.tar.gz: bc74dd39b5b8186f7f6d945277f4fd8a091a20f9c33febf4ed52a788ac54778c6d176e20861261d5e7ef60a061cefdaf1fbefb4eaf63ff5163e661ee378ffde0
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
- (actual['attributes'] || {}).key?(attr.to_s) &&
8
- (!@val_set || actual['attributes'][attr.to_s] == @val)
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 |val|
12
- @val_set = true
13
- @val = val
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.map(&:to_s).all? { |rel| actual['relationships'].key?(rel) }
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.6
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-12 00:00:00.000000000 Z
11
+ date: 2020-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-core