summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Lincoln <max@devopsy.com>2014-08-08 13:27:13 -0400
committerMax Lincoln <max@devopsy.com>2014-08-08 13:27:13 -0400
commit2b824ca72c12c9eb699e21f6a52f07f44af5723d (patch)
tree83f50ebacc048eb860d89e3681eb5129736c40e5
parenta17d15888b11f12fc015573f8a2d1901d1994ce7 (diff)
downloadhashie-2b824ca72c12c9eb699e21f6a52f07f44af5723d.tar.gz
Updated tests because rbx TrueClass behavior is different than MRI
-rw-r--r--spec/hashie/extensions/coercion_spec.rb43
1 files changed, 40 insertions, 3 deletions
diff --git a/spec/hashie/extensions/coercion_spec.rb b/spec/hashie/extensions/coercion_spec.rb
index 15c8ac8..2e729a4 100644
--- a/spec/hashie/extensions/coercion_spec.rb
+++ b/spec/hashie/extensions/coercion_spec.rb
@@ -1,6 +1,10 @@
require 'spec_helper'
describe Hashie::Extensions::Coercion do
+ class NotInitializable
+ private_class_method :new
+ end
+
class Initializable
attr_reader :coerced, :value
@@ -155,8 +159,24 @@ describe Hashie::Extensions::Coercion do
end
it 'raises errors for non-coercable types' do
- subject.coerce_key :foo, TrueClass
- expect { instance[:foo] = true }.to raise_error(TypeError, /TrueClass is not a coercable type/)
+ subject.coerce_key :foo, NotInitializable
+ expect { instance[:foo] = 'true' }.to raise_error(TypeError, /NotInitializable is not a coercable type/)
+ end
+
+ pending 'can coerce false' do
+ subject.coerce_key :foo, Initializable
+
+ instance[:foo] = false
+ expect(instance[:foo]).to be_coerced
+ expect(instance[:foo].value).to eq(false)
+ end
+
+ pending 'can coerce nil' do
+ subject.coerce_key :foo, Initializable
+
+ instance[:foo] = nil
+ expect(instance[:foo]).to be_coerced
+ expect(instance[:foo].value).to be_nil
end
end
@@ -346,7 +366,8 @@ describe Hashie::Extensions::Coercion do
end
pending 'coerces Integer to String' do
- # This isn't possible because coerce_value doesn't handle superclasses
+ subject.coerce_value Integer, String
+
instance[:foo] = 2
instance[:bar] = 2.7
expect(instance[:foo]).to be_a(String)
@@ -354,6 +375,22 @@ describe Hashie::Extensions::Coercion do
expect(instance[:bar]).to be_a(String)
expect(instance[:bar]).to eq('2.0')
end
+
+ pending 'coerces Numeric to String' do
+ subject.coerce_value Numeric, String
+
+ {
+ fixnum: 2,
+ bignum: 12_345_667_890_987_654_321,
+ float: 2.7,
+ rational: Rational(2, 3),
+ complex: Complex(1)
+ }.each do | k, v |
+ instance[k] = v
+ expect(instance[k]).to be_a(String)
+ expect(instance[k]).to eq(v.to_s)
+ end
+ end
end
end