summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Lincoln <max@devopsy.com>2014-08-14 19:49:41 -0400
committerMax Lincoln <max@devopsy.com>2014-08-14 19:49:41 -0400
commit11ef88b31c50cea558fa9be6dabdf6b39d593ed0 (patch)
tree9feab242bcc31e6e0d2d71afac9bbf6791718618
parentc4957c6ff9754b88499633bf2cdcfdea19320670 (diff)
downloadhashie-11ef88b31c50cea558fa9be6dabdf6b39d593ed0.tar.gz
A bit of cleanup
-rw-r--r--lib/hashie/extensions/coercion.rb5
-rw-r--r--spec/hashie/extensions/coercion_spec.rb14
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