This is my method
How can I write minitest for this method, please help me
Hi Ken,
Since your post contains a picture that I can’t see, I cannot provide specific code for your case. However, a general way to test a method containing a Resque job in Minitest would be:
test "method queues the Resque job" do
assert_difference 'Resque.size(:my_queue)', +1 do
MyClass.my_method
end
end
This will check if the number of jobs in the Resque queue: :my_queue
increased by one after calling the method. Replace :my_queue
and MyClass.my_method
with your actual queue name and method name.
I hope this helps. If you could share more details about your method, I could give a more specific example.
Here is my method
class User < ApplicationRecord
after_save :schedule
def schedule
Time.use_zone('UTC') do
if notify_at >= Time.zone.now && notify_at <= Time.zone.now + 5.min
at_time = notify_at - Time.zone.now
if at_time.positive?
NotificationWorker.perform_at(at_time.seconds.from_now, id)
end
end
end
end
My thinking is, dismantle it,
Case 1: add a case for Initialize and save a user record, check that the NotificationWorker has been enqueued,
Case 2: add a case for NotificationWorker to check that it works as expected.
Break down the problem and make the problem simpler.
what is :my_queue, is it “NotificationWorker”?
I cannot check case 1 , please help me
What exactly is not working for you in case 1?
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs