tests/middlewares/instrumentation_tests.rb in excon-0.46.0 vs tests/middlewares/instrumentation_tests.rb in excon-0.47.0
- old
+ new
@@ -1,17 +1,23 @@
require 'active_support/notifications'
require 'securerandom'
class SimpleInstrumentor
class << self
- attr_accessor :events
+ attr_accessor :events, :blocks
def instrument(name, params = {}, &block)
- @events ||= []
@events << name
+ @blocks << name if block_given?
+
yield if block_given?
end
+
+ def reset!
+ @events = []
+ @blocks = []
+ end
end
end
Shindo.tests('Excon instrumentation') do
@@ -24,10 +30,14 @@
ActiveSupport::Notifications.unsubscribe("gug")
Delorean.back_to_the_present
Excon.stubs.clear
end
+ before do
+ SimpleInstrumentor.reset!
+ end
+
def subscribe(match)
@events = []
ActiveSupport::Notifications.subscribe(match) do |*args|
@events << ActiveSupport::Notifications::Event.new(*args)
end
@@ -234,9 +244,22 @@
raises(Excon::Errors::SocketError) do
connection.get(:idempotent => true)
end
SimpleInstrumentor.events
+ end
+
+ tests('always passes the block').returns(
+ ['excon.request', 'excon.response']) do
+ stub_success
+ connection = Excon.new(
+ 'http://127.0.0.1:9292',
+ :instrumentor => SimpleInstrumentor,
+ :mock => true
+ )
+ connection.get(:idempotent => true)
+
+ SimpleInstrumentor.blocks
end
tests('does not generate events when not provided').returns(0) do
subscribe(/excon/)
stub_success