Module: ResqueUnit::SchedulerAssertions

Defined in:
lib/resque_unit/scheduler_assertions.rb

Instance Method Summary collapse

Instance Method Details

#assert_not_queued_at(expected_timestamp, klass, args = nil, message = nil) ⇒ Object

opposite of assert_queued_at



29
30
31
32
33
34
# File 'lib/resque_unit/scheduler_assertions.rb', line 29

def assert_not_queued_at(expected_timestamp, klass, args = nil, message = nil)
  queue = Resque.queue_for(klass)
  assert_block (message || "#{klass} should not have been queued in #{queue} before #{expected_timestamp}.") do 
    !in_timestamped_queue?(queue, expected_timestamp, klass, args)
  end
end

#assert_not_queued_in(expected_time_difference, klass, args = nil, message = nil) ⇒ Object

opposite of assert_queued_in



37
38
39
# File 'lib/resque_unit/scheduler_assertions.rb', line 37

def assert_not_queued_in(expected_time_difference, klass, args = nil, message = nil)
  assert_not_queued_at(Time.now + expected_time_difference, klass, args, message)
end

#assert_queued_at(expected_timestamp, klass, args = nil, message = nil) ⇒ Object

Asserts that klass has been queued into its appropriate queue at least once, with a timestamp less than or equal to expected_timestamp. If the job wasn’t queued with a timestamp, the assertion fails.. If args is nil, it only asserts that the klass has been queued. Otherwise, it asserts that the klass has been queued with the correct arguments. Pass an empty array for args if you want to assert that klass has been queued without arguments.



15
16
17
18
19
20
# File 'lib/resque_unit/scheduler_assertions.rb', line 15

def assert_queued_at(expected_timestamp, klass, args = nil, message = nil)
  queue = Resque.queue_for(klass)
  assert_block (message || "#{klass} should have been queued in #{queue} before #{expected_timestamp}: #{Resque.queue(queue).inspect}.") do 
    in_timestamped_queue?(queue, expected_timestamp, klass, args)
  end
end

#assert_queued_in(expected_time_difference, klass, args = nil, message = nil) ⇒ Object

Similar to assert_queued_at, except it takes an expected time difference (in seconds) instead of a timestamp.



24
25
26
# File 'lib/resque_unit/scheduler_assertions.rb', line 24

def assert_queued_in(expected_time_difference, klass, args = nil, message = nil)
  assert_queued_at(Time.now + expected_time_difference, klass, args, message)
end