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
# 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
end

Instance Method Details

#descriptionObject


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

def description
  "publish events"
end

#exactly(count) ⇒ Object


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

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

#failure_messageObject


60
61
62
# File 'lib/ruby_event_store/rspec/publish.rb', line 60

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

#failure_message_when_negatedObject


64
65
66
# File 'lib/ruby_event_store/rspec/publish.rb', line 64

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

#in(event_store) ⇒ Object


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

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

#in_stream(stream_name) ⇒ Object


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

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

#in_streams(stream_names) ⇒ Object


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

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

#matches?(event_proc) ⇒ Boolean

Returns:

  • (Boolean)

47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ruby_event_store/rspec/publish.rb', line 47

def matches?(event_proc)
  fetch_events.from_last
  event_proc.call
  stream_names.all? do |stream_name|
    fetch_events.stream(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


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

def once
  expected.once
  self
end

#strictObject


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

def strict
  expected.strict
  self
end

#supports_block_expectations?Boolean

Returns:

  • (Boolean)

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

def supports_block_expectations?
  true
end

#timesObject Also known as: time


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

def times
  self
end