rspec-protobuf 0.1.0 → 0.2.0

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: 4edfb359c42bc196bc668c9d88916ed4cf05f9b0f465a39353efccd90dc73477
4
- data.tar.gz: f5151e46350a73c03f25ac349a71ced8a295a573237aae678044711bd72328a3
3
+ metadata.gz: ff057c1fafc371beb4b2d2890300d27ef142158299190715fb9bef3891a24ec6
4
+ data.tar.gz: a9fa3d68d62d37fe63f7b556e05f221afe0de2ebe34bbf47bd91d313e04d06b5
5
5
  SHA512:
6
- metadata.gz: 8a7a6963bc85ed51a6bdfd7802784e5c9c9932f3d24932bbee9c46349112ec861ec8bc289bab12ef2818f1a34117023a45265899f42d66760dfa2b67bb32f062
7
- data.tar.gz: dba4658ed4fa1cae57a4ea57a83867a9313968118a10659b0acfccd229d914c4b36df054fe70428c43eb5430496f0d319ea268ed57e1b6ec2f969cae539424bc
6
+ metadata.gz: b5a7bd6137681147eeb3d97c9e8c162a2e71e7de3d6b2d0f1d4cac95449ea179b6e784c2b428f42fb4dc5912eb19ccbbfea5d1caec6864d7b21d339cb8d23c4e
7
+ data.tar.gz: a8bb57417121161efdcb3f0b876b93e1c5da578ab90c40d96617cb1eb8c04719d5a372d5edcf294d8edbbea2628d67312a65b94d43329b2bc2a33f3a5319690a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ### v0.2.0 (2022-11-09)
2
+ - rspec differ
3
+ - failure message and test coverage
4
+ - simplify
5
+
1
6
  ### v0.1.0 (2022-11-08)
2
7
  -
3
8
 
data/README.md CHANGED
@@ -17,6 +17,26 @@ it { is_expected.to be_a_protobuf(msg: /^h/) }
17
17
  ```
18
18
 
19
19
 
20
+ ### Improved RSpec Errors
21
+ Before
22
+ ```ruby
23
+ Failure/Error: is_expected.to have_attributes(date: { month: 2 })
24
+ expected <ComplexMessage: complex: false, date: <DateMessage: type: :DATE_DEFAULT, month: 1, day: 0, year: 0>> to have attributes {:date => {:month => 2}} but had attributes {:date => <DateMessage: type: :DATE_DEFAULT, month: 1, day: 0, year: 0>}
25
+ Diff:
26
+ @@ -1 +1 @@
27
+ -:date => {:month=>2},
28
+ +:date => <DateMessage: type: :DATE_DEFAULT, month: 1, day: 0, year: 0>,
29
+ ```
30
+
31
+ After
32
+ ```ruby
33
+ Failure/Error: is_expected.to be_a_protobuf(date: { month: 2 })
34
+ Diff:
35
+ @@ -1 +1 @@
36
+ -:date => {:month=>2},
37
+ +:date => {:month=>1},
38
+ ```
39
+
20
40
  ----
21
41
  ## Contributing
22
42
 
@@ -2,24 +2,6 @@ module RSpec
2
2
  module Protobuf
3
3
  module Refinements
4
4
  refine Google::Protobuf::MessageExts do
5
- def normalized_hash(symbolize_keys: true)
6
- res = {}
7
-
8
- self.class.descriptor.each do |field|
9
- key = symbolize_keys ? field.name.to_sym : field.name
10
- value = field.get(self)
11
-
12
- if value.is_a?(Google::Protobuf::MessageExts)
13
- # recursively serialize sub-message
14
- value = value.normalized_hash(symbolize_keys: symbolize_keys)
15
- end
16
-
17
- res[key] = value unless field.default == value
18
- end
19
-
20
- res
21
- end
22
-
23
5
  def include?(*args)
24
6
  expected_attrs = Hash === args.last ? args.pop : {}
25
7
 
@@ -63,6 +45,23 @@ module RSpec
63
45
  end
64
46
  end
65
47
  end
48
+
49
+ def normalized_hash
50
+ res = {}
51
+
52
+ self.class.descriptor.each do |field|
53
+ value = field.get(self)
54
+
55
+ if value.is_a?(Google::Protobuf::MessageExts)
56
+ # recursively serialize sub-message
57
+ value = value.normalized_hash
58
+ end
59
+
60
+ res[field.name.to_sym] = value unless field.default == value
61
+ end
62
+
63
+ res
64
+ end
66
65
  end
67
66
  end
68
67
  end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module Protobuf
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -9,9 +9,10 @@ RSpec::Matchers.define :be_a_protobuf do |type = nil, **attrs|
9
9
  match do |actual|
10
10
  # ensure type is a valid Protobuf message type
11
11
  if type && !(type < Google::Protobuf::MessageExts)
12
- raise TypeError, "Expected areg to be a Google::Protobuf::MessageExts, found: #{type}"
12
+ raise TypeError, "Expected arg to be a Google::Protobuf::MessageExts, found: #{type}"
13
13
  end
14
14
 
15
+ @fail_msg = "#{actual} is not a Protobuf"
15
16
  return false unless actual.is_a?(Google::Protobuf::MessageExts)
16
17
 
17
18
  # match expected message type
@@ -29,14 +30,23 @@ RSpec::Matchers.define :be_a_protobuf do |type = nil, **attrs|
29
30
  end
30
31
  end
31
32
 
33
+ @fail_msg = ""
34
+
35
+ # customize differ output by removing unreferenced and default attrs
36
+ @actual = actual.normalized_hash.slice(*attrs.keys).reject do |k, v|
37
+ v == actual.class.descriptor.lookup(k.to_s).default
38
+ end
39
+
32
40
  actual.include?(attrs)
33
41
  end
34
42
 
35
43
  description do
36
- type ? "a #{type} Protobuf message" : "a Protobuf message"
44
+ type ? "a #{type} Protobuf" : "a Protobuf"
37
45
  end
38
46
 
39
47
  failure_message { @fail_msg }
48
+
49
+ diffable
40
50
  end
41
51
 
42
52
  RSpec::Matchers.alias_matcher :a_protobuf, :be_a_protobuf
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-protobuf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Pepper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-08 00:00:00.000000000 Z
11
+ date: 2022-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-protobuf