在 RSpec 中编写 Resque 相关规范的最佳方式是什么?
在 RSpec 中编写与 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
。
What's the best way to write Resque-related specs in RSpec without stubbing the former?
We currently use the following helper:
@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
Heavily borrowing from Resque's own test helper, this works fine but spews out an annoying zsh: killed rake
when the entire spec suite is run through rake.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是 resque 关于如何在您的规范中最好地运行 Redis 进程的建议:
https:// github.com/resque/resque/wiki/RSpec-and-Resque
Here's resque's recommendation for how best to run Redis processes in your specs:
https://github.com/resque/resque/wiki/RSpec-and-Resque
您可以使用 resque_spec gem http://github.com/leshill/resque_spec 。一堆匹配器来测试 resque。
You can use the resque_spec gem http://github.com/leshill/resque_spec . A bunch of matcher to test resque.