File tree 1 file changed +15
-4
lines changed
spec/rspec/rails/matchers
1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -225,14 +225,25 @@ def self.name; "LoggingJob"; end
225
225
} . to have_enqueued_job . at ( time )
226
226
end
227
227
228
- skip_freeze_time = method_defined? ( :freeze_time ) ? false : "#freeze_time is undefined"
229
- it "works with time offsets" , skip : skip_freeze_time do
230
- freeze_time do
231
- time = Time . current
228
+ it "works with time offsets" do
229
+ # note that Time.current does not replicate Rails behavior for 5 seconds from now.
230
+ time = Time . current . change ( usec : 0 )
231
+ travel_to time do
232
232
expect { hello_job . set ( wait : 5 ) . perform_later } . to have_enqueued_job . at ( time + 5 )
233
233
end
234
234
end
235
235
236
+ it "warns when time offsets are inprecise" do
237
+ expect ( RSpec ) . to receive ( :warn_with ) . with ( /precision error/ )
238
+
239
+ time = Time . current . change ( usec : 550 )
240
+ travel_to time do
241
+ expect {
242
+ expect { hello_job . set ( wait : 5 ) . perform_later } . to have_enqueued_job . at ( time + 5 )
243
+ } . to raise_error ( /expected to enqueue exactly 1 jobs/ )
244
+ end
245
+ end
246
+
236
247
it "accepts composable matchers as an at date" do
237
248
future = 1 . minute . from_now
238
249
slightly_earlier = 58 . seconds . from_now
You can’t perform that action at this time.
0 commit comments