How to test background jobs (Sidekiq) with Rspec?

mind.blank picture mind.blank · Mar 30, 2013 · Viewed 23.8k times · Source

A large part of my application relies on background jobs to process user's websites, so I need to write some tests to cover these.

First question is how to test code that's in a Sidekiq worker class, for example app/workers/some_worker.rb

class SomeWorker
  include Sidekiq::Worker

  def perform(model_id)
    ...
  end
end

Secondly, how do I stub code such as the following so I don't need to actually run workers and slow down my tests?

response = HTTParty.get("http://users-site.com", timeout: 30)

Answer

Mike Perham picture Mike Perham · Mar 30, 2013