rspec-protobuf 0.2.0 → 0.2.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: ff057c1fafc371beb4b2d2890300d27ef142158299190715fb9bef3891a24ec6
4
- data.tar.gz: a9fa3d68d62d37fe63f7b556e05f221afe0de2ebe34bbf47bd91d313e04d06b5
3
+ metadata.gz: e02818bd754dbc93cdd721fd59642c53c442b50d23a351adb44eb0df3df146d9
4
+ data.tar.gz: e913a28c47e0280252f0eaf8a14f66ba16dcceb94de25d4cd227bc51ef40dbdf
5
5
  SHA512:
6
- metadata.gz: b5a7bd6137681147eeb3d97c9e8c162a2e71e7de3d6b2d0f1d4cac95449ea179b6e784c2b428f42fb4dc5912eb19ccbbfea5d1caec6864d7b21d339cb8d23c4e
7
- data.tar.gz: a8bb57417121161efdcb3f0b876b93e1c5da578ab90c40d96617cb1eb8c04719d5a372d5edcf294d8edbbea2628d67312a65b94d43329b2bc2a33f3a5319690a
6
+ metadata.gz: 9b8b8a507e7074155239ee294f122812c28d9575131f93a79315caa44b2b2aab26c931a696da3c17fb1a0491f7755e1a050067277fd24dbd20df206e1ee48da3
7
+ data.tar.gz: 65da298087c49ae41d64c8fa280418666a926abe904d89bb0045785bbed4070abd8a27be13e13e6842b5e706cadd89cd2719bcfb0c5c198a2ec1c24a2d3eb2c6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ### v0.2.1 (2022-11-16)
2
+ - fix enum matching
3
+
1
4
  ### v0.2.0 (2022-11-09)
2
5
  - rspec differ
3
6
  - failure message and test coverage
@@ -11,9 +11,18 @@ module RSpec
11
11
  # ensure all enumerated attributes are present
12
12
  return false unless expected_attrs.keys.all? { |attr| respond_to?(attr) }
13
13
 
14
+ fields = {}
15
+ self.class.descriptor.each { |f| fields[f.name.to_sym] = f }
16
+
14
17
  # check expected attribute matches
15
18
  expected_attrs.all? do |expected_attr, expected_value|
16
- actual_value = send(expected_attr)
19
+ field = fields[expected_attr]
20
+ actual_value = field.get(self)
21
+
22
+ # convert enum to int value to match input type
23
+ if field.type == :enum && expected_value.is_a?(Integer)
24
+ actual_value = field.subtype.lookup_name(actual_value)
25
+ end
17
26
 
18
27
  matches = expected_value === actual_value
19
28
 
@@ -41,7 +50,15 @@ module RSpec
41
50
  if actual_value.is_a?(Google::Protobuf::MessageExts) && expected_value.is_a?(Hash)
42
51
  actual_value.match?(**expected_value)
43
52
  else
44
- attrs.fetch(field.name.to_sym, field.default) === actual_value
53
+ # fall back to default value
54
+ expected_value = field.default unless attrs.key?(field.name.to_sym)
55
+
56
+ # convert enum to int value to match input type
57
+ if field.type == :enum && expected_value.is_a?(Integer)
58
+ actual_value = field.subtype.lookup_name(actual_value)
59
+ end
60
+
61
+ expected_value === actual_value
45
62
  end
46
63
  end
47
64
  end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module Protobuf
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
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.2.0
4
+ version: 0.2.1
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-09 00:00:00.000000000 Z
11
+ date: 2022-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-protobuf