summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorMichael Herold <michael.j.herold@gmail.com>2017-02-24 07:13:12 -0600
committerMichael Herold <michael.j.herold@gmail.com>2017-02-24 07:47:52 -0600
commit55cfb8adbcaf7d9ca27bc630cde06ca6430e8607 (patch)
tree856374fc46ae79f796c5aa35bae3c45288257bd6 /spec
parent9f77380ddbc72347063065d9e9f7c4a13cd504d5 (diff)
downloadhashie-55cfb8adbcaf7d9ca27bc630cde06ca6430e8607.tar.gz
Don't log when overwriting Mash keys
When we switched to using `#respond_to?` to detecting whether to log a Mash collision, we started reporting when we were overwriting keys that already exist in the Mash. This is a poor experience because it causes extra warnings (as in #414) or, in the worst case, causes an "undefined method" error (as in #413). This change fixes that problem and benchmarks to ensure we're not appreciably regressing performance. The results of two benchmarks are below: ``` bundle exec ruby benchmark/mash_method_access.rb: Warming up -------------------------------------- before 92.456k i/100ms Calculating ------------------------------------- before 1.290M (± 4.4%) i/s - 6.472M in 5.028183s Pausing here -- run Ruby again to measure the next benchmark... Warming up -------------------------------------- after 92.941k i/100ms Calculating ------------------------------------- after 1.326M (± 5.4%) i/s - 6.692M in 5.060756s Comparison: after: 1326239.2 i/s before: 1289624.0 i/s - same-ish: difference falls within error ``` and ``` within spec/integrations/omniauth, bundle exec rake perf:ips Warming up -------------------------------------- before 1.260k i/100ms Calculating ------------------------------------- before 13.114k (± 4.2%) i/s - 66.780k in 5.101689s Pausing here -- run Ruby again to measure the next benchmark... Warming up -------------------------------------- after 1.299k i/100ms Calculating ------------------------------------- after 13.149k (± 4.0%) i/s - 66.249k in 5.046630s Comparison: after: 13148.9 i/s before: 13113.8 i/s - same-ish: difference falls within error ``` Closes #413 Closes #414
Diffstat (limited to 'spec')
-rw-r--r--spec/hashie/mash_spec.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/spec/hashie/mash_spec.rb b/spec/hashie/mash_spec.rb
index 6b9882b..162d982 100644
--- a/spec/hashie/mash_spec.rb
+++ b/spec/hashie/mash_spec.rb
@@ -142,6 +142,14 @@ describe Hashie::Mash do
expect(logger_output).to match('Hashie::Mash#trust')
end
+ it 'can set keys more than once and does not warn when doing so' do
+ mash = Hashie::Mash.new
+ mash[:test_key] = 'Test value'
+
+ expect { mash[:test_key] = 'A new value' }.not_to raise_error
+ expect(logger_output).to be_blank
+ end
+
it 'does not write to the logger when warnings are disabled' do
mash_class = Class.new(Hashie::Mash) do
disable_warnings