Class: RubyEventStore::RSpec::HaveSubscribedToEvents

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

Instance Method Summary collapse

Constructor Details

#initialize(mandatory_expected, *optional_expected, differ:, phraser:) ⇒ HaveSubscribedToEvents

Returns a new instance of HaveSubscribedToEvents.


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

def initialize(mandatory_expected, *optional_expected, differ:, phraser:)
  @expected = [mandatory_expected, *optional_expected]
  @matcher = ::RSpec::Matchers::BuiltIn::ContainExactly.new(expected)
  @differ = differ
  @phraser = phraser
end

Instance Method Details

#descriptionObject


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

def description
  "have subscribed to events that have to (#{phraser.(expected)})"
end

#failure_messageObject


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

def failure_message
  "expected #{handler} to be subscribed to events, diff:" + differ.diff(expected.to_s + "\n", subscribed_to)
end

#failure_message_when_negatedObject


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

def failure_message_when_negated
  "expected #{handler} not to be subscribed to events, diff:" + differ.diff(expected.to_s + "\n", subscribed_to)
end

#in(event_store) ⇒ Object


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

def in(event_store)
  @event_store = event_store
  self
end

#matches?(handler) ⇒ Boolean

Returns:

  • (Boolean)

13
14
15
16
17
18
# File 'lib/ruby_event_store/rspec/have_subscribed_to_events.rb', line 13

def matches?(handler)
  @handler = handler
  @subscribed_to = expected.select { |event| event_store.subscribers_for(event).include?(handler) }

  matcher.matches?(subscribed_to)
end