summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorBobby McDonald <BobbyMcWho@users.noreply.github.com>2019-11-18 17:04:37 -0500
committerGitHub <noreply@github.com>2019-11-18 17:04:37 -0500
commitd5f253963731f7b2ef96ba415ecad22c89e22d28 (patch)
treef2a772ddfe026f34262d3339f8efa6c351c626d8 /spec
parent4f014e7fedad93fa2070166051947070cc8ac01c (diff)
parent15ea67ef0667546627f9a3cd4fef4457512f5880 (diff)
downloadhashie-d5f253963731f7b2ef96ba415ecad22c89e22d28.tar.gz
Merge pull request #499 from michaelherold/permissive-respond-to
Add a PermissiveRespondTo extension for Mashes
Diffstat (limited to 'spec')
-rw-r--r--spec/hashie/extensions/mash/permissive_respond_to_spec.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/hashie/extensions/mash/permissive_respond_to_spec.rb b/spec/hashie/extensions/mash/permissive_respond_to_spec.rb
new file mode 100644
index 0000000..189f94a
--- /dev/null
+++ b/spec/hashie/extensions/mash/permissive_respond_to_spec.rb
@@ -0,0 +1,44 @@
+require 'spec_helper'
+
+RSpec.describe Hashie::Extensions::Mash::PermissiveRespondTo do
+ class PermissiveMash < Hashie::Mash
+ include Hashie::Extensions::Mash::PermissiveRespondTo
+ end
+
+ it 'allows you to bind to unset getters' do
+ mash = PermissiveMash.new(a: 1)
+ other_mash = PermissiveMash.new(b: 2)
+
+ expect { mash.method(:b) }.not_to raise_error
+ expect(mash.method(:b).unbind.bind(other_mash).call).to eq 2
+ end
+
+ it 'works properly with SimpleDelegator' do
+ delegator = Class.new(SimpleDelegator) do
+ def initialize(hash)
+ super(PermissiveMash.new(hash))
+ end
+ end
+
+ foo = delegator.new(a: 1)
+
+ expect(foo.a).to eq 1
+ expect { foo.b }.not_to raise_error
+ end
+
+ context 'warnings' do
+ include_context 'with a logger'
+
+ it 'does not log a collision when setting normal keys' do
+ PermissiveMash.new(a: 1)
+
+ expect(logger_output).to be_empty
+ end
+
+ it 'logs a collision with a built-in method' do
+ PermissiveMash.new(zip: 1)
+
+ expect(logger_output).to match('PermissiveMash#zip defined in Enumerable')
+ end
+ end
+end