require 'test_helper' class BackrubTest < MiniTest::Unit::TestCase class MockStore < Backrub::Store::Base end def setup Backrub.store = MockStore.new end def test_subscribing channels = { first_channel: 0, second_channel: 2 } Backrub.store.expects(:backlog).with("second_channel", 2).multiple_yields(["second_channel", "first_bit"], ["second_channel", "second_bit"]) expected_data = [ ["second_channel", "first_bit"], ["second_channel", "second_bit"], ["first_channel", "third_bit"], ] Backrub.store.expects(:subscribe).with("first_channel", "second_channel").yields(["first_channel", "third_bit"]) data = [] Backrub.subscribe(channels) do |channel, message| data << [channel, message] end assert_equal expected_data, data end def test_publishing Backrub.store.expects(:publish).with("test", "data") Backrub.publish("test", "data") end end