diff --git a/lib/dry/container/mixin.rb b/lib/dry/container/mixin.rb index 8272377..014b857 100644 --- a/lib/dry/container/mixin.rb +++ b/lib/dry/container/mixin.rb @@ -163,6 +163,7 @@ def merge(other, namespace: nil) def key?(key) config.resolver.key?(_container, key) end + alias_method :has_key?, :key? # An array of registered names for the container # diff --git a/spec/support/shared_examples/container.rb b/spec/support/shared_examples/container.rb index b3603ad..f38d37d 100644 --- a/spec/support/shared_examples/container.rb +++ b/spec/support/shared_examples/container.rb @@ -318,6 +318,18 @@ end end + describe '#has_key? is alias of #key? for spec matching' do + let(:key) { :key } + + before do + container.register(key) { :item } + end + + subject! { container } + + it { is_expected.to have_key(key) } + end + describe '#keys' do let(:keys) { [:key_1, :key_2] } let(:expected_keys) { ['key_1', 'key_2'] }