webmock-twirp 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/webmock/twirp/refinements.rb +60 -4
- data/lib/webmock/twirp/request_stub.rb +3 -19
- data/lib/webmock/twirp/version.rb +1 -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: 5a732c5a4926da1aa55cfb9348ea84c0cd7506fabc1e598a746dabd4fa57a2c9
|
4
|
+
data.tar.gz: e4ec2abe817732781453442877ffbae84771919cebed81238360c3a002ef7820
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28e13a626132b193b2d3aaa26c5d192949d296171d63d2b5bc2539fd88eab2a72c633d29bc0a4711d804ba7be144de2dc57a1be8b1d71a5d0b614fa3c927885b
|
7
|
+
data.tar.gz: 7b42012c4c5ea5c49868091dddf44cdafcd4fcb7b76dadae2bd91135c8bb5b65307aca1797eef8153d9839fe72ddf08c0178156227f0c74b0fe561a03642d829
|
data/CHANGELOG.md
CHANGED
@@ -9,10 +9,66 @@ module WebMock
|
|
9
9
|
|
10
10
|
refine Google::Protobuf::MessageExts do
|
11
11
|
def normalized_hash(symbolize_keys: true)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
res = {}
|
13
|
+
|
14
|
+
self.class.descriptor.each do |field|
|
15
|
+
key = symbolize_keys ? field.name.to_sym : field.name
|
16
|
+
value = field.get(self)
|
17
|
+
|
18
|
+
if value.is_a?(Google::Protobuf::MessageExts)
|
19
|
+
# recursively serialize sub-message
|
20
|
+
value = value.normalized_hash(symbolize_keys: symbolize_keys)
|
21
|
+
end
|
22
|
+
|
23
|
+
res[key] = value unless field.default == value
|
24
|
+
end
|
25
|
+
|
26
|
+
res
|
27
|
+
end
|
28
|
+
|
29
|
+
def include?(*args)
|
30
|
+
expected_attrs = Hash === args.last ? args.pop : {}
|
31
|
+
|
32
|
+
# ensure all enumerated keys are present
|
33
|
+
return false unless args.all? { |attr| respond_to?(attr) }
|
34
|
+
|
35
|
+
# ensure all enumerated attributes are present
|
36
|
+
return false unless expected_attrs.keys.all? { |attr| respond_to?(attr) }
|
37
|
+
|
38
|
+
# check expected attribute matches
|
39
|
+
expected_attrs.all? do |expected_attr, expected_value|
|
40
|
+
actual_value = send(expected_attr)
|
41
|
+
|
42
|
+
matches = expected_value === actual_value
|
43
|
+
|
44
|
+
if actual_value.is_a?(Google::Protobuf::MessageExts)
|
45
|
+
if expected_value.is_a?(Hash)
|
46
|
+
matches ||= actual_value.match?(**expected_value)
|
47
|
+
else
|
48
|
+
matches ||= expected_value === actual_value.to_h
|
49
|
+
# matches ||= expected_value === actual_value.normalized_hash
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
matches
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def match?(**attrs)
|
58
|
+
# ensure all enumerated keys are present
|
59
|
+
return false unless attrs.keys.all? { |attr| respond_to?(attr) }
|
60
|
+
|
61
|
+
# ensure each field matches
|
62
|
+
self.class.descriptor.all? do |field|
|
63
|
+
actual_value = field.get(self)
|
64
|
+
expected_value = attrs[field.name.to_sym]
|
65
|
+
|
66
|
+
if actual_value.is_a?(Google::Protobuf::MessageExts) && expected_value.is_a?(Hash)
|
67
|
+
actual_value.match?(**expected_value)
|
68
|
+
else
|
69
|
+
attrs.fetch(field.name.to_sym, field.default) === actual_value
|
70
|
+
end
|
71
|
+
end
|
16
72
|
end
|
17
73
|
end
|
18
74
|
end
|
@@ -71,27 +71,11 @@ module WebMock
|
|
71
71
|
|
72
72
|
decoder = ->(request) do
|
73
73
|
input_class = rpc_from_request(request)[:input_class]
|
74
|
-
|
75
|
-
matched = true
|
76
74
|
decoded_request = input_class.decode(request.body)
|
77
75
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
attr_hash = decoded_request.to_h
|
82
|
-
normalize = ->{ decoded_request.normalized_hash }
|
83
|
-
else
|
84
|
-
matcher = WebMock::Matchers::HashIncludingMatcher.new(attrs)
|
85
|
-
attr_hash = WebMock::Util::HashKeysStringifier.stringify_keys!(decoded_request.to_h, deep: true)
|
86
|
-
normalize = ->{ decoded_request.normalized_hash(symbolize_keys: false) }
|
87
|
-
end
|
88
|
-
|
89
|
-
matched &= (matcher === attr_hash || matcher === normalize.call)
|
90
|
-
end
|
91
|
-
|
92
|
-
if block
|
93
|
-
matched &= block.call(decoded_request)
|
94
|
-
end
|
76
|
+
matched = true
|
77
|
+
matched &= decoded_request.include?(attrs) if attrs.any?
|
78
|
+
matched &= block.call(decoded_request) if block
|
95
79
|
|
96
80
|
matched
|
97
81
|
end if attrs.any? || block_given?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webmock-twirp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 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-10-
|
11
|
+
date: 2022-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: webmock
|