Resque your RSpec

To start testing your Resque:

  1. Use the awesome ResqueSpec
# Gemfile
group :test do
  gem 'resque_spec'
  1. In your spec testing, play around with “have_queue_size_of” and “have_queued”.

Example, if you have a worker called SoldPropertyMessenger with its perform action taking in a param of an ‘id’

# app/workers/sold_property_messenger.rb
class SoldPropertyMessenger
  @queue = :notification
  def self.perform(id)
    # magic

Your spec/controller test could do something like:

it "blah blagh blah" do 
  SoldPropertyMessenger.should have_queued(id)

Additional Caveats:

As a tip, normally I would flush my redis database before the start of each test. This is to ensure a clean pristine redis db during tests.

# Assuming your Redis object is $redis

Also, you should make sure that Resque runs on inline when in test mode. This runs the queuing synchronously and probably save you a little bit of headaches.


# in a config/initializer/anything.rb
Resque.inline = Rails.env.test?

# Basically you want inline to be true during testing.

Add that in your before callback on each spec.