Skip to content

Commit b3b4fac

Browse files
committed
Improve enqueued_job at specs from #2350
1 parent 85a146c commit b3b4fac

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

spec/rspec/rails/matchers/active_job_spec.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,25 @@ def self.name; "LoggingJob"; end
225225
}.to have_enqueued_job.at(time)
226226
end
227227

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
232232
expect { hello_job.set(wait: 5).perform_later }.to have_enqueued_job.at(time + 5)
233233
end
234234
end
235235

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+
236247
it "accepts composable matchers as an at date" do
237248
future = 1.minute.from_now
238249
slightly_earlier = 58.seconds.from_now

0 commit comments

Comments
 (0)