Skip to content

Instantly share code, notes, and snippets.

@jwreagor
Last active December 15, 2015 04:59
Show Gist options
  • Save jwreagor/5205327 to your computer and use it in GitHub Desktop.
Save jwreagor/5205327 to your computer and use it in GitHub Desktop.
AssertQueue: An abstraction for testing background queuing in MiniTest, specifically Sidekiq
module AssertQueue
def assert_queued(klass, args)
assert AssertQueue.includes?(klass, args), "Queue should contain #{klass} with args #{args.inspect}\n#{AssertQueue.queue.inspect}"
end
def self.included(base)
Sidekiq::Client.instance_eval do
def push(item)
AssertQueue.queue.push item
end
end
end
private
def self.queue
@queue ||= []
end
def self.includes?(klass, args)
AssertQueue.queue.any? { |item| item['class'] == klass && item['args'] == args }
end
end
class UserNoticeTest < MyApps::UnitTest
test "queueing user notice" do
@user = create :user
assert_queued NoticeWorker, [:new_user, @user.id]
end
end
@jwreagor
Copy link
Author

Include along with your custom assertions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment