Sha256: 664f7a7c42bc7b2b630cd4e1d20aa59fd6b654909cf1d7507e0f3de9f63db486
Contents?: true
Size: 1.29 KB
Versions: 2
Compression:
Stored size: 1.29 KB
Contents
require 'resque' module ResqueSpec extend self def in_queue?(klass, *args) queue_for(klass).any? {|entry| entry[:klass] == klass && entry[:args] == args} end def queue_for(klass) queues[queue_name(klass)] end def queue_name(klass) name_from_instance_var(klass) or name_from_queue_accessor(klass) or raise ::Resque::NoQueueError.new("Jobs must be placed onto a queue.") end def queues @queues ||= Hash.new {|h,k| h[k] = []} end def reset! queues.clear end module Resque def enqueue(klass, *args) ResqueSpec.queue_for(klass) << {:klass => klass, :args => args} end end private def name_from_instance_var(klass) klass.instance_variable_get(:@queue) end def name_from_queue_accessor(klass) klass.respond_to?(:queue) and klass.queue end end Resque.extend(ResqueSpec::Resque) Spec::Matchers.define :have_queued do |*expected_args| match do |actual| ResqueSpec.in_queue?(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 queued arguments" end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
resque_spec-0.2.2 | lib/resque_spec/resque_spec.rb |
resque_spec-0.2.1 | lib/resque_spec/resque_spec.rb |