@@ -7,12 +7,14 @@ module Matchers
77 class ErrorSubscriber
88 attr_reader :events
99
10+ ErrorEvent = Struct . new ( :error , :attributes )
11+
1012 def initialize
1113 @events = [ ]
1214 end
1315
1416 def report ( error , **attrs )
15- @events << [ error , attrs ]
17+ @events << ErrorEvent . new ( error , attrs . with_indifferent_access )
1618 end
1719 end
1820
@@ -47,7 +49,7 @@ def matches?(block)
4749
4850 return attributes_match_if_specified?
4951 ensure
50- ::Rails . error . unsubscribe ( @error_subscriber ) if @error_subscriber
52+ ::Rails . error . unsubscribe ( @error_subscriber )
5153 end
5254
5355 def supports_block_expectations?
@@ -73,7 +75,7 @@ def description
7375
7476 def failure_message
7577 if !@error_subscriber . events . empty? && !@attributes . empty?
76- event_context = @error_subscriber . events . last [ 1 ] . with_indifferent_access [ " context" ]
78+ event_context = @error_subscriber . events . last . attributes [ : context]
7779 unmatched = unmatched_attributes ( event_context )
7880 unless unmatched . empty?
7981 return "Expected error attributes to match #{ @attributes } , but got these mismatches: #{ unmatched } and actual values are #{ event_context } "
@@ -129,12 +131,12 @@ def attributes_match_if_specified?
129131 return true if @attributes . empty?
130132 return false if @error_subscriber . events . empty?
131133
132- event_context = @error_subscriber . events . last [ 1 ] . with_indifferent_access [ " context" ]
134+ event_context = @error_subscriber . events . last . attributes [ : context]
133135 attributes_match? ( event_context )
134136 end
135137
136138 def actual_error
137- @error_subscriber . events . empty? ? nil : @error_subscriber . events . last [ 0 ]
139+ @error_subscriber . events . empty? ? nil : @error_subscriber . events . last . error
138140 end
139141
140142 def attributes_match? ( actual )
0 commit comments