rspec_jsonapi_serializer 1.0.0 → 1.0.1

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: 7ed8b7ea471eb94db672c660a12559e64b185bc7d9e47326f9623be38859d9b6
4
- data.tar.gz: eacf5f0be70a08e50cb2b42f02788c14b089722cbee3d4d1e28a1efda1e8b7a2
3
+ metadata.gz: c575d046628ade51e83238d8bc7179eea00ee9bc1cedde252fda0c8b98fa2269
4
+ data.tar.gz: 30d857690790f7cc807ac6e432e1103ef646e140f085a7c5c09c8b6d3b75b1c6
5
5
  SHA512:
6
- metadata.gz: '090a203b5643c3930787cf553d6ea1146fffc51964b4a2e94e01b318a31900b590ef3b61e50ec63cb9d1b4d6cc66c7040ca74e60719e3e37470bd7e525940936'
7
- data.tar.gz: e7dc94dce570f0a299389743e42183dfe119c723f76573687577f10b5de2175d655ebdbeb2dbb5cc5583027dae58580e07590fe7940eca09035a1270ad924fc4
6
+ metadata.gz: f1303aa1426102b7f26ebc5d4abc0fbfb0a9f712e9b231e05e5a43e6e70900d3f8a1e22731db6d00f701bcbf7c024117a7c2f22fed4530403e069682f2826556
7
+ data.tar.gz: 52b6d4c3dd1e2214e4275105195c028b35dfbb4b599754c23b6d65fe9c6b6cfb86e6ecc2a2bca35b5319d4b507b1c909171513dd0e5c427ea100cfb27429d261
@@ -19,7 +19,13 @@ module RSpecJSONAPISerializer
19
19
  .has_key?(expected)
20
20
  end
21
21
 
22
- def main_failure_message
22
+ def description
23
+ description = "#{association_message} #{expected}"
24
+
25
+ [description, submatchers.map(&:description)].flatten.join(' ')
26
+ end
27
+
28
+ def failure_message
23
29
  [expected_message, actual_message].compact.join(", ")
24
30
  end
25
31
 
@@ -36,7 +42,7 @@ module RSpecJSONAPISerializer
36
42
  end
37
43
 
38
44
  def association_message
39
- relationship_matcher.to_s.split('_')
45
+ relationship_matcher.to_s.split("_").join(" ")
40
46
  end
41
47
 
42
48
  def actual
@@ -13,27 +13,17 @@ module RSpecJSONAPISerializer
13
13
  end
14
14
 
15
15
  def failure_message
16
- ([main_failure_message] + submatcher_failure_messages).compact.join("\n")
16
+ raise NotImplementedError
17
17
  end
18
18
 
19
19
  def failure_message_when_negated
20
- ([main_failure_message_when_negated] + submatcher_failure_messages_when_negated)
21
- .compact
22
- .join("\n")
20
+ raise NotImplementedError
23
21
  end
24
22
 
25
23
  protected
26
24
 
27
25
  attr_reader :expected, :serializer_instance, :submatchers
28
26
 
29
- def main_failure_message
30
- raise NotImplementedError
31
- end
32
-
33
- def main_failure_message_when_negated
34
- raise NotImplementedError
35
- end
36
-
37
27
  def add_submatcher(submatcher)
38
28
  submatchers << submatcher
39
29
  end
@@ -50,16 +40,6 @@ module RSpecJSONAPISerializer
50
40
  serializer_instance.class.name
51
41
  end
52
42
 
53
- private
54
-
55
- def submatcher_failure_messages
56
- failing_submatchers.map(&:failure_message)
57
- end
58
-
59
- def submatcher_failure_messages_when_negated
60
- failing_submatchers.map(&:failure_message_when_negated)
61
- end
62
-
63
43
  def failing_submatchers
64
44
  @failing_submatchers ||= submatchers.select do |submatcher|
65
45
  !submatcher.matches?(serializer_instance)
@@ -13,8 +13,12 @@ module RSpecJSONAPISerializer
13
13
  association_matcher.matches?(serializer_instance)
14
14
  end
15
15
 
16
- def main_failure_message
17
- association_matcher.main_failure_message
16
+ def description
17
+ association_matcher.description
18
+ end
19
+
20
+ def failure_message
21
+ association_matcher.failure_message
18
22
  end
19
23
 
20
24
  private
@@ -19,17 +19,35 @@ module RSpecJSONAPISerializer
19
19
  end
20
20
 
21
21
  def as_nil
22
- add_submatcher HaveAttributeMatchers::AsMatcher.new(expected, nil)
22
+ as(nil)
23
+ end
23
24
 
24
- self
25
+ def description
26
+ description = "have attribute #{expected}"
27
+
28
+ [description, submatchers.map(&:description)].flatten.join(' ')
29
+ end
30
+
31
+ def failure_message
32
+ "Expected #{expectation}."
25
33
  end
