Sha256: 8f40adca184ee44102be066b09985f4522ef7ec9b1904cab857b4c6e867b9791

Contents?: true

Size: 1.9 KB

Versions: 31

Compression:

Stored size: 1.9 KB

Contents

module HybridPlatformsConductorTest

  module Helpers

    module PluginsHelpers

      # Register given plugins for a given plugin type
      #
      # Parameters::
      # * *plugin_type* (Symbol): The plugin type
      # * *plugins* (Hash<Symbol,Class>): The plugin classes, per plugin ID
      # * *replace* (Boolean): Should we replace the plugins with the mocked ones, or only add them? [default: true]
      def register_plugins(plugin_type, plugins, replace: true)
        unless defined?(@plugins_to_mock)
          # First time we invoke it: mock the call to Plugins
          # List of plugins information to mock, per plugin type
          # * *plugins* (Hash<Symbol,Class>): The mocked plugins
          # * *replace* (Boolean): Should we replace the plugins or add them?
          # Hash< Symbol, Hash<Symbol, Object> >
          @plugins_to_mock = {}
          allow(HybridPlatformsConductor::Plugins).to receive(:new).and_wrap_original do |original_new, plugins_type, init_plugin: nil, parse_gems: true, logger: Logger.new($stdout), logger_stderr: Logger.new($stderr)|
            # If this plugin type is to be mocked, then don't parse gems and provide the mocked plugins instead
            mocked_plugins = original_new.call(
              plugins_type,
              init_plugin: init_plugin,
              parse_gems: @plugins_to_mock.key?(plugins_type) && @plugins_to_mock[plugins_type][:replace] ? false : parse_gems,
              logger: logger,
              logger_stderr: logger_stderr
            )
            if @plugins_to_mock.key?(plugins_type)
              @plugins_to_mock[plugins_type][:plugins].each do |plugin_id, plugin_class|
                mocked_plugins[plugin_id] = plugin_class
              end
            end
            mocked_plugins
          end
        end
        @plugins_to_mock[plugin_type] = {
          plugins: plugins,
          replace: replace
        }
      end

    end

  end

end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
hybrid_platforms_conductor-33.9.5 spec/hybrid_platforms_conductor_test/helpers/plugins_helpers.rb
hybrid_platforms_conductor-33.9.4 spec/hybrid_platforms_conductor_test/helpers/plugins_helpers.rb
hybrid_platforms_conductor-33.9.2 spec/hybrid_platforms_conductor_test/helpers/plugins_helpers.rb
hybrid_platforms_conductor-33.9.1 spec/hybrid_platforms_conductor_test/helpers/plugins_helpers.rb
hybrid_platforms_conductor-33.9.0 spec/hybrid_platforms_conductor_test/helpers/plugins_helpers.rb
hybrid_platforms_conductor-33.8.4 spec/hybrid_platforms_conductor_test/helpers/plugins_helpers.rb
hybrid_platforms_conductor-33.8.3 spec/hybrid_platforms_conductor_test/helpers/plugins_helpers.rb
hybrid_platforms_conductor-33.8.2 spec/hybrid_platforms_conductor_test/helpers/plugins_helpers.rb
hybrid_platforms_conductor-33.8.1 spec/hybrid_platforms_conductor_test/helpers/plugins_helpers.rb
hybrid_platforms_conductor-33.8.0 spec/hybrid_platforms_conductor_test/helpers/plugins_helpers.rb
hybrid_platforms_conductor-33.7.4 spec/hybrid_platforms_conductor_test/helpers/plugins_helpers.rb
hybrid_platforms_conductor-33.7.3 spec/hybrid_platforms_conductor_test/helpers/plugins_helpers.rb
hybrid_platforms_conductor-33.7.2 spec/hybrid_platforms_conductor_test/helpers/plugins_helpers.rb
hybrid_platforms_conductor-33.7.1 spec/hybrid_platforms_conductor_test/helpers/plugins_helpers.rb
hybrid_platforms_conductor-33.7.0 spec/hybrid_platforms_conductor_test/helpers/plugins_helpers.rb
hybrid_platforms_conductor-33.6.0 spec/hybrid_platforms_conductor_test/helpers/plugins_helpers.rb
hybrid_platforms_conductor-33.5.1 spec/hybrid_platforms_conductor_test/helpers/plugins_helpers.rb
hybrid_platforms_conductor-33.5.0 spec/hybrid_platforms_conductor_test/helpers/plugins_helpers.rb
hybrid_platforms_conductor-33.4.0 spec/hybrid_platforms_conductor_test/helpers/plugins_helpers.rb
hybrid_platforms_conductor-33.3.0 spec/hybrid_platforms_conductor_test/helpers/plugins_helpers.rb