lib/resque_spec/matchers.rb in resque_spec-0.14.4 vs lib/resque_spec/matchers.rb in resque_spec-0.15.0
- old
+ new
@@ -1,23 +1,21 @@
require 'rspec/core'
require 'rspec/expectations'
require 'rspec/mocks'
module InQueueHelper
- def self.extended(klass)
- klass.instance_eval do
- self.queue_name = nil
- chain :in do |queue_name|
- self.queue_name = queue_name
- end
+ def self.included(klass)
+ klass.class_eval do
+ attr_accessor :queue_name
end
end
- private
+ def in(queue_name)
+ self.queue_name = queue_name
+ self
+ end
- attr_accessor :queue_name
-
def queue(actual)
if @queue_name
ResqueSpec.queue_by_name(@queue_name)
else
ResqueSpec.queue_for(actual)
@@ -25,18 +23,18 @@
end
end
RSpec::Matchers.define :be_queued do |*expected_args|
- extend InQueueHelper
+ include InQueueHelper
chain :times do |num_times_queued|
@times = num_times_queued
@times_info = @times == 1 ? ' once' : " #{@times} times"
end
- chain :once do |num_times_queued|
+ chain :once do
@times = 1
@times_info = ' once'
end
match do |actual|
@@ -65,18 +63,18 @@
"be queued with arguments of [#{expected_args.join(', ')}]#{@times_info}"
end
end
RSpec::Matchers.define :have_queued do |*expected_args|
- extend InQueueHelper
+ include InQueueHelper
chain :times do |num_times_queued|
@times = num_times_queued
@times_info = @times == 1 ? ' once' : " #{@times} times"
end
- chain :once do |num_times_queued|
+ chain :once do
@times = 1
@times_info = ' once'
end
match do |actual|
@@ -105,11 +103,11 @@
"have queued arguments of [#{expected_args.join(', ')}]#{@times_info}"
end
end
RSpec::Matchers.define :have_queue_size_of do |size|
- extend InQueueHelper
+ include InQueueHelper
match do |actual|
queue(actual).size == size
end
@@ -125,11 +123,11 @@
"have a queue size of #{size}"
end
end
RSpec::Matchers.define :have_queue_size_of_at_least do |size|
- extend InQueueHelper
+ include InQueueHelper
match do |actual|
queue(actual).size >= size
end
@@ -145,23 +143,21 @@
"have a queue size of at least #{size}"
end
end
module ScheduleQueueHelper
- def self.extended(klass)
- klass.instance_eval do
- self.queue_name = nil
- chain :queue do |queue_name|
- self.queue_name = queue_name
- end
+ def self.included(klass)
+ klass.class_eval do
+ attr_accessor :queue_name
end
end
- private
+ def queue(queue_name)
+ self.queue_name = queue_name
+ self
+ end
- attr_accessor :queue_name
-
def schedule_queue_for(actual)
if @queue_name
ResqueSpec.queue_by_name(@queue_name)
else
ResqueSpec.schedule_for(actual)
@@ -169,11 +165,11 @@
end
end
RSpec::Matchers.define :have_scheduled do |*expected_args|
- extend ScheduleQueueHelper
+ include ScheduleQueueHelper
chain :at do |timestamp|
@interval = nil
@time = timestamp
@time_info = "at #{@time}"
@@ -214,11 +210,11 @@
"have scheduled arguments"
end
end
RSpec::Matchers.define :have_scheduled_at do |*expected_args|
- extend ScheduleQueueHelper
+ include ScheduleQueueHelper
warn "DEPRECATION WARNING: have_scheduled_at(time, *args) is deprecated and will be removed in future. Please use have_scheduled(*args).at(time) instead."
match do |actual|
time = expected_args.first
other_args = expected_args[1..-1]
@@ -237,11 +233,11 @@
"have scheduled at the given time the arguments"
end
end
RSpec::Matchers.define :have_schedule_size_of do |size|
- extend ScheduleQueueHelper
+ include ScheduleQueueHelper
match do |actual|
schedule_queue_for(actual).size == size
end
@@ -257,10 +253,10 @@
"have schedule size of #{size}"
end
end
RSpec::Matchers.define :have_schedule_size_of_at_least do |size|
- extend ScheduleQueueHelper
+ include ScheduleQueueHelper
match do |actual|
schedule_queue_for(actual).size >= size
end