2013-05-28 113 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 

您可能還能夠使所有作業運行,但由於我只是想跑這些工作,我選擇了:那我手動排空隊列隻手動運行我關心的人。