【发布时间】:2012-10-27 01:15:36
【问题描述】:
我想测试一些 resque 工作人员,以及将工作与这些工作人员一起排队的操作。我正在使用 rspec 和 rails。
目前我有一个模型,我们称之为 Article.rb,它有一个名为 updates_related_categories 的 before_save 方法,用于检查是否需要将具有 CategoriesSorter 的作业加入队列。如果是这样,它将与该工作人员一起排队工作,并使用与文章相关的类别 id 的参数。
然而,在测试中,这些作业被发送到与开发服务器发送作业相同的队列中。 (我使用 resque 服务器进行检查,您可以在 root/redis/overview 中绑定到您的服务器)
我想知道:
1) 如何将测试作业发送到与开发作业不同的队列?
如果可能的话,也欢迎任何其他关于测试 resque 的建议。
我看到了一些相关的问题,建议使用 resque-unit 和 resque-spec,但这些问题还很不成熟,我无法让它们进入有用的工作状态。另外,我听说过使用 Resque.inline,但我不知道在这种情况下是否相关,因为在测试规范中没有调用 resque,它是在保存测试中创建的对象的文章模型中调用的。
示例代码:
Article.rb:
before_save :update_related_categories
def update_related_categories
#some if statements/checks to see if a related category needs updating
Resque.enqueue(CategoriesWorker, [category_id])
end
end
分类排序器:
class CategoriesSorter
@queue=:sorting_queue
def self.perform(ids)
ids.each do |id|
#some code
end
end
end
规格:
it "should do something" do
@article = #set something to enqueue a job
@article.save
#can i check if a job is enqueued? can i send this job NOT to the development queue but a different one?
end
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 rspec rspec2 resque