From c3f91950f9bc3eb9f6e8f2706c42257b21476163 Mon Sep 17 00:00:00 2001 From: geemus Date: Tue, 21 Jun 2011 14:48:21 -0700 Subject: [PATCH] [core] fix mock reset to work with new namespaces closes #370 --- lib/fog/core/mock.rb | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/fog/core/mock.rb b/lib/fog/core/mock.rb index 456584ce6..6847d56b5 100644 --- a/lib/fog/core/mock.rb +++ b/lib/fog/core/mock.rb @@ -64,15 +64,22 @@ module Fog end def self.reset - providers = Fog.providers.map {|p| Fog.const_get(p) } - possible_service_constants = providers.map {|p| p.constants.map {|c| p.const_get(c) } }.flatten - # c.to_sym is 1.8.7 / 1.9.2 compat - services = possible_service_constants.select {|s| s.constants.map {|c| c.to_sym }.include?(:Mock) } - service_mocks = services.map {|s| s.const_get(:Mock) } + mocked_services = [] + Fog.constants.map do |x| + x_const = Fog.const_get(x) + x_const.respond_to?(:constants) && x_const.constants.map do |y| + y_const = x_const.const_get(y) + y_const.respond_to?(:constants) && y_const.constants.map do |z| + if z.to_sym == :Mock + mocked_services << y_const.const_get(z) + end + end + end + end - service_mocks.each do |service_mock| - next unless service_mock.respond_to?(:reset) - service_mock.reset + for mocked_service in mocked_services + next unless mocked_service.respond_to?(:reset) + mocked_service.reset end end