8

前者をスタブせずに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自身のテストヘルパーから大いに借りて、これはうまく機能しますがzsh: killed rake、スペックスイート全体がレーキを通過するときに迷惑を吐き出します。

4

2 に答える 2

12

Here's resque's recommendation for how best to run Redis processes in your specs:

https://github.com/resque/resque/wiki/RSpec-and-Resque

于 2011-07-22T04:40:17.280 に答える
6

resque_spec gem http://github.com/leshill/resque_specを使用できます。resque をテストするためのマッチャーの束。

于 2010-08-13T13:11:07.827 に答える