Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to write Resque-related specs in RSpec?

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.

like image 660
Hakan Ensari Avatar asked Aug 13 '10 09:08

Hakan Ensari


2 Answers

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

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

like image 128
Dia Kharrat Avatar answered Nov 15 '22 10:11

Dia Kharrat


You can use the resque_spec gem http://github.com/leshill/resque_spec . A bunch of matcher to test resque.

like image 42
shingara Avatar answered Nov 15 '22 11:11

shingara