If multiple subclasses of DependencyGroup are defined and at least one of them is an anonymous class, Sinject::Container#load_groups will fail with an ArgumentError.
Steps to reproduce:
require 'sinject'
class MyDependenyGroup < Sinject::DependencyGroup
def valid? = true
def register(container) = container.register(key: :foo, class: String)
end
container = Sinject::Container.new(false)
container.load_groups
container.registered?(:foo)
# => true
Class.new(Sinject::DependencyGroup) do
def valid? = true
def register(container) = container.register(key: :bar, class: String)
end
container = Sinject::Container.new(false)
container.load_groups
Expected:
Actual:
This is caused by the container attempting to sort the DependencyGroup subclasses by name. If the class is anonymous its name, by definition, is nil and the comparison with nil raises. An anonymous DependencyGroup subclass will work if it is the only DependencyGroup.
If multiple subclasses of
DependencyGroupare defined and at least one of them is an anonymous class,Sinject::Container#load_groupswill fail with anArgumentError.Steps to reproduce:
Expected:
No error is raised
Both
:fooand:barare registered in the containerActual:
The call to
Sinject::Container#load_groupsraisesArgumentErrorNo dependencies are registered.
This is caused by the container attempting to sort the
DependencyGroupsubclasses by name. If the class is anonymous its name, by definition, isniland the comparison withnilraises. An anonymousDependencyGroupsubclass will work if it is the onlyDependencyGroup.