webmock-twirp 0.1.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +3 -5
- data/lib/webmock/twirp/refinements.rb +60 -4
- data/lib/webmock/twirp/request_stub.rb +4 -20
- data/lib/webmock/twirp/version.rb +1 -1
- data/webmock-twirp.gemspec +2 -0
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b68a561786519f4bf91828a3a01e4ae803e36e03af7fd327af7780ba5da4d838
|
4
|
+
data.tar.gz: 151994b76bc7d4494be3f302f20633a19fdb681a092d4f1d489e694f89d43189
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b764858403de27f0b9cc28a6bddb7c827379308c1619be1b8bcbeff8d1824a3cb1c3f892644ce63c78c2bc4f1331e4fdb4a60eb88713541e0161d899a4ddaa1c
|
7
|
+
data.tar.gz: 43a24c5182e1aab84cbc16897faae7ea54098be328ad07e5754b939c6b89783985c23f1d565db89fa751fb5e1edb719d72a0fef264b64ae1ceadbc877e8b92d0
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
WebMock::Twirp
|
2
2
|
======
|
3
|
+
![Gem](https://img.shields.io/gem/dt/webmock-twirp?style=plastic)
|
4
|
+
[![codecov](https://codecov.io/gh/dpep/webmock-twirp/branch/main/graph/badge.svg)](https://codecov.io/gh/dpep/webmock-twirp)
|
5
|
+
|
3
6
|
Twirp support for [WebMock](https://github.com/bblimke/webmock). All our favorite http request stubbing for Twirp RPCs - message and error serialization done automatically.
|
4
7
|
|
5
8
|
### Install
|
@@ -106,8 +109,3 @@ Yes please :)
|
|
106
109
|
1. Commit your changes (`git commit -am 'awesome new feature'`)
|
107
110
|
1. Push your branch (`git push origin my-feature`)
|
108
111
|
1. Create a Pull Request
|
109
|
-
|
110
|
-
|
111
|
-
----
|
112
|
-
![Gem](https://img.shields.io/gem/dt/webmock-twirp?style=plastic)
|
113
|
-
[![codecov](https://codecov.io/gh/dpep/webmock-twirp/branch/main/graph/badge.svg)](https://codecov.io/gh/dpep/webmock-twirp)
|
@@ -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
|
@@ -21,7 +21,7 @@ module WebMock
|
|
21
21
|
|
22
22
|
if client
|
23
23
|
conn = client.instance_variable_get(:@conn)
|
24
|
-
uri += conn.url_prefix.to_s if conn
|
24
|
+
uri += conn.url_prefix.to_s.chomp("/") if conn
|
25
25
|
end
|
26
26
|
|
27
27
|
if klass
|
@@ -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?
|
data/webmock-twirp.gemspec
CHANGED
@@ -26,6 +26,8 @@ Gem::Specification.new do |s|
|
|
26
26
|
|
27
27
|
s.add_development_dependency "byebug"
|
28
28
|
s.add_development_dependency "codecov"
|
29
|
+
s.add_development_dependency "rack"
|
29
30
|
s.add_development_dependency "rspec"
|
30
31
|
s.add_development_dependency "simplecov"
|
32
|
+
s.add_development_dependency "webrick"
|
31
33
|
end
|
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.1
|
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-10-
|
11
|
+
date: 2022-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: webmock
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rack
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rspec
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +108,20 @@ dependencies:
|
|
94
108
|
- - ">="
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webrick
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
97
125
|
description: Twirp support for WebMock
|
98
126
|
email:
|
99
127
|
executables: []
|