File tree Expand file tree Collapse file tree 4 files changed +46
-6
lines changed
spec/rspec/rails/matchers Expand file tree Collapse file tree 4 files changed +46
-6
lines changed Original file line number Diff line number Diff line change 5
5
- ' main'
6
6
- ' *-maintenance'
7
7
- ' *-dev'
8
+ - ' *'
8
9
pull_request :
9
10
branches :
10
11
- ' *'
Original file line number Diff line number Diff line change @@ -230,11 +230,25 @@ def initialize(job)
230
230
def matches? ( proc )
231
231
raise ArgumentError , "have_enqueued_job and enqueue_job only support block expectations" unless Proc === proc
232
232
233
- original_enqueued_jobs_count = queue_adapter . enqueued_jobs . count
233
+ original_enqueued_jobs_hashes = queue_adapter . enqueued_jobs . map ( & :hash )
234
234
proc . call
235
- in_block_jobs = queue_adapter . enqueued_jobs . drop ( original_enqueued_jobs_count )
236
235
237
- check ( in_block_jobs )
236
+ in_block_jobs = queue_adapter . enqueued_jobs . each_with_object ( { } ) do |job , memo |
237
+ memo [ job . hash ] ||= { job : job , count : 0 }
238
+ memo [ job . hash ] [ :count ] += 1
239
+ end
240
+
241
+ original_enqueued_jobs_hashes . each do |job_hash |
242
+ in_block_jobs [ job_hash ] [ :count ] -= 1 if in_block_jobs . key? ( job_hash )
243
+ end
244
+
245
+ in_block_jobs = in_block_jobs . flat_map do |hash , job_and_count |
246
+ count , job = job_and_count . values_at ( :count , :job )
247
+
248
+ Array . new ( count , job ) if count . positive?
249
+ end
250
+
251
+ check ( in_block_jobs . compact )
238
252
end
239
253
240
254
def does_not_match? ( proc )
Original file line number Diff line number Diff line change @@ -46,12 +46,12 @@ Gem::Specification.new do |s|
46
46
# get released.
47
47
%w[ core expectations mocks support ] . each do |name |
48
48
if ENV [ 'RSPEC_CI' ]
49
- s . add_runtime_dependency "rspec-#{ name } " , ENV . fetch ( 'RSPEC_VERSION' , '3.11 .0.pre' )
49
+ s . add_runtime_dependency "rspec-#{ name } " , ENV . fetch ( 'RSPEC_VERSION' , '3.12 .0.pre' )
50
50
elsif RSpec ::Rails ::Version ::STRING =~ /pre/ # prerelease builds
51
- expected_rspec_version = "3.11 .0.pre"
51
+ expected_rspec_version = "3.12 .0.pre"
52
52
s . add_runtime_dependency "rspec-#{ name } " , "= #{ expected_rspec_version } "
53
53
else
54
- expected_rspec_version = "3.10 .0"
54
+ expected_rspec_version = "3.11 .0"
55
55
s . add_runtime_dependency "rspec-#{ name } " , "~> #{ expected_rspec_version . split ( "." ) [ 0 ..1 ] . join ( "." ) } "
56
56
end
57
57
end
Original file line number Diff line number Diff line change @@ -98,6 +98,31 @@ def self.name; "LoggingJob"; end
98
98
expect { } . not_to have_enqueued_job
99
99
end
100
100
101
+ context "when job is retried" do
102
+ include ActiveJob ::TestHelper
103
+
104
+ let ( :retried_job ) do
105
+ Class . new ( ActiveJob ::Base ) do
106
+ retry_on StandardError , wait : 5 , queue : :retry
107
+
108
+ def self . name ; "RetriedJob" ; end
109
+ def perform ; raise StandardError ; end
110
+ end
111
+ end
112
+
113
+ before do
114
+ stub_const ( "RetriedJob" , retried_job )
115
+ queue_adapter . perform_enqueued_jobs = true
116
+ end
117
+
118
+ it "passes with reenqueued job" do
119
+ time = Time . current . change ( usec : 0 )
120
+ travel_to time do
121
+ expect { retried_job . perform_later } . to have_enqueued_job ( retried_job ) . on_queue ( :retry ) . at ( time + 5 )
122
+ end
123
+ end
124
+ end
125
+
101
126
it "fails when job is not enqueued" do
102
127
expect {
103
128
expect { } . to have_enqueued_job
You can’t perform that action at this time.
0 commit comments