@@ -7,12 +7,14 @@ module Matchers
7
7
class ErrorSubscriber
8
8
attr_reader :events
9
9
10
+ ErrorEvent = Struct . new ( :error , :attributes )
11
+
10
12
def initialize
11
13
@events = [ ]
12
14
end
13
15
14
16
def report ( error , **attrs )
15
- @events << [ error , attrs ]
17
+ @events << ErrorEvent . new ( error , attrs . with_indifferent_access )
16
18
end
17
19
end
18
20
@@ -47,7 +49,7 @@ def matches?(block)
47
49
48
50
return attributes_match_if_specified?
49
51
ensure
50
- ::Rails . error . unsubscribe ( @error_subscriber ) if @error_subscriber
52
+ ::Rails . error . unsubscribe ( @error_subscriber )
51
53
end
52
54
53
55
def supports_block_expectations?
@@ -73,7 +75,7 @@ def description
73
75
74
76
def failure_message
75
77
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" ]
77
79
unmatched = unmatched_attributes ( event_context )
78
80
unless unmatched . empty?
79
81
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?
129
131
return true if @attributes . empty?
130
132
return false if @error_subscriber . events . empty?
131
133
132
- event_context = @error_subscriber . events . last [ 1 ] . with_indifferent_access [ "context" ]
134
+ event_context = @error_subscriber . events . last . attributes [ "context" ]
133
135
attributes_match? ( event_context )
134
136
end
135
137
136
138
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
138
140
end
139
141
140
142
def attributes_match? ( actual )
0 commit comments