hashie 3.5.7 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +281 -195
  3. data/CONTRIBUTING.md +13 -6
  4. data/LICENSE +1 -1
  5. data/README.md +320 -60
  6. data/Rakefile +2 -2
  7. data/UPGRADING.md +121 -7
  8. data/hashie.gemspec +13 -7
  9. data/lib/hashie/clash.rb +12 -1
  10. data/lib/hashie/dash.rb +56 -35
  11. data/lib/hashie/extensions/active_support/core_ext/hash.rb +14 -0
  12. data/lib/hashie/extensions/coercion.rb +26 -19
  13. data/lib/hashie/extensions/dash/indifferent_access.rb +29 -1
  14. data/lib/hashie/extensions/dash/predefined_values.rb +88 -0
  15. data/lib/hashie/extensions/dash/property_translation.rb +59 -28
  16. data/lib/hashie/extensions/deep_fetch.rb +5 -3
  17. data/lib/hashie/extensions/deep_find.rb +14 -5
  18. data/lib/hashie/extensions/deep_locate.rb +22 -8
  19. data/lib/hashie/extensions/deep_merge.rb +26 -10
  20. data/lib/hashie/extensions/ignore_undeclared.rb +4 -5
  21. data/lib/hashie/extensions/indifferent_access.rb +43 -10
  22. data/lib/hashie/extensions/key_conflict_warning.rb +55 -0
  23. data/lib/hashie/extensions/mash/define_accessors.rb +90 -0
  24. data/lib/hashie/extensions/mash/keep_original_keys.rb +4 -5
  25. data/lib/hashie/extensions/mash/permissive_respond_to.rb +61 -0
  26. data/lib/hashie/extensions/mash/safe_assignment.rb +3 -1
  27. data/lib/hashie/extensions/mash/symbolize_keys.rb +6 -6
  28. data/lib/hashie/extensions/method_access.rb +47 -14
  29. data/lib/hashie/extensions/parsers/yaml_erb_parser.rb +28 -4
  30. data/lib/hashie/extensions/ruby_version_check.rb +5 -1
  31. data/lib/hashie/extensions/strict_key_access.rb +16 -13
  32. data/lib/hashie/extensions/stringify_keys.rb +1 -1
  33. data/lib/hashie/extensions/symbolize_keys.rb +13 -2
  34. data/lib/hashie/hash.rb +18 -11
  35. data/lib/hashie/mash.rb +147 -81
  36. data/lib/hashie/railtie.rb +7 -0
  37. data/lib/hashie/rash.rb +6 -6
  38. data/lib/hashie/utils.rb +28 -0
  39. data/lib/hashie/version.rb +1 -1
  40. data/lib/hashie.rb +22 -19
  41. metadata +23 -131
  42. data/spec/hashie/array_spec.rb +0 -29
  43. data/spec/hashie/clash_spec.rb +0 -70
  44. data/spec/hashie/dash_spec.rb +0 -573
  45. data/spec/hashie/extensions/autoload_spec.rb +0 -24
  46. data/spec/hashie/extensions/coercion_spec.rb +0 -631
  47. data/spec/hashie/extensions/dash/coercion_spec.rb +0 -13
  48. data/spec/hashie/extensions/dash/indifferent_access_spec.rb +0 -84
  49. data/spec/hashie/extensions/deep_fetch_spec.rb +0 -97
  50. data/spec/hashie/extensions/deep_find_spec.rb +0 -138
  51. data/spec/hashie/extensions/deep_locate_spec.rb +0 -137
  52. data/spec/hashie/extensions/deep_merge_spec.rb +0 -70
  53. data/spec/hashie/extensions/ignore_undeclared_spec.rb +0 -47
  54. data/spec/hashie/extensions/indifferent_access_spec.rb +0 -282
  55. data/spec/hashie/extensions/indifferent_access_with_rails_hwia_spec.rb +0 -208
  56. data/spec/hashie/extensions/key_conversion_spec.rb +0 -12
  57. data/spec/hashie/extensions/mash/keep_original_keys_spec.rb +0 -46
  58. data/spec/hashie/extensions/mash/safe_assignment_spec.rb +0 -50
  59. data/spec/hashie/extensions/mash/symbolize_keys_spec.rb +0 -39
  60. data/spec/hashie/extensions/merge_initializer_spec.rb +0 -23
  61. data/spec/hashie/extensions/method_access_spec.rb +0 -188
  62. data/spec/hashie/extensions/strict_key_access_spec.rb +0 -110
  63. data/spec/hashie/extensions/stringify_keys_spec.rb +0 -124
  64. data/spec/hashie/extensions/symbolize_keys_spec.rb +0 -129
  65. data/spec/hashie/hash_spec.rb +0 -84
  66. data/spec/hashie/mash_spec.rb +0 -763
  67. data/spec/hashie/parsers/yaml_erb_parser_spec.rb +0 -46
  68. data/spec/hashie/rash_spec.rb +0 -83
  69. data/spec/hashie/trash_spec.rb +0 -268
  70. data/spec/hashie/utils_spec.rb +0 -25
  71. data/spec/hashie/version_spec.rb +0 -7
  72. data/spec/hashie_spec.rb +0 -13
  73. data/spec/integration/omniauth/app.rb +0 -11
  74. data/spec/integration/omniauth/integration_spec.rb +0 -38
  75. data/spec/integration/omniauth-oauth2/app.rb +0 -53
  76. data/spec/integration/omniauth-oauth2/integration_spec.rb +0 -26
  77. data/spec/integration/omniauth-oauth2/some_site.rb +0 -38
  78. data/spec/integration/rails/app.rb +0 -48
  79. data/spec/integration/rails/integration_spec.rb +0 -26
  80. data/spec/integration/rails-without-dependency/integration_spec.rb +0 -15
  81. data/spec/spec_helper.rb +0 -23
  82. data/spec/support/integration_specs.rb +0 -36
  83. data/spec/support/logger.rb +0 -24
  84. data/spec/support/module_context.rb +0 -11
  85. data/spec/support/ruby_version_check.rb +0 -6
