From 9156962af3393f9726e05f715322ce1010ebd69e Mon Sep 17 00:00:00 2001 From: Christopher Swasey Date: Thu, 28 Feb 2019 07:56:17 -0500 Subject: [PATCH] It would be nice if #key? were aliased to #has_key? so that the have_key RSpec matcher can be used instead of key?(key) eq(true) --- lib/dry/container/mixin.rb | 1 + spec/support/shared_examples/container.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+) 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'] }