lib/qu-spec/matchers.rb in qu-spec-0.1.2 vs lib/qu-spec/matchers.rb in qu-spec-0.2.0
- old
+ new
@@ -60,5 +60,42 @@
description do
"have a queue size of #{size}"
end
end
+
+RSpec::Matchers.define :have_scheduled do |*expected_args|
+ match do |actual|
+ QuSpec.schedule_for(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(', ')}] scheduled"
+ end
+
+ failure_message_for_should_not do |actual|
+ "expected that #{actual} would not have [#{expected_args.join(', ')}] scheduled"
+ end
+
+ description do
+ "have scheduled arguments"
+ end
+end
+
+RSpec::Matchers.define :have_scheduled_at do |*expected_args|
+ match do |actual|
+ time = expected_args.shift
+ QuSpec.schedule_for(actual).any? { |entry| entry.klass.to_s == actual.to_s && entry.time == time && entry.args == expected_args }
+ end
+
+ failure_message_for_should do |actual|
+ "expected that #{actual} would have [#{expected_args.join(', ')}] scheduled"
+ end
+
+ failure_message_for_should_not do |actual|
+ "expected that #{actual} would not have [#{expected_args.join(', ')}] scheduled"
+ end
+
+ description do
+ "have scheduled at the given time the arguments"
+ end
+end