If you specify a contract class, Sinject::Container#register will verify that the methods of the provided class accept parameters with the same names as in the contract. However, it does not check that positional parameters are in the correct order.
Steps to reproduce:
require 'sinject'
container = Sinject::Container.new(false)
class MyContract
def family_then_given(given_name, family_name) = nil
end
class BadImpl
def family_then_given(given_name, surname) = "#{surname}, #{given_name}"
end
container.register(key: :concatenator, class: BadImpl, contract: MyContract)
# => Sinject::DependencyContractInvalidParametersException
# The method signature of method: 'family_then_given' does not match the contract parameters: 'family_name, surname'
class OutOfOrderImpl
def family_then_given(family_name, given_name) = "#{family_name}, #{given_name}"
end
container.register(key: :concatenator, class: OutOfOrderImpl, contract: MyContract)
Expected:
Sinject::DependencyContractInvalidParametersException or similar error to be raised
Actual:
OutOfOrderImpl is considered to match the contract and is registered.
container.get(:concatenator).family_then_given('Kevin', 'Browne')
=> "Kevin, Browne"