Skip to content

Commit

Permalink
Fixing specs
Browse files Browse the repository at this point in the history
  • Loading branch information
AnotherRegularDude committed Dec 15, 2024
1 parent 9c27c02 commit ad5c7ff
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 99 deletions.
12 changes: 6 additions & 6 deletions lib/resol/plugins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ module Resol
module Plugins
PLUGINS_PATH = Pathname("resol/plugins")
class Manager
def self.resolve_module(module_name)
Plugins.const_get(module_name)
end

def initialize
self.allowed_classes = resolve_allowed_classes
self.plugins = []
Expand All @@ -14,7 +18,7 @@ def initialize
def plugin(caller_class, plugin_name)
plugin_name = plugin_name.to_s

return if allowed_classes.exclude?(caller_class)
return unless allowed_classes.include?(caller_class)
return if plugins.include?(plugin_name)

plugin_module = find_plugin_module(plugin_name)
Expand All @@ -39,15 +43,11 @@ def resolve_allowed_classes

def find_plugin_module(plugin_name)
require PLUGINS_PATH.join(plugin_name)
resolve_module(classify_plugin_name(plugin_name))
self.class.resolve_module(classify_plugin_name(plugin_name))
rescue LoadError, NameError => e
raise ArgumentError, "Failed to load plugin '#{plugin_name}': #{e.message}"
end

def resolve_module(module_name)
Plugins.const_get(module_name)
end

def classify_plugin_name(string)
string.split(/_|-/).map!(&:capitalize).join
end
Expand Down
2 changes: 1 addition & 1 deletion lib/resol/result.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true
1# frozen_string_literal: true

module Resol
class UnwrapError < StandardError; end
Expand Down
83 changes: 0 additions & 83 deletions spec/initializers_spec.rb

This file was deleted.

7 changes: 4 additions & 3 deletions spec/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,11 @@ def call
context "when install plugin on the child service class" do
let(:child_service) { Class.new(Resol::Service) }

let(:error_message) { "can load plugins only on base Resol::Service" }
it "just skips installation" do
child_service.plugin(:dummy)
manager = child_service.send(:manager)

it "raises error" do
expect { child_service.plugin(:dump) }.to raise_error(ArgumentError, error_message)
expect(manager.send(:plugins)).to eq([])
end
end

Expand Down
7 changes: 1 addition & 6 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
require "resol/plugins/dummy"

Resol::DependencyContainer.enable_stubs!
Resol.config.send(:data=, { classes_allowed_to_patch: ["Resol::Service", "ReturnEngineService"] })

class SmartService < Resol::Service
inject_initializer! :smartcore_injector
Expand All @@ -52,10 +53,4 @@ class ReturnEngineService < Resol::Service

config.order = :random
Kernel.srand config.seed

config.around do |ex|
applied_classes = Resol::Initializers.send(:applied_classes).dup
ex.call
Resol::Initializers.send(:applied_classes=, applied_classes)
end
end

0 comments on commit ad5c7ff

Please sign in to comment.