resque_spec
resque_spec copied to clipboard
Resque::NoQueueError: Jobs must be placed onto a queue.
Getting this error while trying to run specs using resque_spec. The error is pretty clear what is going on, however from what I understand, the queue is defined in the job that's specified in enqueue
. I have a queue defined in the job, but for some reason it isn't detecting it?
Fairly new to resque in general so it could possibly be something I'm doing wrong, however, here is my simple job and the method I'm trying to test, hopefully there's something I can do:
jobs/MakeChange.rb:
class MakeChange
def self.queue
:notification
end
def self.perform(change_id)
puts 'job started'
puts 'change is made to ' + change_id.to_s if NotificationManager::Manager.notify(change_id)
puts 'job finished'
end
end
services/notification_manager/manager.rb:
module NotificationManager
class Manager
def self.notification(owner, change_type, context, target)
change_id = Notification.new_notification(owner, change_type, context, target)
Resque.enqueue(MakeChange, change_id)
# Resque.enqueue_in(
# 30.seconds,
# MakeChange,
# change_id
# )
notification = Notification.find(change_id)
end
# run populate_test_data from console
def self.notify(change_id)
puts 'the notify method was called'
unless NotificationManager::Notification.find(change_id).cancelled?
change = Notification.find(change_id)
byebug
similar_changes = group_similar_changes(change.owner, change.target, change.change_type)
puts 'group_similar_changes finished. size: ' + similar_changes.length.to_s
mailer = NotificationManager::NotificationMailer
if mailer.send_email(mailer.construct_email(similar_changes))
puts 'the email sent'
end
end
end
end
spec/services/notification_manager/manager_spec.rb:
require 'spec_helper'
module NotificationManager
describe Manager do
describe '#notify' do
before do
ResqueSpec.reset!
end
let(:notification) { NotificationManager::Manager.notification('kyle', 'removed_as_delegate', 'work_id1', '[email protected]') }
it 'adds notification.notify to the notification queue' do
expect(Manager).to have_queued(notification.id, :notify)
end
end
end
end
Thanks for the gem, by the way, it it exactly what I needed, only I hope I can get it working :D
update: I'm using rspec-rails
as I'm working with a Rails application. I read through the readme once more and saw that support for rspec < 3.0 was iffy, so I ran bundle update rspec-rails rspec-core
which put me on the latest releases for both, but to no avail.
I just noticed that the readme makes no mention of actual Rails. I'm hoping this Gem can be used with Rails?
Hi @lawhorkl,
Sorry to be late in replying. Yes, the gem will work with Rails.
In the snippets, the use of the have_queued
matcher is possibly incorrect. The spec is checking the Manager
class while the queue is on the MakeChange
class. Does that help?