rabbit_feed 2.4.3 → 2.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: caa59494167f26b29ead2d8be4e547884c555bf8
4
- data.tar.gz: 873561ab416044cbb81b0b085d56e7bbbc5084f2
3
+ metadata.gz: 5cfc4d957f4cce3aac5cf77870241ec8f60d5495
4
+ data.tar.gz: b6047ba2d39c634ae3c8d3cbc3b09a1f2849f3ab
5
5
  SHA512:
6
- metadata.gz: 9ddfa7d6c4163a6af9d48dcddc6dc87bc06f4e02530211d35d95292c77dc99d49873f05bf524d07a5a95a9ea78d9e140e9d3d4cd68afaf4022644f3a1aeffc7b
7
- data.tar.gz: dee6c6afcee2e1967208cc4c5ad65441b6412763baabecf1ea8e42d46d7bd4693488e8ccb5e1a2c296afa9dab052168ec3dc1fac3a0ba05499f8dce1caa0c9c0
6
+ metadata.gz: 8dafb9b1caf08fc1025fa1f366585a7eab7844e224d1e935c6a7cbf9c2d068cfe490e7964cac24cdcc4011aa797368998b4e0fccd63ca976ac3053c5f190496e
7
+ data.tar.gz: 6a740b0c0fdf17fb64516faf622bb77b7b2d30a5f765c5901d6efb14b7d9ef5022e311b1d4c0343c7b439552ca6c99a676cc7b125dcb1b4ad760b4bda92bc23e
data/README.md CHANGED
@@ -168,6 +168,18 @@ describe BeaversController do
168
168
  end
