Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8936025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:07:16+00:00 2026-06-15T10:07:16+00:00

I would like to test some resque workers, and the actions that enqueue jobs

  • 0

I would like to test some resque workers, and the actions that enqueue jobs with these workers. I am using rspec and rails.

Currently I have a model, let’s call it Article.rb, that has a before_save method called updates_related_categories that checks if a job with CategoriesSorter needs to be enqueued. If so, it enqueues a job with that worker, with the argument of the category id that the article is related to.

In test, however, these jobs are sent to the same queue as the development server sends jobs to. (i check using the resque server that you can tie into your server at root/redis/overview)

I want to know:

1) How can I send test jobs to a different queue than the development jobs?

If this is possible, any other advice on testing resque is also welcome.

I have seen some related questions that suggest resque-unit and resque-spec but these are pretty undeveloped, and I couldn’t get them to a useful working state. Also, I have heard of using Resque.inline but I don’t know if that is relevant in this case, as resque isn’t called in test specs, it’s called from the article model on save of objects created in test.

Sample Code:

Article.rb:

 before_save :update_related_categories
 def update_related_categories
     #some if statements/checks to see if a related category needs updating
         Resque.enqueue(CategoriesWorker, [category_id])
     end
 end

CategoriesSorter:

 class CategoriesSorter
     @queue=:sorting_queue
     def self.perform(ids)
        ids.each do |id|
           #some code
        end
      end
 end

Specs:

 it "should do something" do
     @article = #set something to enqueue a job
     @article.save
     #can i check if a job is enqueued? can i send this job NOT to the development queue but a different one?
 end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:07:17+00:00Added an answer on June 15, 2026 at 10:07 am

    As I see it, you don’t want to test whether enqueueing the job results in perform being called – we trust Resque does what it should.
    However, you can test that 1. calling update_related_categories enqueues the job. Then you can test, separately, whether 2. a worker calling perform results in the desired behavior.

    For testing Resque in general, a combination of resque-spec and simulating a worker can accomplish the above two goals.

    For 1, with resque-spec, you can simulate a worker calling the perform method on your class, and then check that it has been enqueued correctly:

    describe "Calling update_related_categories " do
      before(:each) do
        ResqueSpec.reset!
      end
    
      it "should enqueue the job" do
        Article.update_related_categories
        CategoriesSorter.should have_queue_size_of(1)
      end
    end
    

    For 2, you can create a Job (and specify a separate queue name than your development queue), a Resque::Worker and then assign the Worker to the Job:

    def run_worker_simulation
      # see Resque::Job api for setting the args you want
      Resque::Job.create('test_queue_name', 'class_name', 'type', 'id')
    
      worker = Resque::Worker.new('test_queue_name')
      worker.very_verbose = true
    
      job = worker.reserve
      worker.perform(job)
    end
    

    Hope that gives you some ideas.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some simple GWT client code that I would like to test using
I would like to test some things and I need a PostgreSQL query that
I would like to test a controller that directly renders some JSON output (by
I'm using js-test-driver to run some tests and would like to test some code
For educational purposes, I am using cstrings in some test programs. I would like
I would like to test some exception handling logic in the empty catch block
I'm refactoring some code and would like to junit test some methods but they
I would like to use the libtorrent-rasterbar to devellop some test with torren, but
I have some classes(call it Class A) which I would like to unit test
I would like to setup some automated testing of test cases upon Fortran binaries

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.