stenotype 0.1.9 → 0.1.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rspec.yml +41 -0
- data/CHANGELOG.md +26 -1
- data/Gemfile.lock +44 -37
- data/README.md +45 -7
- data/lib/stenotype.rb +1 -3
- data/lib/stenotype/adapters/stdout_adapter.rb +5 -1
- data/lib/stenotype/adapters/test_adapter.rb +35 -0
- data/lib/stenotype/configuration.rb +3 -1
- data/lib/stenotype/context_handlers.rb +7 -4
- data/lib/stenotype/context_handlers/base.rb +13 -0
- data/lib/stenotype/railtie.rb +0 -7
- data/lib/stenotype/test/matchers.rb +145 -0
- data/lib/stenotype/version.rb +1 -1
- data/stenotype.gemspec +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31a64803c8b2a343a441ce48a26d5b14e5aa55792d718fe2afb236f0589507ca
|
4
|
+
data.tar.gz: 999e4ae1554d49663ac4b8e8cecd94507cde51cfa494c28ebf21fab4240eb41a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a001057b435a76475cb49deb9a73601c2144a3468578d0a68f188ccad85598678a0b5909cd3f32f31b8b04bda42c284b8cb5d54b7423663a79beefb6afcaaf61
|
7
|
+
data.tar.gz: a3f20a7345504675073ad48b48fd3dfb73018bd3d65d1855a28e0224a61a1a9274aaf39bfa483de465b95a82915a616f7c9987986be28a7c3d1f2f1992f3c6d3
|
@@ -0,0 +1,41 @@
|
|
1
|
+
name: RSpec
|
2
|
+
|
3
|
+
on: push
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
strategy:
|
9
|
+
matrix:
|
10
|
+
ruby:
|
11
|
+
- "2.6.x"
|
12
|
+
rails:
|
13
|
+
- "5.2.0"
|
14
|
+
- "6.0.0"
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v1
|
18
|
+
- uses: actions/cache@v1
|
19
|
+
with:
|
20
|
+
path: vendor/bundle
|
21
|
+
key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.rails }}-${{ hashFiles('**/Gemfile.lock') }}
|
22
|
+
restore-keys: |
|
23
|
+
${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.rails }}
|
24
|
+
- name: Set up Ruby ${{ matrix.ruby }}
|
25
|
+
uses: actions/setup-ruby@v1
|
26
|
+
with:
|
27
|
+
ruby-version: ${{ matrix.ruby }}
|
28
|
+
- name: Apply Rails ${{ matrix.rails }} dependencies
|
29
|
+
run: |
|
30
|
+
echo "gem 'rails', '~> ${{ matrix.rails }}'" >> Gemfile
|
31
|
+
- name: Set up dependencies
|
32
|
+
env:
|
33
|
+
BUNDLE_GEM__FURY__IO: ${{ secrets.GEMFURY_DEPLOY_TOKEN }}
|
34
|
+
run: |
|
35
|
+
gem install bundler
|
36
|
+
bundle config path vendor/bundle
|
37
|
+
bundle update rails --jobs 4 --retry 3
|
38
|
+
bundle install --jobs 4 --retry 3
|
39
|
+
- name: Run RSpec
|
40
|
+
run: |
|
41
|
+
bundle exec rspec
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,31 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
|
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
|
+
|
12
|
+
### 0.1.13
|
13
|
+
* Removes obsolete rails pre-configuration for the sake of default configuration settings
|
14
|
+
|
15
|
+
### 0.1.12
|
16
|
+
* Delegates STDOUT adapter to configured logger first. If logger is not set, delegates the output to STDOUT
|
17
|
+
|
18
|
+
### 0.1.11
|
19
|
+
* Removes the annoying warnings in logs
|
20
|
+
|
21
|
+
### 0.1.10
|
22
|
+
Switch from Spicerack::Configurable to Spicerack::Directive
|
23
|
+
|
24
|
+
### 0.1.9
|
25
|
+
* Pass all attributes in the data field instead of attributes field for google cloud. Attributes field did not allow nested objects, which data field allows. See google pub sub documentation for more reference.
|
26
|
+
|
27
|
+
### 0.1.8
|
28
|
+
* Switch auto target initialization to false
|
4
29
|
|
5
30
|
### 0.1.7 2020/01/20
|
6
31
|
* Adds a config option to allow explicit adapter setup.
|
data/Gemfile.lock
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
stenotype (0.1.
|
4
|
+
stenotype (0.1.15)
|
5
5
|
activesupport (>= 5.0.0)
|
6
6
|
google-cloud-pubsub (~> 1.0.0)
|
7
|
-
spicery (>= 0.
|
7
|
+
spicery (>= 0.22.0, < 1.0)
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
@@ -53,26 +53,30 @@ GEM
|
|
53
53
|
addressable (2.7.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.22.4)
|
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.22.4)
|
62
62
|
activesupport (>= 5.2.1)
|
63
|
-
short_circu_it (= 0.
|
64
|
-
tablesalt (= 0.
|
63
|
+
short_circu_it (= 0.22.4)
|
64
|
+
tablesalt (= 0.22.4)
|
65
65
|
concurrent-ruby (1.1.5)
|
66
|
-
conjunction (0.
|
66
|
+
conjunction (0.22.4)
|
67
|
+
activemodel (>= 5.2.1)
|
67
68
|
activesupport (>= 5.2.1)
|
69
|
+
spicerack (= 0.22.4)
|
68
70
|
crass (1.0.5)
|
69
71
|
diff-lcs (1.3)
|
72
|
+
directive (0.22.4)
|
73
|
+
activesupport (>= 5.2.1)
|
70
74
|
docile (1.3.2)
|
71
75
|
erubi (1.9.0)
|
72
|
-
facet (0.
|
76
|
+
facet (0.22.4)
|
73
77
|
activesupport (>= 5.2.1)
|
74
|
-
short_circu_it (= 0.
|
75
|
-
tablesalt (= 0.
|
78
|
+
short_circu_it (= 0.22.4)
|
79
|
+
tablesalt (= 0.22.4)
|
76
80
|
faker (1.9.6)
|
77
81
|
i18n (>= 0.7)
|
78
82
|
faraday (0.17.3)
|
@@ -80,10 +84,12 @@ GEM
|
|
80
84
|
github-markup (3.0.4)
|
81
85
|
globalid (0.4.2)
|
82
86
|
activesupport (>= 4.2.0)
|
83
|
-
google-cloud-core (1.
|
87
|
+
google-cloud-core (1.5.0)
|
84
88
|
google-cloud-env (~> 1.0)
|
89
|
+
google-cloud-errors (~> 1.0)
|
85
90
|
google-cloud-env (1.3.0)
|
86
91
|
faraday (~> 0.11)
|
92
|
+
google-cloud-errors (1.0.0)
|
87
93
|
google-cloud-pubsub (1.0.2)
|
88
94
|
concurrent-ruby (~> 1.1)
|
89
95
|
google-cloud-core (~> 1.2)
|
@@ -96,22 +102,22 @@ GEM
|
|
96
102
|
googleauth (~> 0.9)
|
97
103
|
grpc (~> 1.24)
|
98
104
|
rly (~> 0.2.3)
|
99
|
-
google-protobuf (3.11.
|
105
|
+
google-protobuf (3.11.4-universal-darwin)
|
100
106
|
googleapis-common-protos (1.3.9)
|
101
107
|
google-protobuf (~> 3.0)
|
102
108
|
googleapis-common-protos-types (~> 1.0)
|
103
109
|
grpc (~> 1.0)
|
104
110
|
googleapis-common-protos-types (1.0.4)
|
105
111
|
google-protobuf (~> 3.0)
|
106
|
-
googleauth (0.
|
107
|
-
faraday (
|
112
|
+
googleauth (0.11.0)
|
113
|
+
faraday (>= 0.17.3, < 2.0)
|
108
114
|
jwt (>= 1.4, < 3.0)
|
109
115
|
memoist (~> 0.16)
|
110
116
|
multi_json (~> 1.11)
|
111
117
|
os (>= 0.9, < 2.0)
|
112
118
|
signet (~> 0.12)
|
113
|
-
grpc (1.
|
114
|
-
google-protobuf (~> 3.
|
119
|
+
grpc (1.27.0-universal-darwin)
|
120
|
+
google-protobuf (~> 3.11)
|
115
121
|
googleapis-common-protos-types (~> 1.0)
|
116
122
|
grpc-google-iam-v1 (0.6.9)
|
117
123
|
googleapis-common-protos (>= 1.3.1, < 2.0)
|
@@ -146,7 +152,7 @@ GEM
|
|
146
152
|
pry (0.12.2)
|
147
153
|
coderay (~> 1.1.0)
|
148
154
|
method_source (~> 0.9.0)
|
149
|
-
public_suffix (4.0.
|
155
|
+
public_suffix (4.0.3)
|
150
156
|
rack (2.0.8)
|
151
157
|
rack-test (1.1.0)
|
152
158
|
rack (>= 1.0, < 3)
|
@@ -178,10 +184,10 @@ GEM
|
|
178
184
|
rake (10.5.0)
|
179
185
|
redcarpet (3.5.0)
|
180
186
|
redis (4.1.3)
|
181
|
-
redis_hash (0.
|
187
|
+
redis_hash (0.22.4)
|
182
188
|
activesupport (>= 5.2.1)
|
183
189
|
redis (>= 3.0)
|
184
|
-
tablesalt (= 0.
|
190
|
+
tablesalt (= 0.22.4)
|
185
191
|
rly (0.2.3)
|
186
192
|
rspec (3.9.0)
|
187
193
|
rspec-core (~> 3.9.0)
|
@@ -214,12 +220,12 @@ GEM
|
|
214
220
|
rubocop-rspec (1.35.0)
|
215
221
|
rubocop (>= 0.60.0)
|
216
222
|
ruby-progressbar (1.10.1)
|
217
|
-
short_circu_it (0.
|
223
|
+
short_circu_it (0.22.4)
|
218
224
|
activesupport (>= 5.2.1)
|
219
|
-
around_the_world (= 0.
|
220
|
-
signet (0.
|
225
|
+
around_the_world (= 0.22.4)
|
226
|
+
signet (0.13.0)
|
221
227
|
addressable (~> 2.3)
|
222
|
-
faraday (
|
228
|
+
faraday (>= 0.17.3, < 2.0)
|
223
229
|
jwt (>= 1.5, < 3.0)
|
224
230
|
multi_json (~> 1.10)
|
225
231
|
simplecov (0.17.1)
|
@@ -227,22 +233,23 @@ GEM
|
|
227
233
|
json (>= 1.8, < 3)
|
228
234
|
simplecov-html (~> 0.10.0)
|
229
235
|
simplecov-html (0.10.2)
|
230
|
-
spicerack (0.
|
231
|
-
around_the_world (= 0.
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
+
spicerack (0.22.4)
|
237
|
+
around_the_world (= 0.22.4)
|
238
|
+
directive (= 0.22.4)
|
239
|
+
redis_hash (= 0.22.4)
|
240
|
+
short_circu_it (= 0.22.4)
|
241
|
+
tablesalt (= 0.22.4)
|
242
|
+
technologic (= 0.22.4)
|
236
243
|
spicerack-styleguide (0.19.2)
|
237
244
|
rubocop (= 0.74)
|
238
245
|
rubocop-performance (= 1.4.1)
|
239
246
|
rubocop-rails (= 2.3.0)
|
240
247
|
rubocop-rspec (= 1.35.0)
|
241
|
-
spicery (0.
|
242
|
-
collectible (= 0.
|
243
|
-
conjunction (= 0.
|
244
|
-
facet (= 0.
|
245
|
-
spicerack (= 0.
|
248
|
+
spicery (0.22.4)
|
249
|
+
collectible (= 0.22.4)
|
250
|
+
conjunction (= 0.22.4)
|
251
|
+
facet (= 0.22.4)
|
252
|
+
spicerack (= 0.22.4)
|
246
253
|
sprockets (4.0.0)
|
247
254
|
concurrent-ruby (~> 1.0)
|
248
255
|
rack (> 1, < 3)
|
@@ -250,13 +257,13 @@ GEM
|
|
250
257
|
actionpack (>= 4.0)
|
251
258
|
activesupport (>= 4.0)
|
252
259
|
sprockets (>= 3.0.0)
|
253
|
-
tablesalt (0.
|
260
|
+
tablesalt (0.22.4)
|
254
261
|
activemodel (>= 5.2.1)
|
255
262
|
activesupport (>= 5.2.1)
|
256
|
-
technologic (0.
|
263
|
+
technologic (0.22.4)
|
257
264
|
activesupport (>= 5.2.1)
|
258
265
|
railties (>= 5.2.1)
|
259
|
-
short_circu_it (= 0.
|
266
|
+
short_circu_it (= 0.22.4)
|
260
267
|
thor (0.20.3)
|
261
268
|
thread_safe (0.3.6)
|
262
269
|
timecop (0.9.1)
|
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
|
data/lib/stenotype.rb
CHANGED
@@ -28,10 +28,8 @@ module Stenotype
|
|
28
28
|
# has never been registered in known handlers in {Stenotype::ContextHandlers::Collection}.
|
29
29
|
class UnknownHandlerError < Error; end
|
30
30
|
|
31
|
-
include
|
31
|
+
include Directive::ConfigDelegation
|
32
32
|
delegates_to_configuration
|
33
33
|
end
|
34
34
|
|
35
|
-
Stenotype::ContextHandlers.register(Stenotype::ContextHandlers::Klass)
|
36
|
-
|
37
35
|
require "stenotype/railtie" if defined?(Rails)
|
@@ -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
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "directive"
|
4
|
+
|
3
5
|
module Stenotype
|
4
6
|
#
|
5
7
|
# A module containing freshly-event gem configuration
|
@@ -24,7 +26,7 @@ module Stenotype
|
|
24
26
|
# end
|
25
27
|
#
|
26
28
|
module Configuration
|
27
|
-
extend
|
29
|
+
extend Directive
|
28
30
|
|
29
31
|
# @!attribute graceful_error_handling
|
30
32
|
# @return {true, false} a flag for suppressing error raised withing the gem
|
@@ -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
|
+
|
@@ -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
|
data/lib/stenotype/railtie.rb
CHANGED
@@ -9,13 +9,6 @@ module Stenotype
|
|
9
9
|
# Stenotype extensions for emitting event in various Rails components.
|
10
10
|
#
|
11
11
|
class Railtie < ::Rails::Railtie
|
12
|
-
Stenotype.configure do |config|
|
13
|
-
config.rails do |rails_config|
|
14
|
-
rails_config.enable_action_controller_ext = true
|
15
|
-
rails_config.enable_active_job_ext = true
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
12
|
config.stenotype = Stenotype.config
|
20
13
|
|
21
14
|
config.after_initialize { config.stenotype.targets.each(&:auto_initialize!) } if config.stenotype.rails.auto_adapter_initialization
|
@@ -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/stenotype.gemspec
CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_dependency "activesupport", ">= 5.0.0"
|
33
33
|
spec.add_dependency "google-cloud-pubsub", "~> 1.0.0"
|
34
34
|
|
35
|
-
spec.add_runtime_dependency "spicery", ">= 0.
|
35
|
+
spec.add_runtime_dependency "spicery", ">= 0.22.0", "< 1.0"
|
36
36
|
|
37
37
|
spec.add_development_dependency "bundler", "~> 2.0"
|
38
38
|
spec.add_development_dependency "github-markup", "~> 3.0"
|
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.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Kapitonov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 0.22.0
|
48
48
|
- - "<"
|
49
49
|
- !ruby/object:Gem::Version
|
50
50
|
version: '1.0'
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
requirements:
|
55
55
|
- - ">="
|
56
56
|
- !ruby/object:Gem::Version
|
57
|
-
version: 0.
|
57
|
+
version: 0.22.0
|
58
58
|
- - "<"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '1.0'
|
@@ -245,6 +245,7 @@ executables: []
|
|
245
245
|
extensions: []
|
246
246
|
extra_rdoc_files: []
|
247
247
|
files:
|
248
|
+
- ".github/workflows/rspec.yml"
|
248
249
|
- ".gitignore"
|
249
250
|
- ".rspec"
|
250
251
|
- ".rubocop.yml"
|
@@ -267,6 +268,7 @@ files:
|
|
267
268
|
- lib/stenotype/adapters/base.rb
|
268
269
|
- lib/stenotype/adapters/google_cloud.rb
|
269
270
|
- lib/stenotype/adapters/stdout_adapter.rb
|
271
|
+
- lib/stenotype/adapters/test_adapter.rb
|
270
272
|
- lib/stenotype/at_exit.rb
|
271
273
|
- lib/stenotype/configuration.rb
|
272
274
|
- lib/stenotype/context_handlers.rb
|
@@ -282,6 +284,7 @@ files:
|
|
282
284
|
- lib/stenotype/frameworks/rails/action_controller.rb
|
283
285
|
- lib/stenotype/frameworks/rails/active_job.rb
|
284
286
|
- lib/stenotype/railtie.rb
|
287
|
+
- lib/stenotype/test/matchers.rb
|
285
288
|
- lib/stenotype/version.rb
|
286
289
|
- stenotype.gemspec
|
287
290
|
homepage: https://github.com/Freshly/stenotype
|