spec/support/rabbitmq_queue_matchers.rb in basquiat-1.2.0 vs spec/support/rabbitmq_queue_matchers.rb in basquiat-1.3.0.pre.1
- old
+ new
@@ -1,11 +1,14 @@
+require 'uri'
+require 'net/http'
+
class QueueStats
def initialize(queue)
@queue = queue
- host = ENV.fetch('BASQUIAT_RABBITMQ_1_PORT_25672_TCP_ADDR', 'localhost')
+ host = ENV.fetch('BASQUIAT_RABBITMQ_1_PORT_15672_TCP_ADDR', 'localhost')
port = ENV.fetch('BASQUIAT_RABBITMQ_1_PORT_15672_TCP_PORT', 15_672)
- @uri = "http://guest:guest@#{host}:#{port}/api/queues/%2F/#{@queue}"
+ @uri = URI.parse("http://#{host}:#{port}/api/queues/%2F/#{@queue}")
end
def unacked_messages
queue_status.fetch(:messages_unacknowledged)
end
@@ -15,10 +18,13 @@
def queue_status
@message ||= MultiJson.load(fetch, symbolize_keys: true)
end
def fetch
- `curl -sXGET -H 'Accepts: application/json' #{@uri}`
+ req = Net::HTTP::Get.new @uri
+ req.basic_auth('guest', 'guest')
+ res = Net::HTTP.start(@uri.host, @uri.port) { |http| http.request(req) }
+ res.body
end
end
RSpec::Matchers.define :have_n_unacked_messages do |expected| # number of unacked messages
match do |queue| # queue