Permalink
Browse files

Add unit test for Virtus::Attribute::Hash#coerce

  • Loading branch information...
1 parent 05bd947 commit c4a910183d77b5b61af640d7d0a4612668d63066 @greyblake greyblake committed Sep 2, 2012
Showing with 20 additions and 0 deletions.
  1. +20 −0 spec/unit/virtus/attribute/hash/coerce_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe Virtus::Attribute::Hash, '#coerce' do
+ subject { object.coerce(input_value) }
+
+ let(:options) { {:key_type => String, :value_type => Float } }
+ let(:object) { Virtus::Attribute::Hash.new('stuff', options) }
+
+ context 'respond to `inject`' do
+ let(:input_value) { { :one => '1', 'two' => 2 } }
+
+ it { should == { 'one' => 1.0, 'two' => 2.0 } }
+ end
+
+ context 'does not respond to `inject`' do
+ let(:input_value) { :symbol }
+
+ it { should == :symbol }
+ end
+end

0 comments on commit c4a9101

Please sign in to comment.