Skip to content

Commit 5b1d38d

Browse files
committed
make FetchEvents store last event of each stream
When testing with Publish rspec assertion, we should store what is the last event of each stream we check. Not what is the last event in the whole event store.
1 parent c7d80d1 commit 5b1d38d

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

ruby_event_store-rspec/lib/ruby_event_store/rspec/fetch_events.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ def in(event_store)
1515
@event_store = event_store
1616
end
1717

18-
def from_last
19-
@start = call.last&.event_id
20-
end
21-
2218
def call
2319
raise MissingEventStore if event_store.nil?
2420
events = event_store.read

ruby_event_store-rspec/lib/ruby_event_store/rspec/publish.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ def initialize(*expected, failure_message_formatter:)
77
@expected = ExpectedCollection.new(expected)
88
@failure_message_formatter = failure_message_formatter
99
@fetch_events = FetchEvents.new
10+
@start_for_stream = {}
1011
end
1112

1213
def in(event_store)
@@ -45,10 +46,16 @@ def strict
4546
end
4647

4748
def matches?(event_proc)
48-
fetch_events.from_last
49+
stream_names.each do |stream_name|
50+
fetch_events.stream(stream_name)
51+
@start_for_stream[stream_name] = fetch_events.call.last&.event_id
52+
end
53+
4954
event_proc.call
55+
5056
stream_names.all? do |stream_name|
5157
fetch_events.stream(stream_name)
58+
fetch_events.from(@start_for_stream.fetch(stream_name))
5259
@published_events = fetch_events.call.to_a
5360
@failed_on_stream = stream_name
5461
MatchEvents.new.call(expected, published_events)

ruby_event_store-rspec/spec/ruby_event_store/rspec/publish_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,18 @@ def colorless_differ
246246
event_store.publish(BarEvent.new)
247247
end.to matcher(matchers.an_event(FooEvent), matchers.an_event(BarEvent)).strict.in(event_store)
248248
end
249+
250+
specify do
251+
event_store.publish(FooEvent.new, stream_name: "Stream$1")
252+
event_store.publish(FooEvent.new, stream_name: "Stream$2")
253+
expect do
254+
event_store.publish(BarEvent.new, stream_name: "Stream$1")
255+
event_store.publish(BarEvent.new, stream_name: "Stream$3")
256+
end.to matcher(matchers.an_event(BarEvent))
257+
.strict
258+
.in(event_store)
259+
.in_streams(%w[Stream$1 Stream$3])
260+
end
249261
end
250262
end
251263
end

0 commit comments

Comments
 (0)