stenotype 0.1.13 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +102 -67
- data/README.md +45 -7
- data/lib/stenotype/adapters/test_adapter.rb +35 -0
- data/lib/stenotype/context_handlers/base.rb +13 -0
- data/lib/stenotype/context_handlers.rb +7 -4
- data/lib/stenotype/test/matchers.rb +145 -0
- data/lib/stenotype/version.rb +1 -1
- data/lib/stenotype.rb +0 -2
- data/stenotype.gemspec +1 -1
- metadata +7 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d3ece86eb9d12287228f0ed169992fe05fe087fa242017f2dd58c25bae90f88c
|
|
4
|
+
data.tar.gz: 0a53db551815f5d2f8dbf97f5c9fe95bd2a55326f8c751a39fcaa18270ab0d2f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1b0b60acc691c11caa719e686aa6378f8142466d441a674681c9b745afbc80d3bfb69e155d66ac99bc75a4333d0d23f275722c54840263009ceebcf8992b56bd
|
|
7
|
+
data.tar.gz: cf5db9b8359d73cb00aec740ae746ae4a435a030c9edc2fef7ea4cbdef3daed16551b5e3d4ac8f2b529dcfa4e9912515d46501ce5608f9869c6cb3f380b78fba
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
### 0.1.16
|
|
4
|
+
* Add rspec matchers to use in client code.
|
|
5
|
+
|
|
6
|
+
### 0.1.15
|
|
7
|
+
* Updates readme.
|
|
8
|
+
|
|
9
|
+
### 0.1.14
|
|
10
|
+
* Allows autodiscovering of the context handlers and Rails development env autoreload.
|
|
11
|
+
|
|
3
12
|
### 0.1.13
|
|
4
13
|
* Removes obsolete rails pre-configuration for the sake of default configuration settings
|
|
5
14
|
|
data/Gemfile.lock
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
stenotype (0.1.
|
|
4
|
+
stenotype (0.1.17)
|
|
5
5
|
activesupport (>= 5.0.0)
|
|
6
|
-
google-cloud-pubsub (~> 1.
|
|
6
|
+
google-cloud-pubsub (~> 1.10.0)
|
|
7
7
|
spicery (>= 0.22.0, < 1.0)
|
|
8
8
|
|
|
9
9
|
GEM
|
|
@@ -50,83 +50,109 @@ GEM
|
|
|
50
50
|
i18n (>= 0.7, < 2)
|
|
51
51
|
minitest (~> 5.1)
|
|
52
52
|
tzinfo (~> 1.1)
|
|
53
|
-
addressable (2.
|
|
53
|
+
addressable (2.8.0)
|
|
54
54
|
public_suffix (>= 2.0.2, < 5.0)
|
|
55
55
|
arel (9.0.0)
|
|
56
|
-
around_the_world (0.
|
|
56
|
+
around_the_world (0.29.0)
|
|
57
57
|
activesupport (>= 5.2.1)
|
|
58
58
|
ast (2.4.0)
|
|
59
59
|
builder (3.2.3)
|
|
60
60
|
coderay (1.1.2)
|
|
61
|
-
collectible (0.
|
|
61
|
+
collectible (0.29.0)
|
|
62
62
|
activesupport (>= 5.2.1)
|
|
63
|
-
short_circu_it (= 0.
|
|
64
|
-
tablesalt (= 0.
|
|
63
|
+
short_circu_it (= 0.29.0)
|
|
64
|
+
tablesalt (= 0.29.0)
|
|
65
65
|
concurrent-ruby (1.1.5)
|
|
66
|
-
conjunction (0.
|
|
66
|
+
conjunction (0.29.0)
|
|
67
67
|
activemodel (>= 5.2.1)
|
|
68
68
|
activesupport (>= 5.2.1)
|
|
69
|
-
|
|
69
|
+
directive (= 0.29.0)
|
|
70
70
|
crass (1.0.5)
|
|
71
71
|
diff-lcs (1.3)
|
|
72
|
-
directive (0.
|
|
72
|
+
directive (0.29.0)
|
|
73
|
+
activemodel (>= 5.2.1)
|
|
73
74
|
activesupport (>= 5.2.1)
|
|
75
|
+
substance (= 0.29.0)
|
|
74
76
|
docile (1.3.2)
|
|
75
77
|
erubi (1.9.0)
|
|
76
|
-
facet (0.
|
|
78
|
+
facet (0.29.0)
|
|
77
79
|
activesupport (>= 5.2.1)
|
|
78
|
-
short_circu_it (= 0.
|
|
79
|
-
tablesalt (= 0.
|
|
80
|
+
short_circu_it (= 0.29.0)
|
|
81
|
+
tablesalt (= 0.29.0)
|
|
80
82
|
faker (1.9.6)
|
|
81
83
|
i18n (>= 0.7)
|
|
82
|
-
faraday (
|
|
83
|
-
|
|
84
|
+
faraday (1.10.0)
|
|
85
|
+
faraday-em_http (~> 1.0)
|
|
86
|
+
faraday-em_synchrony (~> 1.0)
|
|
87
|
+
faraday-excon (~> 1.1)
|
|
88
|
+
faraday-httpclient (~> 1.0)
|
|
89
|
+
faraday-multipart (~> 1.0)
|
|
90
|
+
faraday-net_http (~> 1.0)
|
|
91
|
+
faraday-net_http_persistent (~> 1.0)
|
|
92
|
+
faraday-patron (~> 1.0)
|
|
93
|
+
faraday-rack (~> 1.0)
|
|
94
|
+
faraday-retry (~> 1.0)
|
|
95
|
+
ruby2_keywords (>= 0.0.4)
|
|
96
|
+
faraday-em_http (1.0.0)
|
|
97
|
+
faraday-em_synchrony (1.0.0)
|
|
98
|
+
faraday-excon (1.1.0)
|
|
99
|
+
faraday-httpclient (1.0.1)
|
|
100
|
+
faraday-multipart (1.0.4)
|
|
101
|
+
multipart-post (~> 2)
|
|
102
|
+
faraday-net_http (1.0.1)
|
|
103
|
+
faraday-net_http_persistent (1.2.0)
|
|
104
|
+
faraday-patron (1.0.0)
|
|
105
|
+
faraday-rack (1.0.0)
|
|
106
|
+
faraday-retry (1.0.3)
|
|
84
107
|
github-markup (3.0.4)
|
|
85
108
|
globalid (0.4.2)
|
|
86
109
|
activesupport (>= 4.2.0)
|
|
87
|
-
google-cloud-core (1.
|
|
110
|
+
google-cloud-core (1.6.0)
|
|
88
111
|
google-cloud-env (~> 1.0)
|
|
89
112
|
google-cloud-errors (~> 1.0)
|
|
90
|
-
google-cloud-env (1.
|
|
91
|
-
faraday (
|
|
92
|
-
google-cloud-errors (1.
|
|
93
|
-
google-cloud-pubsub (1.0
|
|
113
|
+
google-cloud-env (1.6.0)
|
|
114
|
+
faraday (>= 0.17.3, < 3.0)
|
|
115
|
+
google-cloud-errors (1.2.0)
|
|
116
|
+
google-cloud-pubsub (1.10.0)
|
|
94
117
|
concurrent-ruby (~> 1.1)
|
|
95
118
|
google-cloud-core (~> 1.2)
|
|
96
|
-
google-gax (~> 1.
|
|
119
|
+
google-gax (~> 1.8)
|
|
97
120
|
googleapis-common-protos (>= 1.3.9, < 2.0)
|
|
121
|
+
googleapis-common-protos-types (>= 1.0.4, < 2.0)
|
|
98
122
|
grpc-google-iam-v1 (~> 0.6.9)
|
|
99
|
-
google-gax (1.8.
|
|
123
|
+
google-gax (1.8.2)
|
|
100
124
|
google-protobuf (~> 3.9)
|
|
101
125
|
googleapis-common-protos (>= 1.3.9, < 2.0)
|
|
126
|
+
googleapis-common-protos-types (>= 1.0.4, < 2.0)
|
|
102
127
|
googleauth (~> 0.9)
|
|
103
128
|
grpc (~> 1.24)
|
|
104
129
|
rly (~> 0.2.3)
|
|
105
|
-
google-protobuf (3.
|
|
106
|
-
googleapis-common-protos (1.3.
|
|
107
|
-
google-protobuf (~> 3.
|
|
108
|
-
googleapis-common-protos-types (~> 1.
|
|
109
|
-
grpc (~> 1.
|
|
110
|
-
googleapis-common-protos-types (1.
|
|
111
|
-
google-protobuf (~> 3.
|
|
112
|
-
googleauth (0.
|
|
130
|
+
google-protobuf (3.21.2)
|
|
131
|
+
googleapis-common-protos (1.3.12)
|
|
132
|
+
google-protobuf (~> 3.14)
|
|
133
|
+
googleapis-common-protos-types (~> 1.2)
|
|
134
|
+
grpc (~> 1.27)
|
|
135
|
+
googleapis-common-protos-types (1.3.2)
|
|
136
|
+
google-protobuf (~> 3.14)
|
|
137
|
+
googleauth (0.17.1)
|
|
113
138
|
faraday (>= 0.17.3, < 2.0)
|
|
114
139
|
jwt (>= 1.4, < 3.0)
|
|
115
140
|
memoist (~> 0.16)
|
|
116
141
|
multi_json (~> 1.11)
|
|
117
142
|
os (>= 0.9, < 2.0)
|
|
118
|
-
signet (~> 0.
|
|
119
|
-
grpc (1.
|
|
120
|
-
google-protobuf (~> 3.
|
|
143
|
+
signet (~> 0.15)
|
|
144
|
+
grpc (1.47.0)
|
|
145
|
+
google-protobuf (~> 3.19)
|
|
121
146
|
googleapis-common-protos-types (~> 1.0)
|
|
122
|
-
grpc-google-iam-v1 (0.6.
|
|
123
|
-
|
|
124
|
-
|
|
147
|
+
grpc-google-iam-v1 (0.6.11)
|
|
148
|
+
google-protobuf (~> 3.14)
|
|
149
|
+
googleapis-common-protos (>= 1.3.11, < 2.0)
|
|
150
|
+
grpc (~> 1.27)
|
|
125
151
|
i18n (1.7.0)
|
|
126
152
|
concurrent-ruby (~> 1.0)
|
|
127
153
|
jaro_winkler (1.5.4)
|
|
128
154
|
json (2.2.0)
|
|
129
|
-
jwt (2.
|
|
155
|
+
jwt (2.4.1)
|
|
130
156
|
loofah (2.4.0)
|
|
131
157
|
crass (~> 1.0.2)
|
|
132
158
|
nokogiri (>= 1.5.9)
|
|
@@ -136,23 +162,25 @@ GEM
|
|
|
136
162
|
mimemagic (~> 0.3.2)
|
|
137
163
|
memoist (0.16.2)
|
|
138
164
|
method_source (0.9.2)
|
|
139
|
-
mimemagic (0.3.
|
|
165
|
+
mimemagic (0.3.10)
|
|
166
|
+
nokogiri (~> 1)
|
|
167
|
+
rake
|
|
140
168
|
mini_mime (1.0.2)
|
|
141
169
|
mini_portile2 (2.4.0)
|
|
142
170
|
minitest (5.13.0)
|
|
143
|
-
multi_json (1.
|
|
144
|
-
multipart-post (2.
|
|
171
|
+
multi_json (1.15.0)
|
|
172
|
+
multipart-post (2.2.3)
|
|
145
173
|
nio4r (2.5.2)
|
|
146
174
|
nokogiri (1.10.7)
|
|
147
175
|
mini_portile2 (~> 2.4.0)
|
|
148
|
-
os (1.
|
|
176
|
+
os (1.1.4)
|
|
149
177
|
parallel (1.19.1)
|
|
150
178
|
parser (2.6.5.0)
|
|
151
179
|
ast (~> 2.4.0)
|
|
152
180
|
pry (0.12.2)
|
|
153
181
|
coderay (~> 1.1.0)
|
|
154
182
|
method_source (~> 0.9.0)
|
|
155
|
-
public_suffix (4.0.
|
|
183
|
+
public_suffix (4.0.7)
|
|
156
184
|
rack (2.0.8)
|
|
157
185
|
rack-test (1.1.0)
|
|
158
186
|
rack (>= 1.0, < 3)
|
|
@@ -183,11 +211,11 @@ GEM
|
|
|
183
211
|
rainbow (3.0.0)
|
|
184
212
|
rake (10.5.0)
|
|
185
213
|
redcarpet (3.5.0)
|
|
186
|
-
redis (4.1
|
|
187
|
-
redis_hash (0.
|
|
214
|
+
redis (4.7.1)
|
|
215
|
+
redis_hash (0.29.0)
|
|
188
216
|
activesupport (>= 5.2.1)
|
|
189
217
|
redis (>= 3.0)
|
|
190
|
-
tablesalt (= 0.
|
|
218
|
+
tablesalt (= 0.29.0)
|
|
191
219
|
rly (0.2.3)
|
|
192
220
|
rspec (3.9.0)
|
|
193
221
|
rspec-core (~> 3.9.0)
|
|
@@ -220,12 +248,13 @@ GEM
|
|
|
220
248
|
rubocop-rspec (1.35.0)
|
|
221
249
|
rubocop (>= 0.60.0)
|
|
222
250
|
ruby-progressbar (1.10.1)
|
|
223
|
-
|
|
251
|
+
ruby2_keywords (0.0.5)
|
|
252
|
+
short_circu_it (0.29.0)
|
|
224
253
|
activesupport (>= 5.2.1)
|
|
225
|
-
around_the_world (= 0.
|
|
226
|
-
signet (0.
|
|
227
|
-
addressable (~> 2.
|
|
228
|
-
faraday (>= 0.17.
|
|
254
|
+
around_the_world (= 0.29.0)
|
|
255
|
+
signet (0.17.0)
|
|
256
|
+
addressable (~> 2.8)
|
|
257
|
+
faraday (>= 0.17.5, < 3.a)
|
|
229
258
|
jwt (>= 1.5, < 3.0)
|
|
230
259
|
multi_json (~> 1.10)
|
|
231
260
|
simplecov (0.17.1)
|
|
@@ -233,23 +262,24 @@ GEM
|
|
|
233
262
|
json (>= 1.8, < 3)
|
|
234
263
|
simplecov-html (~> 0.10.0)
|
|
235
264
|
simplecov-html (0.10.2)
|
|
236
|
-
spicerack (0.
|
|
237
|
-
around_the_world (= 0.
|
|
238
|
-
directive (= 0.
|
|
239
|
-
redis_hash (= 0.
|
|
240
|
-
short_circu_it (= 0.
|
|
241
|
-
|
|
242
|
-
|
|
265
|
+
spicerack (0.29.0)
|
|
266
|
+
around_the_world (= 0.29.0)
|
|
267
|
+
directive (= 0.29.0)
|
|
268
|
+
redis_hash (= 0.29.0)
|
|
269
|
+
short_circu_it (= 0.29.0)
|
|
270
|
+
substance (= 0.29.0)
|
|
271
|
+
tablesalt (= 0.29.0)
|
|
272
|
+
technologic (= 0.29.0)
|
|
243
273
|
spicerack-styleguide (0.19.2)
|
|
244
274
|
rubocop (= 0.74)
|
|
245
275
|
rubocop-performance (= 1.4.1)
|
|
246
276
|
rubocop-rails (= 2.3.0)
|
|
247
277
|
rubocop-rspec (= 1.35.0)
|
|
248
|
-
spicery (0.
|
|
249
|
-
collectible (= 0.
|
|
250
|
-
conjunction (= 0.
|
|
251
|
-
facet (= 0.
|
|
252
|
-
spicerack (= 0.
|
|
278
|
+
spicery (0.29.0)
|
|
279
|
+
collectible (= 0.29.0)
|
|
280
|
+
conjunction (= 0.29.0)
|
|
281
|
+
facet (= 0.29.0)
|
|
282
|
+
spicerack (= 0.29.0)
|
|
253
283
|
sprockets (4.0.0)
|
|
254
284
|
concurrent-ruby (~> 1.0)
|
|
255
285
|
rack (> 1, < 3)
|
|
@@ -257,13 +287,18 @@ GEM
|
|
|
257
287
|
actionpack (>= 4.0)
|
|
258
288
|
activesupport (>= 4.0)
|
|
259
289
|
sprockets (>= 3.0.0)
|
|
260
|
-
|
|
290
|
+
substance (0.29.0)
|
|
291
|
+
activemodel (>= 5.2.1)
|
|
292
|
+
activesupport (>= 5.2.1)
|
|
293
|
+
short_circu_it (= 0.29.0)
|
|
294
|
+
tablesalt (= 0.29.0)
|
|
295
|
+
technologic (= 0.29.0)
|
|
296
|
+
tablesalt (0.29.0)
|
|
261
297
|
activemodel (>= 5.2.1)
|
|
262
298
|
activesupport (>= 5.2.1)
|
|
263
|
-
technologic (0.
|
|
299
|
+
technologic (0.29.0)
|
|
264
300
|
activesupport (>= 5.2.1)
|
|
265
|
-
|
|
266
|
-
short_circu_it (= 0.22.4)
|
|
301
|
+
short_circu_it (= 0.29.0)
|
|
267
302
|
thor (0.20.3)
|
|
268
303
|
thread_safe (0.3.6)
|
|
269
304
|
timecop (0.9.1)
|
|
@@ -294,4 +329,4 @@ DEPENDENCIES
|
|
|
294
329
|
yard (~> 0.9)
|
|
295
330
|
|
|
296
331
|
BUNDLED WITH
|
|
297
|
-
2.
|
|
332
|
+
2.2.31
|
data/README.md
CHANGED
|
@@ -105,7 +105,7 @@ Controls whether the hook `auto_initialize!` is run for each adapter. If set to
|
|
|
105
105
|
|
|
106
106
|
#### Configuring context handlers
|
|
107
107
|
|
|
108
|
-
Each event is emitted in a context which might be an ActionController instance or an ActiveJob instance or potentially any other place. Context handlers are implemented as plain ruby classes
|
|
108
|
+
Each event is emitted in a context which might be an ActionController instance or an ActiveJob instance or potentially any other place. Context handlers are implemented as plain ruby classes. By default a plain `Class` handler is registered when not used with any framework. In case Ruby on Rails is used, then there are two additional context handlers for `ActionController` and `ActiveJob` instances. Registration of the context handler happens upon inheriting from `Stenotype::ContextHandlers::Base`.
|
|
109
109
|
|
|
110
110
|
### Emitting Events
|
|
111
111
|
|
|
@@ -118,7 +118,7 @@ Stenotype::Event.emit!(
|
|
|
118
118
|
)
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
-
The event is then going to be passed to a dispatcher responsible for sending the evens to targets.
|
|
121
|
+
The event is then going to be passed to a dispatcher responsible for sending the evens to targets. See [Custom context handlers](#custom-context-handlers) for more details.
|
|
122
122
|
|
|
123
123
|
#### ActionController
|
|
124
124
|
|
|
@@ -201,8 +201,6 @@ class CustomHandler < Stenotype::ContextHandlers::Base
|
|
|
201
201
|
end
|
|
202
202
|
end
|
|
203
203
|
|
|
204
|
-
Stenotype::ContextHandlers.register CustomHandler
|
|
205
|
-
|
|
206
204
|
# Event is being emitted twice. First time with default options.
|
|
207
205
|
# Second time with overriden method name and eval_context.
|
|
208
206
|
class PlainRubyClass < BaseClass
|
|
@@ -251,7 +249,7 @@ Stenotype.config.targets.push(CustomAdapter.new)
|
|
|
251
249
|
|
|
252
250
|
#### Custom context handlers
|
|
253
251
|
|
|
254
|
-
A list of context handlers might be extended by defining a class inheriting from `Stenotype::ContextHandlers::Base
|
|
252
|
+
A list of context handlers might be extended by defining a class inheriting from `Stenotype::ContextHandlers::Base`. Event handler must have a `self.handler_name` in order to use it during context serialization. Also custom handler must implement method `#as_json`:
|
|
255
253
|
```ruby
|
|
256
254
|
class CustomHandler < Stenotype::ContextHandlers::Base
|
|
257
255
|
self.handler_name = :custom_handler_name
|
|
@@ -275,9 +273,49 @@ class CustomHandler < Stenotype::ContextHandlers::Base
|
|
|
275
273
|
end
|
|
276
274
|
```
|
|
277
275
|
|
|
278
|
-
|
|
276
|
+
You do not have to manually register the context handler since it happens upon inheriting from `Stenotype::ContextHandlers::Base`
|
|
277
|
+
|
|
278
|
+
## Testing
|
|
279
|
+
|
|
280
|
+
Stenotype currently supports RSpec integration. To be able to test even emission you can use a predefined matcher by adding the following to spec helper:
|
|
281
|
+
|
|
282
|
+
```ruby
|
|
283
|
+
RSpec.configure do |config|
|
|
284
|
+
config.around(:each, type: :stenotype_event) do |example|
|
|
285
|
+
require 'stenotype/adapters/test_adapter'
|
|
286
|
+
|
|
287
|
+
config.include Stenotype::Test::Matchers
|
|
288
|
+
|
|
289
|
+
RSpec::Mocks.with_temporary_scope do
|
|
290
|
+
allow(Stenotype.config).to receive(:targets).and_return(Array.wrap(Stenotype::Adapters::TestAdapter.new))
|
|
291
|
+
example.run
|
|
292
|
+
allow(Stenotype.config).to receive(:targets).and_call_original
|
|
293
|
+
end
|
|
294
|
+
end
|
|
295
|
+
end
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
After adding the configuration you can use the matchers:
|
|
279
299
|
```ruby
|
|
280
|
-
|
|
300
|
+
class Example
|
|
301
|
+
include Stenotype::Emitter
|
|
302
|
+
|
|
303
|
+
def trigger
|
|
304
|
+
emit_event(:user_subscription)
|
|
305
|
+
end
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
RSpec.describe Stenotype::Emitter do
|
|
309
|
+
describe "POST #create" do
|
|
310
|
+
subject(:post) { Example.new.trigger }
|
|
311
|
+
|
|
312
|
+
it "emits a user_subscription event", type: :stenotype_event do
|
|
313
|
+
expect { post }.to emit_an_event(:user_subscription).
|
|
314
|
+
with_arguments_including({ uuid: "abcd" }).
|
|
315
|
+
exactly(1).times
|
|
316
|
+
end
|
|
317
|
+
end
|
|
318
|
+
end
|
|
281
319
|
```
|
|
282
320
|
|
|
283
321
|
## Development
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Stenotype
|
|
4
|
+
module Adapters
|
|
5
|
+
class TestAdapter < Base
|
|
6
|
+
attr_reader :buffer
|
|
7
|
+
|
|
8
|
+
def initialize(*_)
|
|
9
|
+
@buffer = Array.new
|
|
10
|
+
super()
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
#
|
|
14
|
+
# @param event_data {Sting} The data to be published
|
|
15
|
+
# @param additional_attrs {Hash} The list of additional event attributes
|
|
16
|
+
#
|
|
17
|
+
def publish(event_data, **additional_attrs)
|
|
18
|
+
buffer << parse(event_data)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
#
|
|
22
|
+
# Clears the buffer
|
|
23
|
+
#
|
|
24
|
+
def flush!
|
|
25
|
+
buffer.clear
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def parse(event_data)
|
|
31
|
+
JSON.parse(event_data)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -24,6 +24,10 @@ module Stenotype
|
|
|
24
24
|
class Base
|
|
25
25
|
attr_reader :context, :options
|
|
26
26
|
|
|
27
|
+
def self.inherited(subklass)
|
|
28
|
+
ContextHandlers.register(subklass)
|
|
29
|
+
end
|
|
30
|
+
|
|
27
31
|
#
|
|
28
32
|
# @param context {Object} A context where the event was emitted
|
|
29
33
|
# @param options {Hash} A hash of additional options
|
|
@@ -58,6 +62,15 @@ module Stenotype
|
|
|
58
62
|
@handler_name || raise(NotImplementedError, "Please, specify the handler_name of #{self}")
|
|
59
63
|
end
|
|
60
64
|
end
|
|
65
|
+
|
|
66
|
+
private
|
|
67
|
+
|
|
68
|
+
#
|
|
69
|
+
# A rails specific workaround to make reloading in dev env happy
|
|
70
|
+
#
|
|
71
|
+
def self.before_remove_const
|
|
72
|
+
Stenotype::ContextHandlers.known.unregister(self)
|
|
73
|
+
end
|
|
61
74
|
end
|
|
62
75
|
end
|
|
63
76
|
end
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "stenotype/context_handlers/base"
|
|
4
|
-
require "stenotype/context_handlers/rails/controller"
|
|
5
|
-
require "stenotype/context_handlers/rails/active_job"
|
|
6
|
-
require "stenotype/context_handlers/klass"
|
|
7
3
|
require "stenotype/context_handlers/collection"
|
|
8
4
|
|
|
9
5
|
module Stenotype
|
|
@@ -14,6 +10,7 @@ module Stenotype
|
|
|
14
10
|
module ContextHandlers
|
|
15
11
|
class << self
|
|
16
12
|
attr_writer :known
|
|
13
|
+
|
|
17
14
|
#
|
|
18
15
|
# @return {Array<#publish>} A list of handlers implementing [#publish]
|
|
19
16
|
#
|
|
@@ -28,3 +25,9 @@ module Stenotype
|
|
|
28
25
|
end
|
|
29
26
|
end
|
|
30
27
|
end
|
|
28
|
+
|
|
29
|
+
require "stenotype/context_handlers/base"
|
|
30
|
+
require "stenotype/context_handlers/rails/controller"
|
|
31
|
+
require "stenotype/context_handlers/rails/active_job"
|
|
32
|
+
require "stenotype/context_handlers/klass"
|
|
33
|
+
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
module Stenotype
|
|
5
|
+
module Test
|
|
6
|
+
module Matchers
|
|
7
|
+
extend RSpec::Matchers::DSL
|
|
8
|
+
|
|
9
|
+
class DiffSizeMatchesExpectation
|
|
10
|
+
attr_reader :matching_events, :expected_count
|
|
11
|
+
|
|
12
|
+
def initialize(matching_events, expected_count)
|
|
13
|
+
@matching_events = matching_events
|
|
14
|
+
@expected_count = expected_count
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def failure_message
|
|
18
|
+
"expected to see #{expected_count} event(s) but got #{matching_events.count} event(s)."
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def matches?
|
|
22
|
+
matching_events.count == expected_count
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
class EventHasExpectedArguments
|
|
27
|
+
attr_reader :matching_events, :expected_arguments
|
|
28
|
+
|
|
29
|
+
def initialize(matching_events, expected_arguments)
|
|
30
|
+
@matching_events = matching_events
|
|
31
|
+
@expected_arguments = stringify_keys(expected_arguments)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def matches?
|
|
35
|
+
return false if multiple_events?
|
|
36
|
+
|
|
37
|
+
(expected_arguments.to_a - matching_event.to_a).empty?
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def failure_message
|
|
41
|
+
if multiple_events?
|
|
42
|
+
"more than one event with given event name has been emitted. Can not match event arguments"
|
|
43
|
+
else
|
|
44
|
+
"expected to see all attributes from #{expected_arguments} to be included in event attributes but got #{matching_event}"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
def multiple_events?
|
|
51
|
+
matching_events.size > 1
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def matching_event
|
|
55
|
+
matching_events.first
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def stringify_keys(hash)
|
|
59
|
+
hash.transform_keys(&:to_s)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
class EventEmitted
|
|
64
|
+
attr_reader :matching_events, :expected_event_name
|
|
65
|
+
|
|
66
|
+
def initialize(matching_events, expected_event_name)
|
|
67
|
+
@matching_events = matching_events
|
|
68
|
+
@expected_event_name = expected_event_name
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def matches?
|
|
72
|
+
matching_events.any?
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def failure_message
|
|
76
|
+
"expected to see a '#{expected_event_name}' event but got nothing"
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
matcher :emit_an_event do |expected_event_name, *_|
|
|
81
|
+
supports_block_expectations
|
|
82
|
+
|
|
83
|
+
match do |emitting_event_block|
|
|
84
|
+
@emitting_event_block = emitting_event_block
|
|
85
|
+
|
|
86
|
+
partial_matchers << EventEmitted.new(matching_events, expected_event_name)
|
|
87
|
+
partial_matchers << EventHasExpectedArguments.new(matching_events, @arguments_should_include) if should_validate_events_count?
|
|
88
|
+
partial_matchers << DiffSizeMatchesExpectation.new(matching_events, @matching_events_count) if should_validate_attributes?
|
|
89
|
+
|
|
90
|
+
return first_failure.nil?
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
chain(:with_arguments_including) { |**args| @arguments_should_include = args }
|
|
94
|
+
chain(:exactly) { |times| @matching_events_count = times }
|
|
95
|
+
|
|
96
|
+
# noop for syntatic sugar
|
|
97
|
+
chain(:times) {}
|
|
98
|
+
chain(:time) {}
|
|
99
|
+
|
|
100
|
+
def matching_events
|
|
101
|
+
@matching_events ||= begin
|
|
102
|
+
buffer_before_emit = stenotype_event_buffer.dup
|
|
103
|
+
@emitting_event_block.call
|
|
104
|
+
buffer_after_emit = stenotype_event_buffer.dup
|
|
105
|
+
|
|
106
|
+
diff = buffer_after_emit - buffer_before_emit
|
|
107
|
+
diff.select { |event| event["name"] == expected_event_name.to_s }
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def partial_matchers
|
|
112
|
+
@partial_matchers ||= []
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def first_failure
|
|
116
|
+
@first_failure ||= partial_matchers.detect { |matcher| !matcher.matches? }
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
failure_message do
|
|
120
|
+
return super() unless first_failure
|
|
121
|
+
|
|
122
|
+
first_failure.failure_message
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
private
|
|
126
|
+
|
|
127
|
+
def should_validate_events_count?
|
|
128
|
+
@matching_events_count.present?
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def should_validate_attributes?
|
|
132
|
+
@arguments_should_include.present?
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def stenotype_event_buffer
|
|
136
|
+
stenotype_event_target.buffer
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def stenotype_event_target
|
|
140
|
+
Stenotype.config.targets.first
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
data/lib/stenotype/version.rb
CHANGED
data/lib/stenotype.rb
CHANGED
data/stenotype.gemspec
CHANGED
|
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
|
|
|
30
30
|
spec.require_paths = ["lib"]
|
|
31
31
|
|
|
32
32
|
spec.add_dependency "activesupport", ">= 5.0.0"
|
|
33
|
-
spec.add_dependency "google-cloud-pubsub", "~> 1.
|
|
33
|
+
spec.add_dependency "google-cloud-pubsub", "~> 1.10.0"
|
|
34
34
|
|
|
35
35
|
spec.add_runtime_dependency "spicery", ">= 0.22.0", "< 1.0"
|
|
36
36
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: stenotype
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.17
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Roman Kapitonov
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-07-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -30,14 +30,14 @@ dependencies:
|
|
|
30
30
|
requirements:
|
|
31
31
|
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: 1.
|
|
33
|
+
version: 1.10.0
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: 1.
|
|
40
|
+
version: 1.10.0
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: spicery
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -268,6 +268,7 @@ files:
|
|
|
268
268
|
- lib/stenotype/adapters/base.rb
|
|
269
269
|
- lib/stenotype/adapters/google_cloud.rb
|
|
270
270
|
- lib/stenotype/adapters/stdout_adapter.rb
|
|
271
|
+
- lib/stenotype/adapters/test_adapter.rb
|
|
271
272
|
- lib/stenotype/at_exit.rb
|
|
272
273
|
- lib/stenotype/configuration.rb
|
|
273
274
|
- lib/stenotype/context_handlers.rb
|
|
@@ -283,6 +284,7 @@ files:
|
|
|
283
284
|
- lib/stenotype/frameworks/rails/action_controller.rb
|
|
284
285
|
- lib/stenotype/frameworks/rails/active_job.rb
|
|
285
286
|
- lib/stenotype/railtie.rb
|
|
287
|
+
- lib/stenotype/test/matchers.rb
|
|
286
288
|
- lib/stenotype/version.rb
|
|
287
289
|
- stenotype.gemspec
|
|
288
290
|
homepage: https://github.com/Freshly/stenotype
|
|
@@ -307,7 +309,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
307
309
|
- !ruby/object:Gem::Version
|
|
308
310
|
version: '0'
|
|
309
311
|
requirements: []
|
|
310
|
-
rubygems_version: 3.
|
|
312
|
+
rubygems_version: 3.1.6
|
|
311
313
|
signing_key:
|
|
312
314
|
specification_version: 4
|
|
313
315
|
summary: Gem for emitting events and sending them to an external system.
|