Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danp/resque-mock
Resque mocking without redis
https://github.com/danp/resque-mock
Last synced: 15 days ago
JSON representation
Resque mocking without redis
- Host: GitHub
- URL: https://github.com/danp/resque-mock
- Owner: danp
- License: mit
- Created: 2011-06-16T21:08:35.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2012-11-16T14:34:05.000Z (almost 12 years ago)
- Last Synced: 2024-09-20T09:06:30.205Z (about 2 months ago)
- Language: Ruby
- Homepage:
- Size: 91.8 KB
- Stars: 13
- Watchers: 3
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-rspec - resque-mock - Resque mocking without redis. (Mocks)
README
# resque-mock
In memory mocks for running resque without redis in test mode.
## Overview
Managing forking/background processes in test & CI environments is a
pain. `resque-mock` allows you to run resque jobs in tests without
forking or connecting to a redis server.## Usage
Activate `resque-mock` by calling `Resque.mock!` in your test setup code.
require 'resque'
require 'resque/mock'class VerifyUserTest < Test::Unit::TestCase
def setup
Resque.mock!
enddef test_verify_user
# model with a some states
user = User.new(:state => :signup)# resque job which verifies a user
VerifyUser.enqueue(user.id)# probably have to reload this guy
user.reload!# the job has ran, the user should be verified
assert_equal user.state, :verified
end
endThe `VerifyUser.enqueue` is synchronous and will block until the job
returns.## Async Jobs
You can run jobs asynchronously with `Resque.async`.
class AsyncTest < Test::Unit::TestCase
def setup
Resque.mock!
enddef test_async_verify
user = User.new(:state => :signup)Resque.async do
# this job might take a while, and spawn other jobs.
VerifyUser.enqueue(user.id)# it's a slow job, so it probably won't be finished yet.
user.reload!
assert_not_equal user.state, :verified
end# the block doesn't return until all jobs are finished, so
# the verify job should be done
assert_equal user.state, :verified
end
endAsync jobs are pushed onto a worker queue managed by a manager thread.
Each job is then started in it's own thread.## resque-scheduler
`resque-mock` can also mock `resque-scheduler`'s `Resque.enqueue_in` and
`Resque.enqueue_at` methods.## Contributors
Dan Peterson (https://github.com/dpiddy)
Ben Burkert (https://github.com/benburkert)