Sha256: 22b5cf68ae987b303f25ba3f78f9295b88d66926c7c0c753853953ae5bbdc57a

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

require "minitest"

module ResqueUnitWithoutMock::ResqueAssertions
  def assert_queued(klass, args = nil, &block)
    queue_name = Resque.queue_for(klass)
    queue = Resque.queued(queue_name).map{|x| JSON.parse(x) }
    assert(
      in_queue?(queue, klass, args),
      "#{klass}#{args ? " with #{args.inspect}" : ""} should have been queued in #{queue_name}: #{queue.inspect}.",
    )
  end

  def assert_not_queued(klass, args = nil, &block)
    queue_name = Resque.queue_for(klass)
    queue = Resque.queued(queue_name).map{|x| JSON.parse(x) }
    assert(
      !in_queue?(queue, klass, args),
      "#{klass}#{args ? " with #{args.inspect}" : ""} should not have been queued in #{queue_name}.",
    )
  end

  private

  def in_queue?(queue, klass, args = nil)
    !matching_jobs(queue, klass, args).empty?
  end

  def matching_jobs(queue, klass, args = nil)
    normalized_args = Resque.decode(Resque.encode(args)) if args
    queue.select {|e| e["class"] == klass.to_s && (!args || e["args"] == normalized_args )}
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
resque_unit_without_mock-0.1.2 lib/resque_unit_without_mock/resque_assertions.rb
resque_unit_without_mock-0.1.1 lib/resque_unit_without_mock/resque_assertions.rb
resque_unit_without_mock-0.1.0 lib/resque_unit_without_mock/resque_assertions.rb