我正在尝试为我的Sidekiq作业编写一些使用Sidetiq的测试,但我似乎无法让它工作。我在sidetiq repo上发现了一个处理这个问题的问题,但没有人回答这个问题,所以我想我可以把它带到stackoverflow上,以获得一些答案和清晰度。
以下是指向该问题的链接:https://github.com/tobiassvn/sidetiq/issues/72
下面是看起来不起作用的代码:
spec.rb
# sat 1st feb
Timecop.travel Time.local(2014, 2, 1, 1, 1, 1) do
sign_up_and_onboard user[:email], user[:password]
# sunday 2nd feb, 8pm
Timecop.travel Time.local(2014, 2, 2, 20, 1, 1) do
puts 'should have fired'
end
endworker.rb
recurrence { weekly.day(:sunday).hour_of_day(8) }
def perform
puts 'test'
end再次感谢你的帮助。
发布于 2014-07-23 19:41:23
从你发布的代码来看,似乎没有什么东西真正地解雇了你的员工。还不清楚你的signup_and_onboard方法做了什么--可能就是触发它们。
我建议使用sidekiq/testing (参见https://github.com/mperham/sidekiq/wiki/Testing),然后通过Sidetiq处理程序解雇您的员工,使用如下内容:
Sidekiq::Testing.inline! do
expect(
Sidetiq::Handler.new.dispatch(MyWorker, Time.now)
).to be_truthy
end在你的Timecop块中。
这是我从检查Sidetiq代码库中找到的最好的方法,它可以通过足够多的Sidetiq堆栈来解雇工人,以获得我想要在测试中看到的行为。
https://stackoverflow.com/questions/22642711
复制相似问题