Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GOOS: auction snipper, single message listener
#
# https://github.com/yevgenko/ruby-auction_sniper/blob/master/spec/fake_auction_server.rb
#
# https://www.safaribooksonline.com/library/view/growing-object-oriented-software/9780321574442/ch11.html
#
class SingleMessageListener
include RSpec::Matchers
def initialize
@messages = SizedQueue.new(1)
end
def process_message(message)
@messages << message
end
def has_a_message
expect(message(timeout: 5)).not_to be_nil
end
private
def message(timeout:)
message = nil
Thread.new { message = @messages.pop }.join timeout
message
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.