@@ -67,7 +67,14 @@ def thrice
67
67
end
68
68
69
69
def failure_message
70
- "expected to enqueue #{ base_message } "
70
+ "expected to enqueue #{ base_message } " . tap do |msg |
71
+ if @unmatching_jobs . any?
72
+ msg << "\n Queued jobs:"
73
+ @unmatching_jobs . each do |job |
74
+ msg << "\n #{ base_job_message ( job ) } "
75
+ end
76
+ end
77
+ end
71
78
end
72
79
73
80
def failure_message_when_negated
@@ -89,7 +96,7 @@ def supports_block_expectations?
89
96
private
90
97
91
98
def check ( jobs )
92
- @matching_jobs_count = jobs . count do |job |
99
+ @matching_jobs , @unmatching_jobs = jobs . partition do |job |
93
100
if serialized_attributes . all? { |key , value | value == job [ key ] }
94
101
args = ::ActiveJob ::Arguments . deserialize ( job [ :args ] )
95
102
@block . call ( *args )
@@ -98,6 +105,7 @@ def check(jobs)
98
105
false
99
106
end
100
107
end
108
+ @matching_jobs_count = @matching_jobs . size
101
109
102
110
case @expectation_type
103
111
when :exactly then @expected_number == @matching_jobs_count
@@ -115,6 +123,17 @@ def base_message
115
123
end
116
124
end
117
125
126
+ def base_job_message ( job )
127
+ msg_parts = [ ]
128
+ msg_parts << "with #{ ::ActiveJob ::Arguments . deserialize ( job [ :args ] ) } " if job [ :args ] . any?
129
+ msg_parts << "on queue #{ job [ :queue ] } " if job [ :queue ]
130
+ msg_parts << "at #{ Time . at ( job [ :at ] ) } " if job [ :at ]
131
+
132
+ "#{ job [ :job ] . class . name } job" . tap do |msg |
133
+ msg << " #{ msg_parts . join ( ', ' ) } " if msg_parts . any?
134
+ end
135
+ end
136
+
118
137
def serialized_attributes
119
138
{ } . tap do |attributes |
120
139
attributes [ :args ] = ::ActiveJob ::Arguments . serialize ( @args ) if @args . any?
0 commit comments