Sha256: 1d5215bafc96c0609c2da9a8328ceb574d2dffe33e2bc6652d6a1f053463f3a8

Contents?: true

Size: 1.55 KB

Versions: 5

Compression:

Stored size: 1.55 KB

Contents

require 'resque_spec'

module ResqueSpec

  def scheduled?(klass, time, *args)
    schedule_for(klass).any? {|entry| entry[:klass] == klass && entry[:time] == time && entry[:args] == args}
  end

  def scheduled_anytime?(klass, *args)
    schedule_for(klass).any? {|entry| entry[:klass] == klass && entry[:args] == args}
  end

  def schedule_for(klass)
    name = queue_name(klass).to_s << "_scheduled"
    queues[name]
  end

  module ResqueScheduler
    def enqueue_at(time, klass, *args)
      ResqueSpec.schedule_for(klass) << {:klass => klass, :time  => time, :args => args}
    end
  end
end

Resque.extend(ResqueSpec::ResqueScheduler)

Spec::Matchers.define :have_scheduled do |*expected_args|
  match do |actual|
    ResqueSpec.scheduled_anytime?(actual, *expected_args)
  end

  failure_message_for_should do |actual|
    "expected that #{actual} would have [#{expected_args.join(', ')}] queued"
  end

  failure_message_for_should_not do |actual|
    "expected that #{actual} would not have [#{expected_args.join(', ')}] queued"
  end

  description do
    "have scheduled arguments"
  end
end

Spec::Matchers.define :have_scheduled_at do |*expected_args|
  match do |actual|
    ResqueSpec.scheduled?(actual, *expected_args)
  end

  failure_message_for_should do |actual|
    "expected that #{actual} would have [#{expected_args.join(', ')}] queued"
  end

  failure_message_for_should_not do |actual|
    "expected that #{actual} would not have [#{expected_args.join(', ')}] queued"
  end

  description do
    "have scheduled at the given time the arguments"
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
ryansch-resque_spec-0.2.3.1 lib/resque_spec/resque_scheduler_spec.rb
resque_spec-0.2.3 lib/resque_spec/resque_scheduler_spec.rb
resque_spec-0.2.2 lib/resque_spec/resque_scheduler_spec.rb
resque_spec-0.2.1 lib/resque_spec/resque_scheduler_spec.rb
resque_spec-0.2.0 lib/resque_spec/resque_scheduler_spec.rb