Last active
September 3, 2015 08:47
-
-
Save m4tm4t/b40f9ed4fa4941bf78c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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