Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Methods that specity the positional parameters of a contract method in the wrong order are considered valid #17

Open
KevinBrowne opened this issue Feb 21, 2024 · 0 comments
Labels

Comments

@KevinBrowne
Copy link
Member

KevinBrowne commented Feb 21, 2024

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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant