Skip to content

Commit

Permalink
It would be nice if #key? were aliased to #has_key? so that the have_…
Browse files Browse the repository at this point in the history
…key RSpec matcher can be used instead of key?(key) eq(true)
  • Loading branch information
endash committed Feb 28, 2019
1 parent 490b087 commit 97bbf47
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/dry/container/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def merge(other, namespace: nil)
def key?(key)
config.resolver.key?(_container, key)
end
alias has_key? key?

# An array of registered names for the container
#
Expand Down
12 changes: 12 additions & 0 deletions spec/support/shared_examples/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'] }
Expand Down

0 comments on commit 97bbf47

Please sign in to comment.