Test without mocks

Test without mocks

From 4502b4d09f64371e538ac11729d82d7f325ecabd Mon Sep 17 00:00:00 2001
From: Ben Langfeld <blangfeld@powerhrg.com>
Date: Wed, 28 Nov 2018 16:10:26 -0200
Subject: [PATCH] Test without mocks


diff --git a/lib/message_bus/rack/middleware.rb b/lib/message_bus/rack/middleware.rb
index 46af77f..1e5336f 100644
--- a/lib/message_bus/rack/middleware.rb
+++ b/lib/message_bus/rack/middleware.rb
@@ -24,6 +24,9 @@ class MessageBus::Rack::Middleware
     JSON.dump(m)
   end
 
+  # @return [Boolean] whether the message listener (subscriber) is started or not)
+  attr_reader :started_listener
+
   # Sets up the middleware to receive subscriber client requests and begins
   # listening for messages published on the bus for re-distribution (unless
   # the bus is disabled).
@@ -35,6 +38,7 @@ class MessageBus::Rack::Middleware
     @app = app
     @bus = config[:message_bus] || MessageBus
     @connection_manager = MessageBus::ConnectionManager.new(@bus)
+    @started_listener = false
     start_listener unless @bus.off?
   end
 
diff --git a/spec/lib/message_bus/rack/middleware_spec.rb b/spec/lib/message_bus/rack/middleware_spec.rb
index 70a1289..04f81ae 100644
--- a/spec/lib/message_bus/rack/middleware_spec.rb
+++ b/spec/lib/message_bus/rack/middleware_spec.rb
@@ -115,10 +115,12 @@ describe MessageBus::Rack::Middleware do
     let(:app) { ->(_) { [200, {}, []] } }
 
     it "never subscribes" do
-      bus = Minitest::Mock.new
-      bus.expect(:off?, true)
+      bus = MessageBus::Instance.new
+      bus.off
 
-      MessageBus::Rack::Middleware.new(app, message_bus: bus)
+      middleware = MessageBus::Rack::Middleware.new(app, message_bus: bus)
+
+      middleware.started_listener.must_equal false
     end
   end

GitHub