{"id":13880045,"url":"https://github.com/gocardless/rspec-activejob","last_synced_at":"2025-07-16T16:30:42.633Z","repository":{"id":25829610,"uuid":"29268955","full_name":"gocardless/rspec-activejob","owner":"gocardless","description":"RSpec matchers for testing ActiveJob","archived":true,"fork":false,"pushed_at":"2017-08-18T16:14:06.000Z","size":51,"stargazers_count":99,"open_issues_count":2,"forks_count":17,"subscribers_count":99,"default_branch":"master","last_synced_at":"2025-07-16T03:44:51.984Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gocardless.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-14T22:24:35.000Z","updated_at":"2025-02-06T00:48:38.000Z","dependencies_parsed_at":"2022-07-27T05:32:24.961Z","dependency_job_id":null,"html_url":"https://github.com/gocardless/rspec-activejob","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/gocardless/rspec-activejob","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gocardless%2Frspec-activejob","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gocardless%2Frspec-activejob/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gocardless%2Frspec-activejob/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gocardless%2Frspec-activejob/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gocardless","download_url":"https://codeload.github.com/gocardless/rspec-activejob/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gocardless%2Frspec-activejob/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265524602,"owners_count":23782009,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-06T08:02:44.915Z","updated_at":"2025-07-16T16:30:42.386Z","avatar_url":"https://github.com/gocardless.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"![TravisCI status](https://travis-ci.org/gocardless/rspec-activejob.svg?branch=master)\n\n# Deprecated\n\nSince v3.5, `rspec-rails` defines matchers that provide the same functionality\nas those in `rspec-activejob`.  See\n[rspec-rails docs](https://relishapp.com/rspec/rspec-rails/v/3-5/docs/matchers/have-been-enqueued-matcher)\nfor more detail.\n\n# Installation\n\n```gem install rspec-activejob ```\n\nOr add it to the Gemfile into the :development and :test group\n\n```ruby\n# Gemfile\ngroup :development, :test do\n  ...\n  gem 'rspec-activejob'\n  ...\nend\n```\n\n# RSpec ActiveJob matchers\n\n```ruby\n# config/environments/test.rb\nconfig.active_job.queue_adapter = :test\n\n# spec/spec_helper.rb\nrequire 'rspec/active_job'\n\nRSpec.configure do |config|\n  config.include(RSpec::ActiveJob)\n\n  # clean out the queue after each spec\n  config.after(:each) do\n    ActiveJob::Base.queue_adapter.enqueued_jobs = []\n    ActiveJob::Base.queue_adapter.performed_jobs = []\n  end\nend\n\n# spec/controllers/my_controller_spec.rb\nRSpec.describe MyController do\n  let(:user) { create(:user) }\n  let(:params) { { user_id: user.id }.with_indifferent_access }\n  subject(:make_request) { described_class.make_request(params) }\n\n  specify { expect { make_request }.to enqueue_a(RequestMaker).with(global_id(user), deserialize_as(params)) }\n\n  # or\n  make_request\n  expect(RequestMaker).to have_been_enqueued.with(global_id(user), deserialize_as(params))\nend\n```\n\nrspec-activejob expects the current queue adapter to expose an array of `enqueued_jobs`, like the included\ntest adapter. The test adapter included in ActiveJob 4.2.0 does not fully serialize its arguments, so you\nwill not need to use the GlobalID matcher unless you're using ActiveJob 4.2.1. See rails/rails#18266 for\nthe improved test adapter.\n\nThis gem defines four matchers:\n\n* `enqueue_a`: for a block or proc, expects that to enqueue an job to the ActiveJob test adapter. Optionally\n  takes the job class as its argument, and can be modified with a `.with(*args)` call to expect specific arguments.\n  This will use the same argument list matcher as rspec-mocks' `receive(:message).with(*args)` matcher.\n  To verify the queue name (useful when `queue_as` was passed a block) use `.as(queue_name)` modifier.\n  If your job uses `set(wait_until: time)`, you can use `.to_run_at(time)` chain after `enqueue_a` call as well.\n  In order to check for the right number of enqueued jobs use a `.once` or `.times(n)` modifiers.\n\n* `have_been_enqueued`: expects to have enqueued an job in the ActiveJob test adapter. Optionally accepts all the\n  same modifiers as `enqueue_a`.\n\n* `global_id(model_or_class)`: an argument matcher, matching ActiveJob-serialized versions of model classes or\n  specific models (or any other class which implements `to_global_id`). If you pass a model class, it will match\n  the serialized version of any instance of that model; if you pass an instance, it will expect the serialized\n  version of that specific instance.\n\n* `deserialize_as(hash)`: an argument matcher, matching ActiveJob-serialized versions of hashes (with\n  string/symbol keys, or with indifferent access).  This is required to properly match an instance of `ActionController::Parameters` in a controller spec for instance.\n\nWith the `global_id` matcher it's important to note that it's specific to ActiveJob-serialized GlobalIDs.\nActiveJob serializes them as a hash like `{ '_aj_global_id' =\u003e 'gid://my-app/MyModel/ID123' }`, to avoid\nclashes with plain strings which accidentally match the GlobalID syntax. This matcher will not work with\nother usages of GlobalID.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgocardless%2Frspec-activejob","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgocardless%2Frspec-activejob","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgocardless%2Frspec-activejob/lists"}