在RSpec without stubbing the former中编写与Resque相关的规范的最佳方法是什么?
我们目前使用以下帮助程序:
@dir = File.dirname(File.expand_path(__FILE__))
def start_redis
`redis-server #{@dir}/redis-test.conf`
Resque.redis = "localhost:9736"
end
def stop_redis
`rm -f #{@dir}/dump.rdb`
pid = `ps -A -o pid,command | grep [r]edis-test`.split(" ")[0]
Process.kill("KILL", pid.to_i)
end
Rspec.configure do |config|
config.before(:suite) do
start_redis
end
config.after(:suite) do
stop_redis
end
config.before(:each) do
Resque.redis.flushall
end
end
从Resque自己的测试帮助中大量借用,这可以正常工作,但当整个规范套件通过rake运行时会发出恼人的zsh: killed rake
。
答案 0 :(得分:12)
以下是关于如何在规范中最佳运行Redis流程的建议:
答案 1 :(得分:6)
您可以使用resque_spec gem http://github.com/leshill/resque_spec。一堆测试resque的匹配器。