169
169
  ```
170
170
 
171
+ You can also pass a block with `do/end` (not `{}`) and do more fine grained matching.
172
+
173
+ ```ruby
174
+ it 'publishes a create event' do
175
+ expect{
176
+ post :create, beaver: { name: 'beaver' }
177
+ }.to publish_event('user_creates_beaver', nil) do |payload|
178
+ expect(payload['beaver_name']).to match(/ea/)
179
+ end
180
+ end
181
+ ```
182
+
171
183
  ## Consuming events
172
184
 
173
185
  The consumer defines to which events it will subscribe as well as how it handles events using the [Event Routing DSL](https://github.com/simplybusiness/rabbit_feed#event-routing-dsl). In a rails app, this can be defined in the [initialiser](https://github.com/simplybusiness/rabbit_feed#initialisation).
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- rabbit_feed (2.4.3)
4
+ rabbit_feed (2.4.4)
5
5
  activemodel (>= 3.2.0, < 5.0.0)
6
6
  activesupport (>= 3.2.0, < 5.0.0)
7
7
  avro (>= 1.5.4, < 1.8.0)
@@ -30,7 +30,7 @@ GEM
30
30
  i18n (0.7.0)
31
31
  json (1.8.3)
32
32
  minitest (5.8.4)
33
- multi_json (1.11.2)
33
+ multi_json (1.12.0)
34
34
  pidfile (0.3.0)
35
35
  rake (10.4.2)
36
36
  rspec (3.2.0)
@@ -59,4 +59,4 @@ DEPENDENCIES
59
59
  rspec
60
60
 
61
61
  BUNDLED WITH
62
- 1.10.6
62
+ 1.11.2
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- rabbit_feed (2.4.3)
4
+ rabbit_feed (2.4.4)
5
5
  activemodel (>= 3.2.0, < 5.0.0)
6
6
  activesupport (>= 3.2.0, < 5.0.0)
7
7
  avro (>= 1.5.4, < 1.8.0)
@@ -189,4 +189,4 @@ DEPENDENCIES
189
189
  unicorn
190
190
 
191
191
  BUNDLED WITH
192
- 1.10.6
192
+ 1.11.2
@@ -10,30 +10,19 @@ module RabbitFeed
10
10
  end
11
11
 
12
12
  def matches?(given_proc, negative_expectation = false)
13
- unless given_proc.respond_to?(:call)
14
- ::Kernel.warn "`publish_event` was called with non-proc object #{given_proc.inspect}"
15
- return false
16
- end
17
-
18
- begin
19
- TestingSupport.published_events.clear
20
- given_proc.call
21
- rescue
22
- end
13
+ execute_proc(given_proc)
23
14
 
24
- actual_event = TestingSupport.published_events.detect do |event|
25
- event.name == expected_event
26
- end
27
-
28
- received_expected_event = actual_event.present?
15
+ if block_given? && actual_event
16
+ yield actual_event.payload
17
+ else
18
+ received_expected_event = actual_event.present?
19
+ with_expected_payload = negative_expectation
29
20
 
30
- with_expected_payload = negative_expectation
31
- if received_expected_event && !with_expected_payload
32
- actual_payload = actual_event.payload
33
- with_expected_payload = expected_payload.nil? || actual_payload == expected_payload
21
+ if received_expected_event && !with_expected_payload
22
+ with_expected_payload = expected_payload.nil? || actual_event.payload == expected_payload
23
+ end
24
+ return received_expected_event && with_expected_payload
34
25
  end
35
-
36
- return received_expected_event && with_expected_payload
37
26
  end
38
27
 
39
28
  alias == matches?
@@ -72,6 +61,23 @@ module RabbitFeed
72
61
 
73
62
  private
74
63
 
64
+ def execute_proc(given_proc)
65
+ unless given_proc.respond_to?(:call)
66
+ ::Kernel.warn "`publish_event` was called with non-proc object #{given_proc.inspect}"
67
+ return false
68
+ end
69
+
70
+ TestingSupport.published_events.clear
71
+ given_proc.call
72
+ rescue
73
+ end
74
+
75
+ def actual_event
76
+ TestingSupport.published_events.detect do |event|
77
+ event.name == expected_event
78
+ end
79
+ end
80
+
75
81
  def expected_payload
76
82
  @expected_payload.respond_to?(:call) ? @expected_payload.call : @expected_payload
77
83
  end
@@ -1,3 +1,3 @@
1
1
  module RabbitFeed
2
- VERSION = '2.4.3'
2
+ VERSION = '2.4.4'
3
3
  end
@@ -74,6 +74,42 @@ module RabbitFeed
74
74
  (matcher.matches? block).should be_falsey
75
75
  end
76
76
 
77
+ context 'with block' do
78
+ it 'validates block' do
79
+ expect {
80
+ RabbitFeed::Producer.publish_event event_name, event_payload
81
+ }.to publish_event(event_name, nil) do |actual_payload|
82
+ expect(actual_payload['field']).to eq 'value'
83
+ end
84
+ end
85
+
86
+ it 'validates block with `with` will be ignored' do
87
+ eval_block = Proc.new {|actual_payload|
88
+ expect(actual_payload['field']).to eq 'value'
89
+ }
90
+ matcher = described_class.new(event_name, nil).with({field: 'different name'})
91
+ block = Proc.new { RabbitFeed::Producer.publish_event event_name, {'field' => 'value'} }
92
+
93
+ (matcher.matches? block, &eval_block).should be true
94
+ end
95
+
96
+ it 'does not evaluates block with {}' do
97
+ expect {
98
+ RabbitFeed::Producer.publish_event event_name, event_payload
99
+ }.to publish_event(event_name, nil) { |actual_payload|
100
+ raise 'this block should not be evaluated'
101
+ }
102
+ end
103
+
104
+ it 'does not evaluate block if the expectation block does not return actual payload' do
105
+ expect {
106
+ nil
107
+ }.not_to publish_event(event_name, nil) do |actual_payload|
108
+ raise 'this block should not be evaluated'
109
+ end
110
+ end
111
+ end
112
+
77
113
  context 'when validating the payload' do
78
114
  context 'and the payload is not a Proc' do
79
115
  it 'validates the event payload' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabbit_feed
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.3
4
+ version: 2.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simply Business
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-19 00:00:00.000000000 Z
11
+ date: 2016-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -368,7 +368,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
368
368
  version: '0'
369
369
  requirements: []
370
370
  rubyforge_project:
371
- rubygems_version: 2.0.14
371
+ rubygems_version: 2.4.5.1
372
372
  signing_key:
373
373
  specification_version: 4
374
374
  summary: Enables your Ruby applications to perform centralized event logging with