Rspec Matcher for delayed jobs
Have you ever tried to confirm that a particular delayed job would be fired in rspec?
Now you can, with this custom matcher:
RSpec::Matchers.define :startdelayedjobs do |*expected|
match_for_should do |delayed_jobs|
jobs = Delayed::Backend::ActiveRecord::Job.all.map do |job|
YAML.load(job.handler).method_name
end
expected.any? do |e|
jobs.include?(e)
end
end
match_for_should_not do |delayed_jobs|
jobs = Delayed::Backend::ActiveRecord::Job.all.map do |job|
YAML.load(job.handler).method_name
end
expected.none? do |e|
jobs.include?(e)
end
end
end
so you can do things like this:
object.should_not start_delayed_jobs(:method)
Written by Val
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rspec
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#