diff options
-rw-r--r-- | lib/hashie/extensions/coercion.rb | 5 | ||||
-rw-r--r-- | spec/hashie/extensions/coercion_spec.rb | 14 |
2 files changed, 5 insertions, 14 deletions
diff --git a/lib/hashie/extensions/coercion.rb b/lib/hashie/extensions/coercion.rb index cc96dd0..c78b29e 100644 --- a/lib/hashie/extensions/coercion.rb +++ b/lib/hashie/extensions/coercion.rb @@ -1,9 +1,8 @@ module Hashie + class CoercionError < StandardError; end + module Extensions module Coercion - class CoercionError < StandardError - end - CORE_TYPES = { Integer => :to_i, Float => :to_f, diff --git a/spec/hashie/extensions/coercion_spec.rb b/spec/hashie/extensions/coercion_spec.rb index 0ba4abf..136a324 100644 --- a/spec/hashie/extensions/coercion_spec.rb +++ b/spec/hashie/extensions/coercion_spec.rb @@ -252,7 +252,7 @@ describe Hashie::Extensions::Coercion do it 'raises errors for non-coercable types' do subject.coerce_key :foo, NotInitializable - expect { instance[:foo] = 'true' }.to raise_error(Hashie::Extensions::Coercion::CoercionError, /NotInitializable is not a coercable type/) + expect { instance[:foo] = 'true' }.to raise_error(Hashie::CoercionError, /NotInitializable is not a coercable type/) end it 'can coerce false' do @@ -272,14 +272,6 @@ describe Hashie::Extensions::Coercion do end end - it 'does not coerce unnecessarily' do - subject.coerce_key :foo, Float - - instance[:foo] = 2.0 - expect(instance[:foo]).to be_a(Float) - expect(instance[:foo]).to eq(2.0) - end - it 'calls #new if no coerce method is available' do subject.coerce_key :foo, Initializable @@ -452,9 +444,9 @@ describe Hashie::Extensions::Coercion do expect(instance[:hi]).to eq(0) end - it 'raises a TypeError when coercion is not possible' do + it 'raises a CoercionError when coercion is not possible' do subject.coerce_value Fixnum, Symbol - expect { instance[:hi] = 1 }.to raise_error(Hashie::Extensions::Coercion::CoercionError, /Cannot coerce property :hi from Fixnum to Symbol/) + expect { instance[:hi] = 1 }.to raise_error(Hashie::CoercionError, /Cannot coerce property :hi from Fixnum to Symbol/) end it 'coerces Integer to String' do |