Sha256: 20a281aaf5090661460392dd177f48e0c3fe368d9cfcea7472201fca36f90f31

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

require 'rspec'

module InQueueHelper
  def self.extended(klass)
    klass.instance_eval do
      chain :in do |queue_name|
        self.queue_name = queue_name
      end
    end
  end

  private

  attr_accessor :queue_name

  def queue(actual)
    if @queue_name
      Qu.backend.get_queue_by_name(@queue_name)
    else
      Qu.backend.get_queue_by_klass(actual)
    end
  end

end

RSpec::Matchers.define :have_queued do |*expected_args|
  extend InQueueHelper

  match do |actual|
    queue(actual).any? { |entry| entry.klass.to_s == actual.to_s && entry.args == 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 of [#{expected_args.join(', ')}]"
  end
end

RSpec::Matchers.define :have_queue_size_of do |size|
  extend InQueueHelper

  match do |actual|
    queue(actual).size == size
  end

  failure_message_for_should do |actual|
    "expected that #{actual} would have #{size} entries queued, but got #{queue(actual).size} instead"
  end

  failure_message_for_should_not do |actual|
    "expected that #{actual} would not have #{size} entries queued, but got #{queue(actual).size} instead"
  end

  description do
    "have a queue size of #{size}"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
qu-spec-0.1.2 lib/qu-spec/matchers.rb