views:

26

answers:

1

I am trying to run rspecs for a custom delayed job (GetPage::GetPageJob), but I have a problem.

When I run them, the jobs are well enqueued (that is to say, well inserted in the delayed_jobs table), but they are not processed by the job worker. Indeed, after launching "rake jobs:work RAILS_ENV=test" in a first terminal, and after running the specs in a second terminal, I don't see any output from the job worker in the first terminal.

On the other hand, the jobs are well processed if I enqueue them via "script/console test". So I'm a bit confused.

With both the specs and the script/console, the line I use to enqueue my jobs is :

Delayed::Job.enqueue GetPage::GetPageJob.new("http://cnn.com")

Any idea ?

A: 

In the past, I've tried to do an end-to-end test of logic -> delayed-job -> perform job, and it was too many things. I think rather than test that full sweet using RSpec, you could focus on testing each aspect.

So, test that a job gets inserted. Then, have another test that tests what should happen when a job is executed.

Alternatively, mock out the delayed-job, so that when you enqueue a job, it executes it right away.

Jesse Wolgamott