summaryrefslogtreecommitdiff
path: root/spec/support/matchers/event_store.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/matchers/event_store.rb')
-rw-r--r--spec/support/matchers/event_store.rb37
1 files changed, 32 insertions, 5 deletions
diff --git a/spec/support/matchers/event_store.rb b/spec/support/matchers/event_store.rb
index 96a71ae3c22..eb5b37f39e5 100644
--- a/spec/support/matchers/event_store.rb
+++ b/spec/support/matchers/event_store.rb
@@ -1,12 +1,39 @@
# frozen_string_literal: true
-RSpec::Matchers.define :event_type do |event_class|
- match do |actual|
- actual.instance_of?(event_class) &&
- actual.data == @expected_data
+RSpec::Matchers.define :publish_event do |expected_event_class|
+ supports_block_expectations
+
+ match do |proc|
+ raise ArgumentError, 'This matcher only supports block expectation' unless proc.respond_to?(:call)
+
+ @events ||= []
+
+ allow(Gitlab::EventStore).to receive(:publish) do |published_event|
+ @events << published_event
+ end
+
+ proc.call
+
+ @events.any? do |event|
+ event.instance_of?(expected_event_class) && event.data == @expected_data
+ end
end
- chain :containing do |expected_data|
+ chain :with do |expected_data|
@expected_data = expected_data
end
+
+ failure_message do
+ "expected #{expected_event_class} with #{@expected_data} to be published, but got #{@events}"
+ end
+
+ match_when_negated do |proc|
+ raise ArgumentError, 'This matcher only supports block expectation' unless proc.respond_to?(:call)
+
+ allow(Gitlab::EventStore).to receive(:publish)
+
+ proc.call
+
+ expect(Gitlab::EventStore).not_to have_received(:publish).with(instance_of(expected_event_class))
+ end
end