Created
May 1, 2019 12:00
-
-
Save yevgenko/96900b94041564d93226d7d719f2337d to your computer and use it in GitHub Desktop.
GOOS: auction snipper, single message listener
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
# | |
# 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