Class: RubyEventStore::RSpec::Publish

Inherits:
Object
  • Object
show all
Includes:
RSpec::Matchers::Composable
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.



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

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



77
78
79
# File 'lib/ruby_event_store/rspec/publish.rb', line 77

def description
  "publish events"
end

#exactly(count) ⇒ Object



30
31
32
33
# File 'lib/ruby_event_store/rspec/publish.rb', line 30

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

#failure_messageObject



69
70
71
# File 'lib/ruby_event_store/rspec/publish.rb', line 69

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

#failure_message_when_negatedObject



73
74
75
# File 'lib/ruby_event_store/rspec/publish.rb', line 73

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

#in(event_store) ⇒ Object



15
16
17
18
# File 'lib/ruby_event_store/rspec/publish.rb', line 15

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

#in_stream(stream_name) ⇒ Object



20
21
22
23
# File 'lib/ruby_event_store/rspec/publish.rb', line 20

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

#in_streams(stream_names) ⇒ Object



25
26
27
28
# File 'lib/ruby_event_store/rspec/publish.rb', line 25

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

#matches?(event_proc) ⇒ Boolean

Returns:

  • (Boolean)


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

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



35
36
37
38
# File 'lib/ruby_event_store/rspec/publish.rb', line 35

def once
  expected.once
  self
end

#strictObject



45
46
47
48
# File 'lib/ruby_event_store/rspec/publish.rb', line 45

def strict
  expected.strict
  self
end

#supports_block_expectations?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/ruby_event_store/rspec/publish.rb', line 81

def supports_block_expectations?
  true
end

#timesObject Also known as: time



40
41
42
# File 'lib/ruby_event_store/rspec/publish.rb', line 40

def times
  self
end