Class: RubyEventStore::RSpec::StepByStepFailureMessageFormatter::HavePublished

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

Instance Method Summary collapse

Constructor Details

#initialize(differ, lingo) ⇒ HavePublished

Returns a new instance of HavePublished.



14
15
16
17
# File 'lib/ruby_event_store/rspec/step_by_step_failure_message_formatter.rb', line 14

def initialize(differ, lingo)
  @differ = differ
  @lingo = lingo
end

Instance Method Details

#failure_message(expected, events, stream_name = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ruby_event_store/rspec/step_by_step_failure_message_formatter.rb', line 19

def failure_message(expected, events, stream_name = nil)
  return failure_message_strict(expected, events) if expected.strict?
  return failure_message_no_events if expected.empty?
  expected.events.each do |expected_event|
    correct_event_count = 0
    events_with_correct_type = []
    events.each do |actual_event|
      if expected_event.matches?(actual_event)
        correct_event_count += 1
      elsif expected_event.matches_kind?(actual_event)
        events_with_correct_type << actual_event
      end
    end

    expectations = expected_message(expected, expected_event, stream_name)

    if expected.specified_count?
      if correct_event_count >= 1
        reality = failure_message_incorrect_count(expected_event, events_with_correct_type, correct_event_count)
      elsif !events_with_correct_type.empty?
        reality = failure_message_correct_type_incorrect_payload(expected_event, events_with_correct_type)
      else
        reality = failure_message_incorrect_type
      end
    else
      if correct_event_count >= 1
        next
      else
        if !events_with_correct_type.empty?
          reality = failure_message_correct_type_incorrect_payload(expected_event, events_with_correct_type)
        else
          reality = failure_message_incorrect_type
        end
      end
    end

    return expectations + reality
  end
end

#failure_message_when_negated(expected, events, _stream_name = nil) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ruby_event_store/rspec/step_by_step_failure_message_formatter.rb', line 59

def failure_message_when_negated(expected, events, _stream_name = nil)
  return failure_message_when_negated_no_events if expected.empty?
  if expected.specified_count?
    <<~EOS
    expected
      #{expected.events.first.description}
    not to be #{lingo.published} exactly #{expected.count} times

    #{actual_events_list(events)}
    EOS
  else
    <<~EOS
    expected #{expected_events_list(expected.events)} not to #{"exactly " if expected.strict?}be #{lingo.published}

    #{actual_events_list(events)}
    EOS
  end
end