summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLucas Nestor <lnestor@covermymeds.com>2018-08-02 16:05:21 -0400
committerMichael Herold <opensource@michaeljherold.com>2018-08-11 21:45:43 -0500
commit1d943216394f1b4a4eb7e0584144aaeeefa1e19a (patch)
tree437d95976cb0bfc9646708fb81b38cbc10ee5483 /spec
parent7b415991772fa3f6ac30ca44b34c2c92b0114b08 (diff)
downloadhashie-1d943216394f1b4a4eb7e0584144aaeeefa1e19a.tar.gz
Add MethodOverridingInitializer extension
Diffstat (limited to 'spec')
-rw-r--r--spec/hashie/extensions/method_access_spec.rb40
1 files changed, 39 insertions, 1 deletions
diff --git a/spec/hashie/extensions/method_access_spec.rb b/spec/hashie/extensions/method_access_spec.rb
index 9ad09c7..dcd049d 100644
--- a/spec/hashie/extensions/method_access_spec.rb
+++ b/spec/hashie/extensions/method_access_spec.rb
@@ -181,8 +181,46 @@ end
describe Hashie::Extensions::MethodAccessWithOverride do
it 'includes all of the other method mixins' do
+ mod_list = [
+ Hashie::Extensions::MethodReader,
+ Hashie::Extensions::MethodOverridingWriter,
+ Hashie::Extensions::MethodQuery,
+ Hashie::Extensions::MethodOverridingInitializer
+ ]
+
klass = Class.new(Hash)
klass.send :include, Hashie::Extensions::MethodAccessWithOverride
- expect((klass.ancestors & [Hashie::Extensions::MethodReader, Hashie::Extensions::MethodOverridingWriter, Hashie::Extensions::MethodQuery]).size).to eq 3
+
+ expect((klass.ancestors & mod_list).size).to eq 4
+ end
+end
+
+describe Hashie::Extensions::MethodOverridingInitializer do
+ class OverridingHash < Hash
+ include Hashie::Extensions::MethodOverridingInitializer
+ end
+
+ context 'when the key is a string' do
+ subject { OverridingHash.new('zip' => 'a-dee-doo-dah') }
+
+ it 'overrides the original method' do
+ expect(subject.zip).to eq 'a-dee-doo-dah'
+ end
+
+ it 'aliases the method with two leading underscores' do
+ expect(subject.__zip).to eq [[%w[zip a-dee-doo-dah]]]
+ end
+ end
+
+ context 'when the key is a symbol' do
+ subject { OverridingHash.new(zip: 'a-dee-doo-dah') }
+
+ it 'overrides the original method' do
+ expect(subject.zip).to eq 'a-dee-doo-dah'
+ end
+
+ it 'aliases the method with two leading underscores' do
+ expect(subject.__zip).to eq [[%w[zip a-dee-doo-dah]]]
+ end
end
end