
Product
A Fresh Look for the Socket Dashboard
We’ve redesigned the Socket dashboard with simpler navigation, less visual clutter, and a cleaner UI that highlights what really matters.
ResqueUnit provides some extra assertions and a mock Resque for testing Rails code that depends on Resque. You can install it as either a gem:
gem install resque_unit
and in your test.rb:
config.gem 'resque_unit'
ResqueUnit provides some extra assertions for your unit tests. For example, if you have code that queues a resque job:
class MyJob
@queue = :low
def self.perform(x)
# do stuff
end
end
def queue_job
Resque.enqueue(MyJob, 1)
end
You can write a unit test for code that queues this job:
def test_job_queued
queue_job
assert_queued(MyJob) # assert that MyJob was queued in the :low queue
end
You can also verify that a job was queued with arguments:
def test_job_queued_with_arguments
queue_job
assert_queued(MyJob, [1])
end
And you can run all the jobs in the queue, so you can verify that they run correctly:
def test_job_runs
queue_job
Resque.run!
assert stuff_was_done, "Job didn't run"
end
You can also access the queues directly:
def test_jobs_in_queue
queue_job
assert_equal 1, Resque.queue(:low).length
end
Finally, you can enable hooks:
Resque.enable_hooks!
class MyJobWithHooks
@queue = :hooked
def self.perform(x)
# do stuff
end
def self.after_enqueue_mark(*args)
# called when the job is enqueued
end
def self.before_perform_mark(*args)
# called just before the +perform+ method
end
def self.after_perform_mark(*args)
# called just after the +perform+ method
end
def self.failure_perform_mark(*args)
# called if the +perform+ method raised
end
end
def queue_job
Resque.enqueue(MyJobWithHooks, 1)
end
Resque.reset!
in your test's
setup method to clear all of the test queues.By calling require 'resque_unit_scheduler'
, ResqueUnit will provide
mocks for resque-scheduler's
enqueue_at
and enqueue_in
methods, along with a few extra
assertions. These are used like this:
Resque.enqueue_in(600, MediumPriorityJob) # enqueues MediumPriorityJob in 600 seconds
assert_queued_in(600, MediumPriorityJob) # will pass
assert_not_queued_in(300, MediumPriorityJob) # will also pass
Resque.enqueue_at(Time.now + 10, MediumPriorityJob) # enqueues MediumPriorityJob at 10 seconds from now
assert_queued_at(Time.now + 10, MediumPriorityJob) # will pass
assert_not_queued_at(Time.now + 1, MediumPriorityJob) # will also pass
For now, assert_queued
and assert_not_queued
will pass for any
scheduled job. Resque.run!
will run all scheduled jobs as well.
Copyright (c) 2010 Justin Weiss, released under the MIT license
FAQs
Unknown package
We found that resque_unit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
We’ve redesigned the Socket dashboard with simpler navigation, less visual clutter, and a cleaner UI that highlights what really matters.
Industry Insights
Terry O’Daniel, Head of Security at Amplitude, shares insights on building high-impact security teams, aligning with engineering, and why AI gives defenders a fighting chance.
Security News
MCP spec updated with structured tool output, stronger OAuth 2.1 security, resource indicators, and protocol cleanups for safer, more reliable AI workflows.