ears 0.22.1 → 0.23.0
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/.github/workflows/build.yml +3 -3
- data/.github/workflows/codeql.yml +4 -4
- data/.github/workflows/dependency-review.yml +1 -1
- data/.tool-versions +1 -1
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +20 -23
- data/README.md +77 -0
- data/lib/ears/publisher_channel_pool.rb +28 -2
- data/lib/ears/publisher_retry_handler.rb +1 -1
- data/lib/ears/testing/matchers.rb +43 -0
- data/lib/ears/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 47ba90195072b718e5d0b371dfa46500416c466522ee035aaca493453556d3a6
|
|
4
|
+
data.tar.gz: 5d2d73b8503c82553c8f070b0fcf24b9b8843179f8fedec1f089b8cfc5aaa5c7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e97b11468d7d90d10147c3ac327149cd1333e4684439c1f1b587a4e6765357857fa4d96c37f3df486dfbeb536515ab198e46139c36c13e8354334f45e5f45ada
|
|
7
|
+
data.tar.gz: d042ae7b9a0a0460c085b2b617e2671a3dea383197588ece367e9ecc60bb0cf5b4a39a2ad027aa38f346f1c3c35131d4e6f900330dcd3e83fb6516a7ca68e298
|
data/.github/workflows/build.yml
CHANGED
|
@@ -15,13 +15,13 @@ jobs:
|
|
|
15
15
|
ruby-version: ['3.2', '3.3', '3.4']
|
|
16
16
|
|
|
17
17
|
steps:
|
|
18
|
-
- uses: actions/checkout@
|
|
18
|
+
- uses: actions/checkout@v5
|
|
19
19
|
- name: Set up Ruby
|
|
20
20
|
uses: ruby/setup-ruby@v1
|
|
21
21
|
with:
|
|
22
22
|
ruby-version: ${{ matrix.ruby-version }}
|
|
23
23
|
bundler-cache: true
|
|
24
|
-
- uses: actions/setup-node@
|
|
24
|
+
- uses: actions/setup-node@v6
|
|
25
25
|
with:
|
|
26
26
|
node-version: '24'
|
|
27
27
|
- name: Run prettier
|
|
@@ -37,7 +37,7 @@ jobs:
|
|
|
37
37
|
runs-on: ubuntu-latest
|
|
38
38
|
|
|
39
39
|
steps:
|
|
40
|
-
- uses: actions/checkout@
|
|
40
|
+
- uses: actions/checkout@v5
|
|
41
41
|
- name: Set up Ruby
|
|
42
42
|
uses: ruby/setup-ruby@v1
|
|
43
43
|
with:
|
|
@@ -41,11 +41,11 @@ jobs:
|
|
|
41
41
|
|
|
42
42
|
steps:
|
|
43
43
|
- name: Checkout repository
|
|
44
|
-
uses: actions/checkout@
|
|
44
|
+
uses: actions/checkout@v5
|
|
45
45
|
|
|
46
46
|
# Initializes the CodeQL tools for scanning.
|
|
47
47
|
- name: Initialize CodeQL
|
|
48
|
-
uses: github/codeql-action/init@
|
|
48
|
+
uses: github/codeql-action/init@v4
|
|
49
49
|
with:
|
|
50
50
|
languages: ${{ matrix.language }}
|
|
51
51
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
|
@@ -58,7 +58,7 @@ jobs:
|
|
|
58
58
|
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
|
|
59
59
|
# If this step fails, then you should remove it and run the build manually (see below)
|
|
60
60
|
- name: Autobuild
|
|
61
|
-
uses: github/codeql-action/autobuild@
|
|
61
|
+
uses: github/codeql-action/autobuild@v4
|
|
62
62
|
|
|
63
63
|
# ℹ️ Command-line programs to run using the OS shell.
|
|
64
64
|
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
|
|
@@ -71,6 +71,6 @@ jobs:
|
|
|
71
71
|
# ./location_of_script_within_repo/buildscript.sh
|
|
72
72
|
|
|
73
73
|
- name: Perform CodeQL Analysis
|
|
74
|
-
uses: github/codeql-action/analyze@
|
|
74
|
+
uses: github/codeql-action/analyze@v4
|
|
75
75
|
with:
|
|
76
76
|
category: '/language:${{matrix.language}}'
|
data/.tool-versions
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
ruby 3.2.9
|
|
2
|
-
nodejs 24.
|
|
2
|
+
nodejs 24.8.0
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.23.0 (2025-11-06)
|
|
4
|
+
|
|
5
|
+
- Add `have_been_published` rspec matcher
|
|
6
|
+
|
|
7
|
+
## 0.22.2 (2025-09-19)
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- Publisher now proactively detects and recovers from closed channels before attempting to publish, preventing `Bunny::ChannelAlreadyClosed` errors when channels are closed by RabbitMQ (e.g., due to missing queues or other channel-level errors)
|
|
12
|
+
|
|
3
13
|
## 0.22.1 (2025-09-11)
|
|
4
14
|
|
|
5
15
|
- Add optional `routing_key_match` parameter to `#published_messages` in `Ears::Testing::TestHelper`
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
ears (0.
|
|
4
|
+
ears (0.23.0)
|
|
5
5
|
bunny (>= 2.22.0)
|
|
6
6
|
connection_pool (~> 2.4)
|
|
7
7
|
multi_json
|
|
@@ -14,7 +14,7 @@ GEM
|
|
|
14
14
|
bunny (2.24.0)
|
|
15
15
|
amq-protocol (~> 2.3)
|
|
16
16
|
sorted_set (~> 1, >= 1.0.2)
|
|
17
|
-
connection_pool (2.5.
|
|
17
|
+
connection_pool (2.5.4)
|
|
18
18
|
diff-lcs (1.6.2)
|
|
19
19
|
docile (1.4.1)
|
|
20
20
|
json (2.13.2)
|
|
@@ -26,12 +26,12 @@ GEM
|
|
|
26
26
|
ast (~> 2.4.1)
|
|
27
27
|
racc
|
|
28
28
|
prettier_print (1.2.1)
|
|
29
|
-
prism (1.
|
|
29
|
+
prism (1.5.1)
|
|
30
30
|
racc (1.8.1)
|
|
31
31
|
rainbow (3.1.1)
|
|
32
32
|
rake (13.3.0)
|
|
33
33
|
rbtree (0.4.6)
|
|
34
|
-
regexp_parser (2.
|
|
34
|
+
regexp_parser (2.11.3)
|
|
35
35
|
rspec (3.13.1)
|
|
36
36
|
rspec-core (~> 3.13.0)
|
|
37
37
|
rspec-expectations (~> 3.13.0)
|
|
@@ -44,8 +44,8 @@ GEM
|
|
|
44
44
|
rspec-mocks (3.13.5)
|
|
45
45
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
46
46
|
rspec-support (~> 3.13.0)
|
|
47
|
-
rspec-support (3.13.
|
|
48
|
-
rubocop (1.
|
|
47
|
+
rspec-support (3.13.5)
|
|
48
|
+
rubocop (1.80.2)
|
|
49
49
|
json (~> 2.3)
|
|
50
50
|
language_server-protocol (~> 3.17.0.2)
|
|
51
51
|
lint_roller (~> 1.1.0)
|
|
@@ -55,7 +55,6 @@ GEM
|
|
|
55
55
|
regexp_parser (>= 2.9.3, < 3.0)
|
|
56
56
|
rubocop-ast (>= 1.46.0, < 2.0)
|
|
57
57
|
ruby-progressbar (~> 1.7)
|
|
58
|
-
tsort (>= 0.2.0)
|
|
59
58
|
unicode-display_width (>= 2.4.0, < 4.0)
|
|
60
59
|
rubocop-ast (1.46.0)
|
|
61
60
|
parser (>= 3.3.7.2)
|
|
@@ -63,7 +62,7 @@ GEM
|
|
|
63
62
|
rubocop-rake (0.7.1)
|
|
64
63
|
lint_roller (~> 1.1)
|
|
65
64
|
rubocop (>= 1.72.1)
|
|
66
|
-
rubocop-rspec (3.
|
|
65
|
+
rubocop-rspec (3.7.0)
|
|
67
66
|
lint_roller (~> 1.1)
|
|
68
67
|
rubocop (~> 1.72, >= 1.72.1)
|
|
69
68
|
ruby-progressbar (1.13.0)
|
|
@@ -79,10 +78,9 @@ GEM
|
|
|
79
78
|
set (~> 1.0)
|
|
80
79
|
syntax_tree (6.3.0)
|
|
81
80
|
prettier_print (>= 1.2.0)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
unicode-emoji (4.0.4)
|
|
81
|
+
unicode-display_width (3.2.0)
|
|
82
|
+
unicode-emoji (~> 4.1)
|
|
83
|
+
unicode-emoji (4.1.0)
|
|
86
84
|
yard (0.9.37)
|
|
87
85
|
|
|
88
86
|
PLATFORMS
|
|
@@ -110,10 +108,10 @@ CHECKSUMS
|
|
|
110
108
|
amq-protocol (2.3.4) sha256=98be5b9244e28dc66acc8351a254dbf45d996c5a0b7d49ab3ff8b72b0d2e6308
|
|
111
109
|
ast (2.4.3) sha256=954615157c1d6a382bc27d690d973195e79db7f55e9765ac7c481c60bdb4d383
|
|
112
110
|
bunny (2.24.0) sha256=072fe4ae98eaa9c95a17e4d166204f710bba8a9a7070b73a8c3b023f439d1682
|
|
113
|
-
connection_pool (2.5.
|
|
111
|
+
connection_pool (2.5.4) sha256=e9e1922327416091f3f6542f5f4446c2a20745276b9aa796dd0bb2fd0ea1e70a
|
|
114
112
|
diff-lcs (1.6.2) sha256=9ae0d2cba7d4df3075fe8cd8602a8604993efc0dfa934cff568969efb1909962
|
|
115
113
|
docile (1.4.1) sha256=96159be799bfa73cdb721b840e9802126e4e03dfc26863db73647204c727f21e
|
|
116
|
-
ears (0.
|
|
114
|
+
ears (0.23.0)
|
|
117
115
|
json (2.13.2) sha256=02e1f118d434c6b230a64ffa5c8dee07e3ec96244335c392eaed39e1199dbb68
|
|
118
116
|
language_server-protocol (3.17.0.5) sha256=fd1e39a51a28bf3eec959379985a72e296e9f9acfce46f6a79d31ca8760803cc
|
|
119
117
|
lint_roller (1.1.0) sha256=2c0c845b632a7d172cb849cc90c1bce937a28c5c8ccccb50dfd46a485003cc87
|
|
@@ -121,21 +119,21 @@ CHECKSUMS
|
|
|
121
119
|
parallel (1.27.0) sha256=4ac151e1806b755fb4e2dc2332cbf0e54f2e24ba821ff2d3dcf86bf6dc4ae130
|
|
122
120
|
parser (3.3.9.0) sha256=94d6929354b1a6e3e1f89d79d4d302cc8f5aa814431a6c9c7e0623335d7687f2
|
|
123
121
|
prettier_print (1.2.1) sha256=a72838b5f23facff21f90a5423cdcdda19e4271092b41f4ea7f50b83929e6ff9
|
|
124
|
-
prism (1.
|
|
122
|
+
prism (1.5.1) sha256=b40c1b76ccb9fcccc3d1553967cda6e79fa7274d8bfea0d98b15d27a6d187134
|
|
125
123
|
racc (1.8.1) sha256=4a7f6929691dbec8b5209a0b373bc2614882b55fc5d2e447a21aaa691303d62f
|
|
126
124
|
rainbow (3.1.1) sha256=039491aa3a89f42efa1d6dec2fc4e62ede96eb6acd95e52f1ad581182b79bc6a
|
|
127
125
|
rake (13.3.0) sha256=96f5092d786ff412c62fde76f793cc0541bd84d2eb579caa529aa8a059934493
|
|
128
126
|
rbtree (0.4.6) sha256=14eea4469b24fd2472542e5f3eb105d6344c8ccf36f0b56d55fdcfeb4e0f10fc
|
|
129
|
-
regexp_parser (2.
|
|
127
|
+
regexp_parser (2.11.3) sha256=ca13f381a173b7a93450e53459075c9b76a10433caadcb2f1180f2c741fc55a4
|
|
130
128
|
rspec (3.13.1) sha256=b9f9a58fa915b8d94a1d6b3195fe6dd28c4c34836a6097015142c4a9ace72140
|
|
131
129
|
rspec-core (3.13.5) sha256=ab3f682897c6131c67f9a17cfee5022a597f283aebe654d329a565f9937a4fa3
|
|
132
130
|
rspec-expectations (3.13.5) sha256=33a4d3a1d95060aea4c94e9f237030a8f9eae5615e9bd85718fe3a09e4b58836
|
|
133
131
|
rspec-mocks (3.13.5) sha256=e4338a6f285ada9fe56f5893f5457783af8194f5d08884d17a87321d5195ea81
|
|
134
|
-
rspec-support (3.13.
|
|
135
|
-
rubocop (1.
|
|
132
|
+
rspec-support (3.13.5) sha256=add745af535dd14b18f1209ab41ef987fdfad12786176b6a3b3619b9a7279fbf
|
|
133
|
+
rubocop (1.80.2) sha256=6485f30fefcf5c199db3b91e5e253b1ef43f7e564784e2315255809a3dd9abf4
|
|
136
134
|
rubocop-ast (1.46.0) sha256=0da7f6ad5b98614f89b74f11873c191059c823eae07d6ffd40a42a3338f2232b
|
|
137
135
|
rubocop-rake (0.7.1) sha256=3797f2b6810c3e9df7376c26d5f44f3475eda59eb1adc38e6f62ecf027cbae4d
|
|
138
|
-
rubocop-rspec (3.
|
|
136
|
+
rubocop-rspec (3.7.0) sha256=b7b214da112034db9c6d00f2d811a354847e870f7b6ed2482b29649c3d42058f
|
|
139
137
|
ruby-progressbar (1.13.0) sha256=80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33
|
|
140
138
|
set (1.1.2) sha256=ca33a60d202e788041d94a5d4c12315b1639875576f1a266f3a10913646d8ef1
|
|
141
139
|
simplecov (0.22.0) sha256=fe2622c7834ff23b98066bb0a854284b2729a569ac659f82621fc22ef36213a5
|
|
@@ -143,10 +141,9 @@ CHECKSUMS
|
|
|
143
141
|
simplecov_json_formatter (0.1.4) sha256=529418fbe8de1713ac2b2d612aa3daa56d316975d307244399fa4838c601b428
|
|
144
142
|
sorted_set (1.0.3) sha256=4f2b8bee6e8c59cbd296228c0f1f81679357177a8b6859dcc2a99e86cce6372f
|
|
145
143
|
syntax_tree (6.3.0) sha256=56e25a9692c798ec94c5442fe94c5e94af76bef91edc8bb02052cbdecf35f13d
|
|
146
|
-
|
|
147
|
-
unicode-
|
|
148
|
-
unicode-emoji (4.0.4) sha256=2c2c4ef7f353e5809497126285a50b23056cc6e61b64433764a35eff6c36532a
|
|
144
|
+
unicode-display_width (3.2.0) sha256=0cdd96b5681a5949cdbc2c55e7b420facae74c4aaf9a9815eee1087cb1853c42
|
|
145
|
+
unicode-emoji (4.1.0) sha256=4997d2d5df1ed4252f4830a9b6e86f932e2013fbff2182a9ce9ccabda4f325a5
|
|
149
146
|
yard (0.9.37) sha256=a6e910399e78e613f80ba9add9ba7c394b1a935f083cccbef82903a3d2a26992
|
|
150
147
|
|
|
151
148
|
BUNDLED WITH
|
|
152
|
-
2.7.
|
|
149
|
+
2.7.2
|
data/README.md
CHANGED
|
@@ -663,6 +663,83 @@ Each captured message has the following properties:
|
|
|
663
663
|
- `timestamp` - When the message was captured
|
|
664
664
|
- `thread_id` - Thread that published the message
|
|
665
665
|
|
|
666
|
+
### Custom RSpec Matcher: `have_been_published`
|
|
667
|
+
|
|
668
|
+
To make tests more expressive, Ears provides a custom RSpec matcher that allows you to easily assert that a specific message was published to a mocked exchange.
|
|
669
|
+
|
|
670
|
+
#### Usage
|
|
671
|
+
|
|
672
|
+
Include the matcher by requiring `ears/testing` in your RSpec tests and including the helper module:
|
|
673
|
+
|
|
674
|
+
```ruby
|
|
675
|
+
require 'ears/testing'
|
|
676
|
+
|
|
677
|
+
RSpec.describe MyPublisher do
|
|
678
|
+
include Ears::Testing::TestHelper
|
|
679
|
+
|
|
680
|
+
before { mock_ears('events') }
|
|
681
|
+
after { ears_reset! }
|
|
682
|
+
|
|
683
|
+
it 'publishes a user.created message' do
|
|
684
|
+
publisher = Ears::Publisher.new('events', :topic)
|
|
685
|
+
publisher.publish({ user_id: 1 }, routing_key: 'user.created')
|
|
686
|
+
|
|
687
|
+
expect(
|
|
688
|
+
exchange_name: 'events',
|
|
689
|
+
routing_key: 'user.created',
|
|
690
|
+
data: {
|
|
691
|
+
user_id: 1,
|
|
692
|
+
},
|
|
693
|
+
).to have_been_published
|
|
694
|
+
end
|
|
695
|
+
|
|
696
|
+
# also works with negative assertions
|
|
697
|
+
it 'does not publish a user.deleted message' do
|
|
698
|
+
publisher = Ears::Publisher.new('events', :topic)
|
|
699
|
+
publisher.publish({ user_id: 1 }, routing_key: 'user.created')
|
|
700
|
+
|
|
701
|
+
expect(
|
|
702
|
+
exchange_name: 'events',
|
|
703
|
+
routing_key: 'user.deleted',
|
|
704
|
+
data: {
|
|
705
|
+
user_id: 1,
|
|
706
|
+
},
|
|
707
|
+
).not_to have_been_published
|
|
708
|
+
end
|
|
709
|
+
end
|
|
710
|
+
```
|
|
711
|
+
|
|
712
|
+
#### Supported Keys
|
|
713
|
+
|
|
714
|
+
You can match on any or all of the following attributes:
|
|
715
|
+
|
|
716
|
+
| Key | Description | Example |
|
|
717
|
+
| ---------------- | ---------------------------------------------- | --------------------------------------------------- |
|
|
718
|
+
| `:exchange_name` | The exchange where the message was published | `'events'` |
|
|
719
|
+
| `:routing_key` | The routing key used for the message | `'user.created'` |
|
|
720
|
+
| `:data` | The message payload (exact match) | `{ user_id: 1 }` |
|
|
721
|
+
| `:options` | Message options such as headers or persistence | `{ persistent: true, headers: { version: '1.0' } }` |
|
|
722
|
+
|
|
723
|
+
If a key is omitted, it will not be checked — allowing partial matches (for example, matching only on `exchange_name` and `routing_key`).
|
|
724
|
+
|
|
725
|
+
#### Example: Matching with Options
|
|
726
|
+
|
|
727
|
+
> **Note:** When matching `:options`, you only need to specify the options you want to verify — the matcher will ignore any additional options present in the published message.
|
|
728
|
+
|
|
729
|
+
```ruby
|
|
730
|
+
expect(
|
|
731
|
+
exchange_name: 'events',
|
|
732
|
+
routing_key: 'user.created',
|
|
733
|
+
data: {
|
|
734
|
+
id: 42,
|
|
735
|
+
name: 'Alice',
|
|
736
|
+
},
|
|
737
|
+
options: {
|
|
738
|
+
persistent: true,
|
|
739
|
+
},
|
|
740
|
+
).to have_been_published
|
|
741
|
+
```
|
|
742
|
+
|
|
666
743
|
### Error Handling
|
|
667
744
|
|
|
668
745
|
By default, publishing to unmocked exchanges raises an error:
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'connection_pool'
|
|
2
|
+
require 'ears/publisher_retry_handler'
|
|
2
3
|
|
|
3
4
|
module Ears
|
|
4
5
|
# Channel pool management for publishers.
|
|
@@ -11,12 +12,15 @@ module Ears
|
|
|
11
12
|
# @param [Boolean] confirms Whether to use a channel with publisher confirms enabled
|
|
12
13
|
# @yieldparam [Bunny::Channel] channel The channel to use for publishing
|
|
13
14
|
# @return [Object] The result of the block
|
|
14
|
-
def with_channel(confirms: false, &)
|
|
15
|
+
def with_channel(confirms: false, &block)
|
|
15
16
|
# CRITICAL: Preserve fork-safety at the entry point
|
|
16
17
|
reset! if @creator_pid && @creator_pid != Process.pid
|
|
17
18
|
|
|
18
19
|
pool = confirms ? confirms_pool : standard_pool
|
|
19
|
-
pool.with
|
|
20
|
+
pool.with do |channel|
|
|
21
|
+
validate_channel_health!(channel, confirms)
|
|
22
|
+
block.call(channel)
|
|
23
|
+
end
|
|
20
24
|
end
|
|
21
25
|
|
|
22
26
|
# Resets both channel pools, forcing new channels to be created.
|
|
@@ -97,6 +101,28 @@ module Ears
|
|
|
97
101
|
def init_mutex
|
|
98
102
|
@init_mutex ||= Mutex.new
|
|
99
103
|
end
|
|
104
|
+
|
|
105
|
+
def validate_channel_health!(channel, confirms)
|
|
106
|
+
return if channel.open?
|
|
107
|
+
|
|
108
|
+
cleanup_closed_channel(channel)
|
|
109
|
+
reset_appropriate_pool(confirms)
|
|
110
|
+
|
|
111
|
+
raise PublisherRetryHandler::PublishToStaleChannelError,
|
|
112
|
+
'Channel is closed'
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def cleanup_closed_channel(channel)
|
|
116
|
+
return unless channel.respond_to?(:close)
|
|
117
|
+
|
|
118
|
+
channel.close
|
|
119
|
+
rescue StandardError
|
|
120
|
+
# Channel is already closed, ignore cleanup errors
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def reset_appropriate_pool(confirms)
|
|
124
|
+
confirms ? reset_confirms_pool! : reset!
|
|
125
|
+
end
|
|
100
126
|
end
|
|
101
127
|
end
|
|
102
128
|
end
|
|
@@ -35,7 +35,7 @@ module Ears
|
|
|
35
35
|
rescue *NON_RETRYABLE_ERRORS => e
|
|
36
36
|
raise e
|
|
37
37
|
rescue *CONNECTION_ERRORS => e
|
|
38
|
-
attempt = handle_connection_error(e, attempt)
|
|
38
|
+
attempt = handle_connection_error(e, attempt)
|
|
39
39
|
retry
|
|
40
40
|
rescue StandardError => e
|
|
41
41
|
attempt = handle_standard_error(e, attempt)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module Ears
|
|
2
|
+
module Testing
|
|
3
|
+
module Matchers
|
|
4
|
+
RSpec::Matchers.define :have_been_published do # rubocop:disable Metrics/BlockLength
|
|
5
|
+
include Ears::Testing::TestHelper
|
|
6
|
+
|
|
7
|
+
match do |expected|
|
|
8
|
+
exchange_name = expected[:exchange_name]
|
|
9
|
+
messages = published_messages(exchange_name)
|
|
10
|
+
|
|
11
|
+
messages.any? { |message| matches_message?(message, expected) }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
failure_message do |expected|
|
|
15
|
+
"expected a message with #{expected.inspect} to have been published, " \
|
|
16
|
+
"but published were:\n" \
|
|
17
|
+
"#{published_messages(expected[:exchange_name]).map(&:inspect).join("\n")}"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
failure_message_when_negated do |expected|
|
|
21
|
+
matching =
|
|
22
|
+
published_messages(expected[:exchange_name]).select do |m|
|
|
23
|
+
matches_message?(m, expected)
|
|
24
|
+
end
|
|
25
|
+
"expected no message with #{expected.inspect} to have been published, but found:\n" \
|
|
26
|
+
"#{matching.map(&:inspect).join("\n")}"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def matches_message?(published, expected)
|
|
30
|
+
routing_key = expected[:routing_key]
|
|
31
|
+
data = expected[:data]
|
|
32
|
+
options = expected[:options]
|
|
33
|
+
|
|
34
|
+
[
|
|
35
|
+
(routing_key.nil? || published.routing_key == routing_key),
|
|
36
|
+
(data.nil? || published.data == data),
|
|
37
|
+
(options.nil? || options.all? { |k, v| published.options[k] == v }),
|
|
38
|
+
].all?
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
data/lib/ears/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ears
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.23.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- InVision AG
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-11-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bunny
|
|
@@ -93,6 +93,7 @@ files:
|
|
|
93
93
|
- lib/ears/publisher_retry_handler.rb
|
|
94
94
|
- lib/ears/setup.rb
|
|
95
95
|
- lib/ears/testing.rb
|
|
96
|
+
- lib/ears/testing/matchers.rb
|
|
96
97
|
- lib/ears/testing/message_capture.rb
|
|
97
98
|
- lib/ears/testing/publisher_mock.rb
|
|
98
99
|
- lib/ears/testing/test_helper.rb
|