26
34
 
27
- def main_failure_message
28
- "expected #{serializer_name} to have attribute #{expected}." unless has_attribute?
35
+ def failure_message_when_negated
36
+ "Did not expect #{expectation}."
29
37
  end
30
38
 
31
39
  private
32
40
 
41
+ def expectation
42
+ expectation = "#{serializer_name} to have attribute #{expected}"
43
+
44
+ submatchers_expectations = failing_submatchers.map do |submatcher|
45
+ "(#{submatcher.expectation})"
46
+ end.compact.join(", ")
47
+
48
+ [expectation, submatchers_expectations].reject(&:nil?).reject(&:empty?).join(" ")
49
+ end
50
+
33
51
  def attributes
34
52
  @attributes ||= serializer_instance.class.try(:attributes_to_serialize) || {}
35
53
  end
@@ -18,20 +18,30 @@ module RSpecJSONAPISerializer
18
18
  actual == expected
19
19
  end
20
20
 
21
- def failure_message
22
- [expected_message, actual_message].compact.join(", ")
21
+ def description
22
+ "as #{expected_to_string}"
23
+ end
24
+
25
+ def expectation
26
+ [ "as #{expected_to_string}", actual_message ].compact.join(", ")
23
27
  end
24
28
 
25
29
  private
26
30
 
27
31
  attr_reader :attribute
28
32
 
29
- def expected_message
30
- "expected #{serializer_instance.class.name} to serialize #{attribute} as #{expected}"
33
+ def expected_to_string
34
+ value_to_string(expected)
31
35
  end
32
36
 
33
37
  def actual_message
34
- "got #{actual.nil? ? 'nil' : actual} instead" if attributes.has_key?(attribute)
38
+ "got #{value_to_string(actual)} instead" if attributes.has_key?(attribute)
39
+ end
40
+
41
+ def value_to_string(value)
42
+ return 'nil' if value.nil?
43
+
44
+ value.to_s
35
45
  end
36
46
 
37
47
  def actual
@@ -11,7 +11,7 @@ module RSpecJSONAPISerializer
11
11
  actual == expected
12
12
  end
13
13
 
14
- def main_failure_message
14
+ def failure_message
15
15
  "expected that #{serializer_name} to have id :#{expected}, got :#{actual} instead"
16
16
  end
17
17
 
@@ -19,17 +19,35 @@ module RSpecJSONAPISerializer
19
19
  end
20
20
 
21
21
  def as_nil
22
- add_submatcher HaveLinkMatchers::AsMatcher.new(expected, nil)
22
+ as(nil)
23
+ end
23
24
 
24
- self
25
+ def description
26
+ description = "have link #{expected}"
27
+
28
+ [description, submatchers.map(&:description)].flatten.join(' ')
29
+ end
30
+
31
+ def failure_message
32
+ "Expected #{expectation}."
25
33
  end
26
34
 
27
- def main_failure_message
28
- "expected #{serializer_name} to have link #{expected}." unless has_link?
35
+ def failure_message_when_negated
36
+ "Did not expect #{expectation}."
29
37
  end
30
38
 
31
39
  private
32
40
 
41
+ def expectation
42
+ expectation = "#{serializer_name} to have link #{expected}"
43
+
44
+ submatchers_expectations = failing_submatchers.map do |submatcher|
45
+ "(#{submatcher.expectation})"
46
+ end.compact.join(", ")
47
+
48
+ [expectation, submatchers_expectations].reject(&:nil?).reject(&:empty?).join(" ")
49
+ end
50
+
33
51
  def has_link?
34
52
  links.has_key?(expected)
35
53
  end
@@ -18,20 +18,30 @@ module RSpecJSONAPISerializer
18
18
  actual == expected
19
19
  end
20
20
 
21
- def failure_message
22
- [expected_message, actual_message].compact.join(", ")
21
+ def description
22
+ "as #{expected_to_string}"
23
+ end
24
+
25
+ def expectation
26
+ [ "as #{expected_to_string}", actual_message ].compact.join(", ")
23
27
  end
24
28
 
25
29
  private
26
30
 
27
31
  attr_reader :link
28
32
 
29
- def expected_message
30
- "expected #{serializer_instance.class.name} to serialize link #{link} as #{expected}"
33
+ def expected_to_string
34
+ value_to_string(expected)
31
35
  end
32
36
 
33
37
  def actual_message
34
- "got #{actual.nil? ? 'nil' : actual} instead" if links.has_key?(link)
38
+ "got #{value_to_string(actual)} instead" if links.has_key?(link)
39
+ end
40
+
41
+ def value_to_string(value)
42
+ return 'nil' if value.nil?
43
+
44
+ value.to_s
35
45
  end
36
46
 
37
47
  def actual
