Class: Eventifier::Matchers::Notifications

Inherits:
Object
  • Object
show all
Defined in:
lib/eventifier/matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ Notifications

Returns a new instance of Notifications.



4
5
6
# File 'lib/eventifier/matchers.rb', line 4

def initialize(target)
  @target = target
end

Instance Method Details

#failure_message_for_shouldObject



19
20
21
22
# File 'lib/eventifier/matchers.rb', line 19

def failure_message_for_should
  'should have worked'
  #"the block should have chronicled the '#{ @event_name }' incident for the #{ @target.class.name }##{ @target.object_id }, but it didn't"
end

#failure_message_for_should_notObject



24
25
26
27
# File 'lib/eventifier/matchers.rb', line 24

def failure_message_for_should_not
  'should not have worked'
  #"the block should not have chronicled the '#{ @event_name }' incident for the #{ @target.class.name }##{ @target.object_id }, but it did"
end

#matches?(block_to_test) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
17
# File 'lib/eventifier/matchers.rb', line 8

def matches?(block_to_test)
  #before = incidents_count
  existing_notifications = @target.inject({}) do |memo, record|
    memo[record] = record.notifications
  end
  block_to_test.call
  @target.none? do |record|
    (existing_notifications[record] - record.notifications).empty?
  end
end