@@ -1,282 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Hashie::Extensions::IndifferentAccess do
4
- class IndifferentHashWithMergeInitializer < Hash
5
- include Hashie::Extensions::MergeInitializer
6
- include Hashie::Extensions::IndifferentAccess
7
-
8
- class << self
9
- alias_method :build, :new
10
- end
11
- end
12
-
13
- class IndifferentHashWithArrayInitializer < Hash
14
- include Hashie::Extensions::IndifferentAccess
15
-
16
- class << self
17
- alias_method :build, :[]
18
- end
19
- end
20
-
21
- class IndifferentHashWithTryConvertInitializer < Hash
22
- include Hashie::Extensions::IndifferentAccess
23
-
24
- class << self
25
- alias_method :build, :try_convert
26
- end
27
- end
28
-
29
- class IndifferentHashWithDash < Hashie::Dash
30
- include Hashie::Extensions::IndifferentAccess
31
- property :foo
32
- end
33
-
34
- class IndifferentHashWithIgnoreUndeclaredAndPropertyTranslation < Hashie::Dash
35
- include Hashie::Extensions::IgnoreUndeclared
36
- include Hashie::Extensions::Dash::PropertyTranslation
37
- include Hashie::Extensions::IndifferentAccess
38
- property :foo, from: :bar
39
- end
40
-
41
- describe '#merge' do
42
- it 'indifferently merges in a hash' do
43
- indifferent_hash = Class.new(::Hash) do
44
- include Hashie::Extensions::IndifferentAccess
45
- end.new
46
-
47
- merged_hash = indifferent_hash.merge(:cat => 'meow')
48
-
49
- expect(merged_hash[:cat]).to eq('meow')
50
- expect(merged_hash['cat']).to eq('meow')
51
- end
52
- end
53
-
54
- describe '#merge!' do
55
- it 'indifferently merges in a hash' do
56
- indifferent_hash = Class.new(::Hash) do
57
- include Hashie::Extensions::IndifferentAccess
58
- end.new
59
-
60
- indifferent_hash.merge!(:cat => 'meow')
61
-
62
- expect(indifferent_hash[:cat]).to eq('meow')
63
- expect(indifferent_hash['cat']).to eq('meow')
64
- end
65
- end
66
-
67
- describe 'when included in dash' do
68
- let(:params) { { foo: 'bar' } }
69
- subject { IndifferentHashWithDash.new(params) }
70
-
71
- it 'initialize with a symbol' do
72
- expect(subject.foo).to eq params[:foo]
73
- end
74
- end
75
-
76
- describe 'when translating properties and ignoring undeclared' do
77
- let(:value) { 'baz' }
78
-
79
- subject { IndifferentHashWithIgnoreUndeclaredAndPropertyTranslation.new(params) }
80
-
81
- context 'and the hash keys are strings' do
82
- let(:params) { { 'bar' => value } }
83
-
84
- it 'sets the property' do
85
- expect(subject[:foo]).to eq value
86
- end
87
- end
88
-
89
- context 'and the hash keys are symbols' do
90
- let(:params) { { bar: 'baz' } }
91
-
92
- it 'sets the property' do
93
- expect(subject[:foo]).to eq value
94
- end
95
- end
96
-
97
- context 'and there are undeclared keys' do
98
- let(:params) { { 'bar' => 'baz', 'fail' => false } }
99
-
100
- it 'sets the property' do
101
- expect(subject[:foo]).to eq value
102
- end
103
- end
104
- end
105
-
106
- shared_examples_for 'hash with indifferent access' do
107
- it 'is able to access via string or symbol' do
108
- h = subject.build(abc: 123)
109
- expect(h[:abc]).to eq 123
110
- expect(h['abc']).to eq 123
111
- end
112
-
113
- describe '#values_at' do
114
- it 'indifferently finds values' do
115
- h = subject.build(:foo => 'bar', 'baz' => 'qux')
116
- expect(h.values_at('foo', :baz)).to eq %w(bar qux)
117
- end
118
-
119
- it 'returns the same instance of the hash that was set' do
120
- hash = {}
121
- h = subject.build(foo: hash)
122
- expect(h.values_at(:foo)[0]).to be(hash)
123
- end
124
-
125
- it 'returns the same instance of the array that was set' do
126
- array = []
127
- h = subject.build(foo: array)
128
- expect(h.values_at(:foo)[0]).to be(array)
129
- end
130
-
131
- it 'returns the same instance of the string that was set' do
132
- str = 'my string'
133
- h = subject.build(foo: str)
134
- expect(h.values_at(:foo)[0]).to be(str)
135
- end
136
-
137
- it 'returns the same instance of the object that was set' do
138
- object = Object.new
139
- h = subject.build(foo: object)
140
- expect(h.values_at(:foo)[0]).to be(object)
141
- end
142
- end
143
-
144
- describe '#fetch' do
145
- it 'works like normal fetch, but indifferent' do
146
- h = subject.build(foo: 'bar')
147
- expect(h.fetch(:foo)).to eq h.fetch('foo')
148
- expect(h.fetch(:foo)).to eq 'bar'
149
- end
150
-
151
- it 'returns the same instance of the hash that was set' do
152
- hash = {}
153
- h = subject.build(foo: hash)
154
- expect(h.fetch(:foo)).to be(hash)
155
- end
156
-
157
- it 'returns the same instance of the array that was set' do
158
- array = []
159
- h = subject.build(foo: array)
160
- expect(h.fetch(:foo)).to be(array)
161
- end
162
-
163
- it 'returns the same instance of the string that was set' do
164
- str = 'my string'
165
- h = subject.build(foo: str)
166
- expect(h.fetch(:foo)).to be(str)
167
- end
168
-
169
- it 'returns the same instance of the object that was set' do
170
- object = Object.new
171
- h = subject.build(foo: object)
172
- expect(h.fetch(:foo)).to be(object)
173
- end
174
-
175
- it 'yields with key name if key does not exists' do
176
- h = subject.build(a: 0)
177
- expect(h.fetch(:foo) { |key| ['default for', key] }).to eq ['default for', 'foo']
178
- end
179
- end
180
-
181
- describe '#delete' do
182
- it 'deletes indifferently' do
183
- h = subject.build(:foo => 'bar', 'baz' => 'qux')
184
- h.delete('foo')
185
- h.delete(:baz)
186
- expect(h).to be_empty
187
- end
188
- end
189
-
190
- describe '#key?' do
191
- let(:h) { subject.build(foo: 'bar') }
192
-
193
- it 'finds it indifferently' do
194
- expect(h).to be_key(:foo)
195
- expect(h).to be_key('foo')
196
- end
197
-
198
- %w(include? member? has_key?).each do |key_alias|
199
- it "is aliased as #{key_alias}" do
200
- expect(h.send(key_alias.to_sym, :foo)).to be(true)
201
- expect(h.send(key_alias.to_sym, 'foo')).to be(true)
202
- end
203
- end
204
- end
205
-
206
- describe '#update' do
207
- let(:h) { subject.build(foo: 'bar') }
208
-
209
- it 'allows keys to be indifferent still' do
210
- h.update(baz: 'qux')
211
- expect(h['foo']).to eq 'bar'
212
- expect(h['baz']).to eq 'qux'
213
- end
214
-
215
- it 'recursively injects indifference into sub-hashes' do
216
- h.update(baz: { qux: 'abc' })
217
- expect(h['baz']['qux']).to eq 'abc'
218
- end
219
-
220
- it 'does not change the ancestors of the injected object class' do
221
- h.update(baz: { qux: 'abc' })
222
- expect({}).not_to be_respond_to(:indifferent_access?)
223
- end
224
- end
225
-
226
- describe '#replace' do
227
- let(:h) { subject.build(foo: 'bar').replace(bar: 'baz', hi: 'bye') }
228
-
229
- it 'returns self' do
230
- expect(h).to be_a(subject)
231
- end
232
-
233
- it 'removes old keys' do
234
- [:foo, 'foo'].each do |k|
235
- expect(h[k]).to be_nil
236
- expect(h.key?(k)).to be_falsy
237
- end
238
- end
239
-
240
- it 'creates new keys with indifferent access' do
241
- [:bar, 'bar', :hi, 'hi'].each { |k| expect(h.key?(k)).to be_truthy }
242
- expect(h[:bar]).to eq 'baz'
243
- expect(h['bar']).to eq 'baz'
244
- expect(h[:hi]).to eq 'bye'
245
- expect(h['hi']).to eq 'bye'
246
- end
247
- end
248
-
249
- describe '#try_convert' do
250
- describe 'with conversion' do
251
- let(:h) { subject.try_convert(foo: 'bar') }
252
-
253
- it 'is a subject' do
254
- expect(h).to be_a(subject)
255
- end
256
- end
257
-
258
- describe 'without conversion' do
259
- let(:h) { subject.try_convert('{ :foo => bar }') }
260
-
261
- it 'is nil' do
262
- expect(h).to be_nil
263
- end
264
- end
265
- end
266
- end
267
-
268
- describe 'with merge initializer' do
269
- subject { IndifferentHashWithMergeInitializer }
270
- it_should_behave_like 'hash with indifferent access'
271
- end
272
-
273
- describe 'with array initializer' do
274
- subject { IndifferentHashWithArrayInitializer }
275
- it_should_behave_like 'hash with indifferent access'
276
- end
277
-
278
- describe 'with try convert initializer' do
279
- subject { IndifferentHashWithTryConvertInitializer }
280
- it_should_behave_like 'hash with indifferent access'
281
- end
282
- end
@@ -1,208 +0,0 @@
1
- # This set of tests verifies that Hashie::Extensions::IndifferentAccess works with
2
- # ActiveSupport HashWithIndifferentAccess hashes. See #164 and #166 for details.
3
-
4
- require 'active_support/hash_with_indifferent_access'
5
- require 'active_support/core_ext/hash'
6
- require 'spec_helper'
7
-
8
- describe Hashie::Extensions::IndifferentAccess do
9
- class IndifferentHashWithMergeInitializer < Hash
10
- include Hashie::Extensions::MergeInitializer
11
- include Hashie::Extensions::IndifferentAccess
12
-
13
- class << self
14
- alias_method :build, :new
15
- end
16
- end
17
-
18
- class IndifferentHashWithArrayInitializer < Hash
19
- include Hashie::Extensions::IndifferentAccess
20
-
21
- class << self
22
- alias_method :build, :[]
23
- end
24
- end
25
-
26
- class IndifferentHashWithTryConvertInitializer < Hash
27
- include Hashie::Extensions::IndifferentAccess
28
-
29
- class << self
30
- alias_method :build, :try_convert
31
- end
32
- end
33
-
34
- class CoercableHash < Hash
35
- include Hashie::Extensions::Coercion
36
- include Hashie::Extensions::MergeInitializer
37
- end
38
-
39
- class MashWithIndifferentAccess < Hashie::Mash
40
- include Hashie::Extensions::IndifferentAccess
41
- end
42
-
43
- shared_examples_for 'hash with indifferent access' do
44
- it 'is able to access via string or symbol' do
45
- indifferent_hash = ActiveSupport::HashWithIndifferentAccess.new(abc: 123)
46
- h = subject.build(indifferent_hash)
47
- expect(h[:abc]).to eq 123
48
- expect(h['abc']).to eq 123
49
- end
50
-
51
- describe '#values_at' do
52
- it 'indifferently finds values' do
53
- indifferent_hash = ActiveSupport::HashWithIndifferentAccess.new(
54
- :foo => 'bar', 'baz' => 'qux'
55
- )
56
- h = subject.build(indifferent_hash)
57
- expect(h.values_at('foo', :baz)).to eq %w(bar qux)
58
- end
59
- end
60
-
61
- describe '#fetch' do
62
- it 'works like normal fetch, but indifferent' do
63
- indifferent_hash = ActiveSupport::HashWithIndifferentAccess.new(foo: 'bar')
64
- h = subject.build(indifferent_hash)
65
- expect(h.fetch(:foo)).to eq h.fetch('foo')
66
- expect(h.fetch(:foo)).to eq 'bar'
67
- end
68
- end
69
-
70
- describe '#delete' do
71
- it 'deletes indifferently' do
72
- indifferent_hash = ActiveSupport::HashWithIndifferentAccess.new(
73
- :foo => 'bar',
74
- 'baz' => 'qux'
75
- )
76
- h = subject.build(indifferent_hash)
77
- h.delete('foo')
78
- h.delete(:baz)
79
- expect(h).to be_empty
80
- end
81
- end
82
-
83
- describe '#key?' do
84
- let(:h) do
85
- indifferent_hash = ActiveSupport::HashWithIndifferentAccess.new(foo: 'bar')
86
- subject.build(indifferent_hash)
87
- end
88
-
89
- it 'finds it indifferently' do
90
- expect(h).to be_key(:foo)
91
- expect(h).to be_key('foo')
92
- end
93
-
94
- %w(include? member? has_key?).each do |key_alias|
95
- it "is aliased as #{key_alias}" do
96
- expect(h.send(key_alias.to_sym, :foo)).to be(true)
97
- expect(h.send(key_alias.to_sym, 'foo')).to be(true)
98
- end
99
- end
100
- end
101
-
102
- describe '#update' do
103
- let(:h) do
104
- indifferent_hash = ActiveSupport::HashWithIndifferentAccess.new(foo: 'bar')
105
- subject.build(indifferent_hash)
106
- end
107
-
108
- it 'allows keys to be indifferent still' do
109
- h.update(baz: 'qux')
110
- expect(h['foo']).to eq 'bar'
111
- expect(h['baz']).to eq 'qux'
112
- end
113
-
114
- it 'recursively injects indifference into sub-hashes' do
115
- h.update(baz: { qux: 'abc' })
116
- expect(h['baz']['qux']).to eq 'abc'
117
- end
118
-
119
- it 'does not change the ancestors of the injected object class' do
120
- h.update(baz: { qux: 'abc' })
121
- expect({}).not_to be_respond_to(:indifferent_access?)
122
- end
123
- end
124
-
125
- describe '#replace' do
126
- let(:h) do
127
- indifferent_hash = ActiveSupport::HashWithIndifferentAccess.new(foo: 'bar')
128
- subject.build(indifferent_hash).replace(bar: 'baz', hi: 'bye')
129
- end
130
-
131
- it 'returns self' do
132
- expect(h).to be_a(subject)
133
- end
134
-
135
- it 'removes old keys' do
136
- [:foo, 'foo'].each do |k|
137
- expect(h[k]).to be_nil
138
- expect(h.key?(k)).to be_falsy
139
- end
140
- end
141
-
142
- it 'creates new keys with indifferent access' do
143
- [:bar, 'bar', :hi, 'hi'].each { |k| expect(h.key?(k)).to be_truthy }
144
- expect(h[:bar]).to eq 'baz'
145
- expect(h['bar']).to eq 'baz'
146
- expect(h[:hi]).to eq 'bye'
147
- expect(h['hi']).to eq 'bye'
148
- end
149
- end
150
-
151
- describe '#try_convert' do
152
- describe 'with conversion' do
153
- let(:h) do
154
- indifferent_hash = ActiveSupport::HashWithIndifferentAccess.new(foo: 'bar')
155
- subject.try_convert(indifferent_hash)
156
- end
157
-
158
- it 'is a subject' do
159
- expect(h).to be_a(subject)
160
- end
161
- end
162
-
163
- describe 'without conversion' do
164
- let(:h) { subject.try_convert('{ :foo => bar }') }
165
-
166
- it 'is nil' do
167
- expect(h).to be_nil
168
- end
169
- end
170
- end
171
- end
172
-
173
- describe 'with merge initializer' do
174
- subject { IndifferentHashWithMergeInitializer }
175
- it_should_behave_like 'hash with indifferent access'
176
- end
177
-
178
- describe 'with array initializer' do
179
- subject { IndifferentHashWithArrayInitializer }
180
- it_should_behave_like 'hash with indifferent access'
181
- end
182
-
183
- describe 'with try convert initializer' do
184
- subject { IndifferentHashWithTryConvertInitializer }
185
- it_should_behave_like 'hash with indifferent access'
186
- end
187
-
188
- describe 'with coercion' do
189
- subject { CoercableHash }
190
-
191
- let(:instance) { subject.new }
192
-
193
- it 'supports coercion for ActiveSupport::HashWithIndifferentAccess' do
194
- subject.coerce_key :foo, ActiveSupport::HashWithIndifferentAccess.new(Coercable => Coercable)
195
- instance[:foo] = { 'bar_key' => 'bar_value', 'bar2_key' => 'bar2_value' }
196
- expect(instance[:foo].keys).to all(be_coerced)
197
- expect(instance[:foo].values).to all(be_coerced)
198
- expect(instance[:foo]).to be_a(ActiveSupport::HashWithIndifferentAccess)
199
- end
200
- end
201
-
202
- describe 'Mash with indifferent access' do
203
- it 'is able to be created for a deep nested HashWithIndifferentAccess' do
204
- indifferent_hash = ActiveSupport::HashWithIndifferentAccess.new(abc: { def: 123 })
205
- MashWithIndifferentAccess.new(indifferent_hash)
206
- end
207
- end
208
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
- require 'support/module_context'
3
-
4
- describe Hashie::Extensions::KeyConversion do
5
- include_context 'included hash module'
6
-
7
- it { should respond_to(:stringify_keys) }
8
- it { should respond_to(:stringify_keys!) }
9
-
10
- it { should respond_to(:symbolize_keys) }
11
- it { should respond_to(:symbolize_keys!) }
12
- end
@@ -1,46 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Hashie::Extensions::Mash::KeepOriginalKeys do
4
- let(:keeping_mash) do
5
- Class.new(Hashie::Mash) do
6
- include Hashie::Extensions::Mash::KeepOriginalKeys
7
- end
8
- end
9
-
10
- it 'keeps the keys in the resulting hash identical to the original' do
11
- original = { :a => 'apple', 'b' => 'bottle' }
12
- mash = keeping_mash.new(original)
13
-
14
- expect(mash.to_hash).to eq(original)
15
- end
16
-
17
- it 'indifferently responds to keys' do
18
- original = { :a => 'apple', 'b' => 'bottle' }
19
- mash = keeping_mash.new(original)
20
-
21
- expect(mash['a']).to eq(mash[:a])
22
- expect(mash['b']).to eq(mash[:b])
23
- end
24
-
25
- it 'responds to all method accessors like a Mash' do
26
- original = { :a => 'apple', 'b' => 'bottle' }
27
- mash = keeping_mash.new(original)
28
-
29
- expect(mash.a).to eq('apple')
30
- expect(mash.a?).to eq(true)
31
- expect(mash.b).to eq('bottle')
32
- expect(mash.b?).to eq(true)
33
- expect(mash.underbang_).to be_a(keeping_mash)
34
- expect(mash.bang!).to be_a(keeping_mash)
35
- expect(mash.predicate?).to eq(false)
36
- end
37
-
38
- it 'keeps the keys that are directly passed without converting them' do
39
- original = { :a => 'apple', 'b' => 'bottle' }
40
- mash = keeping_mash.new(original)
41
-
42
- mash[:c] = 'cat'
43
- mash['d'] = 'dog'
44
- expect(mash.to_hash).to eq(:a => 'apple', 'b' => 'bottle', :c => 'cat', 'd' => 'dog')
45
- end
46
- end
@@ -1,50 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Hashie::Extensions::Mash::SafeAssignment do
4
- class MashWithSafeAssignment < Hashie::Mash
5
- include Hashie::Extensions::Mash::SafeAssignment
6
-
7
- private
8
-
9
- def my_own_private
10
- :hello!
11
- end
12
- end
13
-
14
- context 'when included in Mash' do
15
- subject { MashWithSafeAssignment.new }
16
-
17
- context 'when not attempting to override a method' do
18
- it 'assigns just fine' do
19
- expect do
20
- subject.blabla = 'Test'
21
- subject.blabla = 'Test'
22
- end.to_not raise_error
23
- end
24
- end
25
-
26
- context 'when attempting to override a method' do
27
- it 'raises an error' do
28
- expect { subject.zip = 'Test' }.to raise_error(ArgumentError)
29
- end
30
- end
31
-
32
- context 'when attempting to override a private method' do
33
- it 'raises an error' do
34
- expect { subject.my_own_private = 'Test' }.to raise_error(ArgumentError)
35
- end
36
- end
37
-
38
- context 'when attempting to initialize with predefined method' do
39
- it 'raises an error' do
40
- expect { MashWithSafeAssignment.new(zip: true) }.to raise_error(ArgumentError)
41
- end
42
- end
43
-
44
- context 'when setting as a hash key' do
45
- it 'still raises if conflicts with a method' do
46
- expect { subject[:zip] = 'Test' }.to raise_error(ArgumentError)
47
- end
48
- end
49
- end
50
- end
@@ -1,39 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Hashie::Extensions::Mash::SymbolizeKeys do
4
- it 'raises an error when included in a class that is not a Mash' do
5
- expect do
6
- Class.new do
7
- include Hashie::Extensions::Mash::SymbolizeKeys
8
- end
9
- end.to raise_error(ArgumentError)
10
- end
11
-
12
- it 'symbolizes all keys in the Mash' do
13
- my_mash = Class.new(Hashie::Mash) do
14
- include Hashie::Extensions::Mash::SymbolizeKeys
15
- end
16
-
17
- expect(my_mash.new('test' => 'value').to_h).to eq(test: 'value')
18
- end
19
-
20
- context 'implicit to_hash on double splat' do
21
- let(:destructure) { ->(**opts) { opts } }
22
- let(:my_mash) do
23
- Class.new(Hashie::Mash) do
24
- include Hashie::Extensions::Mash::SymbolizeKeys
25
- end
26
- end
27
- let(:instance) { my_mash.new('outer' => { 'inner' => 42 }, 'testing' => [1, 2, 3]) }
28
-
29
- subject { destructure.call(instance) }
30
-
31
- it 'is converted on method calls' do
32
- expect(subject).to eq(outer: { inner: 42 }, testing: [1, 2, 3])
33
- end
34
-
35
- it 'is converted on explicit operator call' do
36
- expect(**instance).to eq(outer: { inner: 42 }, testing: [1, 2, 3])
37
- end
38
- end
39
- end
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Hashie::Extensions::MergeInitializer do
4
- class MergeInitializerHash < Hash
5
- include Hashie::Extensions::MergeInitializer
6
- end
7
-
8
- subject { MergeInitializerHash }
9
-
10
- it 'initializes with no arguments' do
11
- expect(subject.new).to eq({})
12
- end
13
-
14
- it 'initializes with a hash' do
15
- expect(subject.new(abc: 'def')).to eq(abc: 'def')
16
- end
17
-
18
- it 'initializes with a hash and a default' do
19
- h = subject.new({ abc: 'def' }, 'bar')
20
- expect(h[:foo]).to eq 'bar'
21
- expect(h[:abc]).to eq 'def'
22
- end
23
- end