https://github.com/gocardless/rspec-que
RSpec matchers for testing Que
https://github.com/gocardless/rspec-que
Last synced: about 2 months ago
JSON representation
RSpec matchers for testing Que
- Host: GitHub
- URL: https://github.com/gocardless/rspec-que
- Owner: gocardless
- License: mit
- Created: 2015-04-07T09:47:01.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2020-07-20T11:22:18.000Z (almost 5 years ago)
- Last Synced: 2025-04-06T10:03:25.119Z (2 months ago)
- Language: Ruby
- Size: 37.1 KB
- Stars: 1
- Watchers: 94
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# RSpec Que matchers
This gem defines a matcher for checking that Que jobs have been enqueued,
in the style of [rspec-activejob](https://github.com/gocardless/rspec-activejob).## Installation
Add the dependency to your application's Gemfile:
gem 'rspec-que', '~> 1.1.0'
And then install from your Gemfile:
$ bundle
## Usage
The matcher expects a block of code, and will expect that code to enqueue a job
in Que. The matcher can take a class for the job as its arguments. It can also
expect the job to be queued with arguments via `.with(arg1, arg2)` or at a
specific time via `.at(time)`.If the matcher does not match, it will display informations about jobs queued
at the last stage of the matcher which did match. (For instance, if you specify
a job class, arguments, and a time, the matcher will display information about
jobs of the right class and arguments but at the wrong time.)```ruby
# spec/spec_helper.rb
require 'rspec/que'RSpec.configure do |config|
config.include(RSpec::Que)# clean out the queue after each spec
config.after(:each) do
RSpec::Que.purge_jobs
end
end# spec/controllers/my_controller_spec.rb
RSpec.describe MyController do
let(:user) { create(:user) }
let(:params) { { user_id: user.id } }
let(:later_time) { DateTime.parse("2038-01-01T01:02:03+00:00").utc }
subject(:make_request) { described_class.make_request(params) }specify { expect { make_request }.to queue_up(RequestMaker).with(user) }
specify { expect { make_request }.to queue_up(DelayedRequest).at(later_time) }
end
```## Development
Setup:
``` shell
bundle install
```Run tests:
``` shell
bundle exec rake```