在 RSpec 中编写 Resque 相关规范的最佳方式是什么?

发布于 2024-09-14 04:44:24 字数 742 浏览 2 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怎言笑 2024-09-21 04:44:24

以下是 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

娇柔作态 2024-09-21 04:44:24

您可以使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文