Skip to content

Instantly share code, notes, and snippets.

@greatghoul
Created August 4, 2017 03:06
Show Gist options
  • Save greatghoul/6cea850cc77f4c5d8ee0293d0d3a4729 to your computer and use it in GitHub Desktop.
Save greatghoul/6cea850cc77f4c5d8ee0293d0d3a4729 to your computer and use it in GitHub Desktop.
RSpec: Execute jobs triggered in specific methods.
# spec/support/jobs.rb
ActiveJob::Base.queue_adapter = :test
module PerformJobsSupport
def perform_jobs_on(klass, *method_names)
klass.class_eval do
include ActiveJob::TestHelper
method_names.each do |method_name|
alias_method "origin_#{method_name}", method_name
define_method method_name do |*args, &block|
perform_enqueued_jobs do
send("origin_#{method_name}", *args, &block)
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment