Class: RubyEventStore::RSpec::Publish

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_event_store/rspec/publish.rb

Instance Method Summary collapse

Constructor Details

#initialize(*expected, failure_message_formatter:) ⇒ Publish

Returns a new instance of Publish.



6
7
8
9
10
11
# File 'lib/ruby_event_store/rspec/publish.rb', line 6

def initialize(*expected, failure_message_formatter:)
  @expected = ExpectedCollection.new(expected)
  @failure_message_formatter = failure_message_formatter
  @fetch_events = FetchEvents.new
  @start_for_stream = {}
end

Instance Method Details

#descriptionObject



75
76
77
# File 'lib/ruby_event_store/rspec/publish.rb', line 75

def description
  "publish events"
end

#exactly(count) ⇒ Object



28
29
30
31
# File 'lib/ruby_event_store/rspec/publish.rb', line 28

def exactly(count)
  expected.exactly(count)
  self
end

#failure_messageObject



67
68
69
# File 'lib/ruby_event_store/rspec/publish.rb', line 67

def failure_message
  failure_message_formatter.failure_message(expected, published_events, failed_on_stream)
end

#failure_message_when_negatedObject



71
72
73
# File 'lib/ruby_event_store/rspec/publish.rb', line 71

def failure_message_when_negated
  failure_message_formatter.failure_message_when_negated(expected, published_events, fetch_events.stream_name)
end

#in(event_store) ⇒ Object



13
14
15
16
# File 'lib/ruby_event_store/rspec/publish.rb', line 13

def in(event_store)
  fetch_events.in(event_store)
  self
end

#in_stream(stream_name) ⇒ Object



18
19
20
21
# File 'lib/ruby_event_store/rspec/publish.rb', line 18

def in_stream(stream_name)
  @stream_names = [stream_name]
  self
end

#in_streams(stream_names) ⇒ Object



23
24
25
26
# File 'lib/ruby_event_store/rspec/publish.rb', line 23

def in_streams(stream_names)
  @stream_names = Array(stream_names)
  self
end

#matches?(event_proc) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ruby_event_store/rspec/publish.rb', line 48

def matches?(event_proc)
  stream_names.each do |stream_name|
    fetch_events.stream(stream_name)
    @start_for_stream[stream_name] = fetch_events.call.last&.event_id
  end

  event_proc.call

  stream_names.all? do |stream_name|
    fetch_events.stream(stream_name)
    fetch_events.from(@start_for_stream.fetch(stream_name))
    @published_events = fetch_events.call.to_a
    @failed_on_stream = stream_name
    MatchEvents.new.call(expected, published_events)
  end
rescue FetchEvents::MissingEventStore
  raise "You have to set the event store instance with `in`, e.g. `expect { ... }.to publish(an_event(MyEvent)).in(event_store)`"
end

#onceObject



33
34
35
36
# File 'lib/ruby_event_store/rspec/publish.rb', line 33

def once
  expected.once
  self
end

#strictObject



43
44
45
46
# File 'lib/ruby_event_store/rspec/publish.rb', line 43

def strict
  expected.strict
  self
end

#supports_block_expectations?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/ruby_event_store/rspec/publish.rb', line 79

def supports_block_expectations?
  true
end

#timesObject Also known as: time



38
39
40
# File 'lib/ruby_event_store/rspec/publish.rb', line 38

def times
  self
end