Skip to content

Instantly share code, notes, and snippets.

@m4tm4t
Last active September 3, 2015 08:47
Show Gist options
  • Save m4tm4t/b40f9ed4fa4941bf78c5 to your computer and use it in GitHub Desktop.
Save m4tm4t/b40f9ed4fa4941bf78c5 to your computer and use it in GitHub Desktop.
# spec/support/resque_helper.rb
module ResqueHelper
def create_worker( queue_name )
Resque.redis.flushall
@worker = Resque::Worker.new( queue_name )
@worker.register_worker
return @worker
end
def perform_next_job(worker, &block)
return unless job = worker.reserve
worker.perform(job, &block)
worker.done_working
end
end
RSpec.configure do |config|
config.include ResqueHelper
end
# your_spec.rb
it "Should retry in 10 seconds" do
allow( SomeJob ).to receive( :perform ).and_raise( Exception )
Resque.enqueue( SomeJob, "Lorem", "Ipsum" )
@worker = create_worker( :queue_name )
perform_next_job( @worker )
expect( SomeJob ).to have_scheduled(
"Lorem", "Ipsum"
).in( 10.seconds )
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment