如何在RSpec中测试后台进程? [英] How to test background process in RSpec?

查看:70
本文介绍了如何在RSpec中测试后台进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

找到了一种在Sinatra中运行单独进程的简单方法:在Sinatra中运行后台进程

Found this simple way to run a separate process in Sinatra: Run background process in Sinatra

get '/start_process'
  @@pid = Process.spawn('external_command_to_run')
end

您将如何在RSpec中对此进行测试?

How would you test this in RSpec?

Ruby 1.9.3.

Ruby 1.9.3.

推荐答案

提取一个类,该类将进行后台处理并对其进行单元测试.然后测试期望您的操作调用此类的方法

Extract a class which does the background processing and unit-test it. Then test expectation that your action invokes method on this class

一些伪代码":

before do
  MyWorker.should_receive(:perform)
end

specify { get :something }

这篇关于如何在RSpec中测试后台进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