Last active
December 15, 2015 04:59
-
-
Save jwreagor/5205327 to your computer and use it in GitHub Desktop.
AssertQueue: An abstraction for testing background queuing in MiniTest, specifically Sidekiq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserNoticeTest < MyApps::UnitTest | |
test "queueing user notice" do | |
@user = create :user | |
assert_queued NoticeWorker, [:new_user, @user.id] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Include along with your custom assertions.