Skip to content

Instantly share code, notes, and snippets.

@yevgenko
Created May 1, 2019 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yevgenko/96900b94041564d93226d7d719f2337d to your computer and use it in GitHub Desktop.
Save yevgenko/96900b94041564d93226d7d719f2337d to your computer and use it in GitHub Desktop.
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