@@ -13,8 +13,12 @@ module RSpecJSONAPISerializer
13
13
  association_matcher.matches?(serializer_instance)
14
14
  end
15
15
 
16
- def main_failure_message
17
- association_matcher.main_failure_message
16
+ def description
17
+ association_matcher.description
18
+ end
19
+
20
+ def failure_message
21
+ association_matcher.failure_message
18
22
  end
19
23
 
20
24
  private
@@ -19,17 +19,35 @@ module RSpecJSONAPISerializer
19
19
  end
20
20
 
21
21
  def as_nil
22
- add_submatcher HaveMetaMatchers::AsMatcher.new(expected, nil)
22
+ as(nil)
23
+ end
23
24
 
24
- self
25
+ def description
26
+ description = "serialize meta #{expected}"
27
+
28
+ [description, submatchers.map(&:description)].flatten.join(' ')
29
+ end
30
+
31
+ def failure_message
32
+ "Expected #{expectation}."
25
33
  end
26
34
 
27
- def main_failure_message
28
- "expected #{serializer_name} to serialize meta #{expected}." unless has_meta?
35
+ def failure_message_when_negated
36
+ "Did not expect #{expectation}."
29
37
  end
30
38
 
31
39
  private
32
40
 
41
+ def expectation
42
+ expectation = "#{serializer_name} to serialize meta #{expected}"
43
+
44
+ submatchers_expectations = failing_submatchers.map do |submatcher|
45
+ "(#{submatcher.expectation})"
46
+ end.compact.join(", ")
47
+
48
+ [expectation, submatchers_expectations].reject(&:nil?).reject(&:empty?).join(" ")
49
+ end
50
+
33
51
  def metas
34
52
  @metas ||= serializable_hash.dig(:data, :meta) || {}
35
53
  end
@@ -18,22 +18,33 @@ module RSpecJSONAPISerializer
18
18
  actual == expected
19
19
  end
20
20
 
21
- def failure_message
22
- [expected_message, actual_message].compact.join(", ")
21
+ def description
22
+ "as #{expected_to_string}"
23
+ end
24
+
25
+ def expectation
26
+ [ "as #{expected_to_string}", actual_message ].compact.join(", ")
23
27
  end
24
28
 
25
29
  private
26
30
 
27
31
  attr_reader :meta
28
32
 
29
- def expected_message
30
- "expected #{serializer_instance.class.name} to serialize meta #{meta} as #{expected}"
33
+ def expected_to_string
34
+ value_to_string(expected)
31
35
  end
32
36
 
33
37
  def actual_message
34
38
  "got #{actual.nil? ? 'nil' : actual} instead" if metas.has_key?(meta)
35
39
  end
36
40
 
41
+ def value_to_string(value)
42
+ return 'nil' if value.nil?
43
+
44
+ value.to_s
45
+ end
46
+
47
+
37
48
  def actual
38
49
  metas[meta]
39
50
  end
@@ -13,8 +13,12 @@ module RSpecJSONAPISerializer
13
13
  association_matcher.matches?(serializer_instance)
14
14
  end
15
15
 
16
- def main_failure_message
17
- association_matcher.main_failure_message
16
+ def description
17
+ association_matcher.description
18
+ end
19
+
20
+ def failure_message
21
+ association_matcher.failure_message
18
22
  end
19
23
 
20
24
  private
@@ -11,7 +11,7 @@ module RSpecJSONAPISerializer
11
11
  actual == expected
12
12
  end
13
13
 
14
- def main_failure_message
14
+ def failure_message
15
15
  "expected that #{serializer_name} to have type :#{expected}, got :#{actual} instead"
16
16
  end
17
17
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RSpecJSONAPISerializer
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_jsonapi_serializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateus Cruz
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-10 00:00:00.000000000 Z
11
+ date: 2023-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-serializer
@@ -24,7 +24,7 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
- description:
27
+ description:
28
28
  email:
29
29
  - mateus@intricately.com
30
30
  executables: []
@@ -54,7 +54,7 @@ metadata:
54
54
  homepage_uri: https://github.com/teamintricately/rspec_jsonapi_serializer
55
55
  source_code_uri: https://github.com/teamintricately/rspec_jsonapi_serializer
56
56
  changelog_uri: https://github.com/teamintricately/rspec_jsonapi_serializer/blob/main/CHANGELOG.md
57
- post_install_message:
57
+ post_install_message:
58
58
  rdoc_options: []
59
59
  require_paths:
60
60
  - lib
@@ -69,8 +69,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  requirements: []
72
- rubygems_version: 3.2.16
73
- signing_key:
72
+ rubygems_version: 3.3.7
73
+ signing_key:
74
74
  specification_version: 4
75
75
  summary: RSpec matchers for jsonapi-serializer.
76
76
  test_files: []