lib/resque_spec/matchers.rb in resque_spec-0.16.0 vs lib/resque_spec/matchers.rb in resque_spec-0.17.0

- old
+ new

@@ -4,12 +4,12 @@ module ArgsHelper private def match_args(expected_args, args) - arg_list_matcher = RSpec::Mocks::ArgumentListMatcher.new(expected_args) - arg_list_matcher.args_match?(args) + arg_list_matcher = RSpec::Mocks::ArgumentListMatcher.new(*expected_args) + arg_list_matcher.args_match?(*args) end end module InQueueHelper include ArgsHelper @@ -73,50 +73,12 @@ "be queued with arguments of [#{expected_args.join(', ')}]#{@times_info}" end end -RSpec::Matchers.define :have_queued do |*expected_args| - include InQueueHelper +RSpec::Matchers.alias_matcher :have_queued, :be_queued - chain :times do |num_times_queued| - @times = num_times_queued - @times_info = @times == 1 ? ' once' : " #{@times} times" - end - - chain :once do - @times = 1 - @times_info = ' once' - end - - match do |actual| - matched = queue(actual).select do |entry| - klass = entry.fetch(:class) - args = entry.fetch(:args) - klass.to_s == actual.to_s && match_args(expected_args, args) - end - - if @times - matched.size == @times - else - matched.size > 0 - end - end - - failure_message do |actual| - "expected that #{actual} would have [#{expected_args.join(', ')}] queued#{@times_info}" - end - - failure_message_when_negated do |actual| - "expected that #{actual} would not have [#{expected_args.join(', ')}] queued#{@times_info}" - end - - description do - "have queued arguments of [#{expected_args.join(', ')}]#{@times_info}" - end -end - RSpec::Matchers.define :have_queue_size_of do |size| include InQueueHelper match do |actual| queue(actual).size == size @@ -198,10 +160,10 @@ schedule_queue_for(actual).any? do |entry| class_matches = entry[:class].to_s == actual.to_s args_match = match_args(expected_args, entry[:args]) time_matches = if @time - entry[:time] == @time + entry[:time].to_i == @time.to_i elsif @interval entry[:time].to_i == (entry[:stored_at] + @interval).to_i else true end