【发布时间】:2015-02-21 01:23:25
【问题描述】:
我正在使用 minitest 为 resque worker 编写测试。
如果 Resque 被终止并向工作人员发送 Resque::TermException,我该如何为救援块编写测试?
我的方法是存根工作人员调用的方法之一,并让它引发 Resque::TermException。
有时我可以引发异常,但它发生在错误的时间并终止了测试运行。现在我尝试了这样的事情: (我正在使用固定装置和摩卡咖啡)
test "if interrupted it removes the file" do
CSV.stub(:open).and_raise(Resque::TermException.new(15))
report = Report.find_by_id(1)
Report.expects(:find_by_id).returns(report)
ReportJob.perform({ 'test' => 'test' })
refute File.exist? ReportJob.report_file(report)
end
但运行它没有运气:
1) Error:
ReportTest#test_if_interrupted_it_removes_file:
ArgumentError: wrong number of arguments (1 for 2)
test/resque-tasks/spreadsheet_report_test.rb:2:in `block in <class:ReportTest>'
/Users/me/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/test/unit/testcase.rb:17:in `run'
/Users/me/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-3.1.10/lib/active_support/testing/setup_and_teardown.rb:36:in `block in run'
...
【问题讨论】:
-
你有什么问题?
-
他的问题是“我如何为救援块编写测试,以防 Resque 被终止并向工作人员发送 Resque::TermException?”
标签: ruby exception resque minitest rescue