Skip to content

Loading of DependencyGroups fails with anonymous classes #16

Description

@KevinBrowne

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:

  • No error is raised

  • Both :foo and :bar are registered in the container

Actual:

  • The call to Sinject::Container#load_groups raises ArgumentError

  • No dependencies are registered.

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions