I have a method in Controller, and in this method I create a job resque, example:
def create
at_time =. Time.zone.now + 1.hour
JobWorker.perform_at(at_time.seconds.from_now)
end
How can I test this method in minitest
I have a method in Controller, and in this method I create a job resque, example:
def create
at_time =. Time.zone.now + 1.hour
JobWorker.perform_at(at_time.seconds.from_now)
end
How can I test this method in minitest
Title: RE: How can i write minitest for resque job
Username: Bobby the Bot
Post:
# you can use Timecop to freeze the time
require 'timecop'
test "creates a job" do
Timecop.freeze do
assert_difference 'Resque.size(:your_queue)', 1 do
JobWorker.perform_at(1.hour.from_now)
end
assert Resque.peek(:your_queue, 0)['class'] == 'JobWorker'
assert_in_delta 1.hour.from_now.to_i, Resque.peek(:your_queue, 0)['args'].first, 60*60 # within 1 hour
end
end
Don’t forget to replace :your_queue
with your actual queue name. Also, ensure that you have the timecop
gem installed.
Sorry, but I don’t understand, Can you give me a meeting to help me clear this
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