2013-05-28 112 views
2

我有一种方法可以启动两个不同的Sidekiq工作人员 - 一个发送电子邮件,一个发布到Faye频道到前端。我试图在一个黄瓜功能测试行为。该代码在开发中运行良好。如何使用黄瓜测试sidekiq

我已将require 'sidekiq/testing/inline'列入features/support/env.rb,以便我可以检查工作人员努力的实际结果。电子邮件测试工作正常(使用Spreewald电子邮件步骤),但我看不到任何证据显示其他工作人员已被执行。我在工作人员中加入了'logger.debug'语句,但他们没有出现在log/test.log - 我还有什么地方应该看?

工作人员似乎不可能正在运行,但前端似乎没有收到Faye消息。任何关于如何调试的建议都会受到欢迎。

回答

2

我能在我的黄瓜测试运行我Sidekiq工人加入适当的要求support/env.rb声明:

require 'sidekiq/testing' 

如果使用叉勺,把它放在你的prefork块:

Spork.prefork do 
    # ... 
    require 'sidekiq/testing' 
    # ... 

然后我写了一个这样的功能:

When I submit the form that adds jobs to the queue 
Then I should see "Your jobs were added to the queue." 
When I wait for the jobs to finish 
And I refresh the page 
Then the completed jobs are listed on the page 

直列加入Sidekiq::Testing.inline!support/env.rb后需要声明

When(/^I wait for the jobs to finish$/) do 
    MySpecialWorker.drain 
end 

您可能还能够使所有作业运行,但由于我只是想跑这些工作,我选择了:那我手动排空队列只手动运行我关心的人。