Module: JobIteration::TestHelper

Defined in:
lib/job-iteration/test_helper.rb

Overview

Include JobIteration::TestHelper to mock interruption when testing your jobs.

Instance Method Summary collapse

Instance Method Details

#continue_iteratingObject

Removes previous stubs and tells the job to iterate until the end.



36
37
38
# File 'lib/job-iteration/test_helper.rb', line 36

def continue_iterating
  stub_shutdown_adapter_to_return(false)
end

#iterate_exact_times(n_times) ⇒ Object

Stubs interruption adapter to interrupt the job after every N iterations.

Examples:

test "this stuff interrupts" do
  iterate_exact_times(3.times)
  MyJob.perform_now
end

Parameters:

  • n_times (Integer)

    Number of times before the job is interrupted



25
26
27
# File 'lib/job-iteration/test_helper.rb', line 25

def iterate_exact_times(n_times)
  JobIteration.stubs(:interruption_adapter).returns(StoppingSupervisor.new(n_times.size))
end

#iterate_onceObject

Stubs interruption adapter to interrupt the job after every sing iteration.



31
32
33
# File 'lib/job-iteration/test_helper.rb', line 31

def iterate_once
  iterate_exact_times(1.times)
end

#mark_job_worker_as_interruptedObject

Stubs the worker as already interrupted.



41
42
43
# File 'lib/job-iteration/test_helper.rb', line 41

def mark_job_worker_as_interrupted
  stub_shutdown_adapter_to_return(true)
end