spec/test_myrrha.rb in myrrha-1.0.0 vs spec/test_myrrha.rb in myrrha-1.1.0
- old
+ new
@@ -82,6 +82,43 @@
c.coercion String, Symbol, lambda{|s,t| s.to_s.upcase.to_sym}
end
rules.coerce("hello", Symbol).should eq(:HELLO)
end
+ it "should used superdomain rules in an optimistic strategy" do
+ rules = Myrrha.coercions do |c|
+ c.coercion String, Numeric, lambda{|s,t| Integer(s)}
+ end
+ rules.coerce("12", Integer).should eql(12)
+ lambda{ rules.coerce("12", Float) }.should raise_error(Myrrha::Error)
+ end
+
+ describe "path convertions" do
+ let(:rules){
+ Myrrha.coercions do |c|
+ c.coercion Integer, String, lambda{|s,t| s.to_s}
+ c.coercion String, Float, lambda{|s,t| Float(s)}
+ c.coercion Integer, Float, [String]
+ c.coercion Float, String, lambda{|s,t| s.to_s}
+ c.coercion String, Symbol, lambda{|s,t| s.to_sym}
+ c.coercion Integer, Symbol, [Float, String]
+ end
+ }
+ it "should work with a simple and single" do
+ rules.coerce(12, Float).should eql(12.0)
+ end
+ it "should work with a complex and multiple path" do
+ rules.coerce(12, Symbol).should eql(:"12.0")
+ end
+ end
+
+ specify "path convertions (from CHANGELOG)" do
+ rules = Myrrha.coercions do |r|
+ r.coercion String, Symbol, lambda{|s,t| s.to_sym }
+ r.coercion Float, String, lambda{|s,t| s.to_s }
+ r.coercion Integer, Float, lambda{|s,t| Float(s) }
+ r.coercion Integer, Symbol, [Float, String]
+ end
+ rules.coerce(12, Symbol).should eql(:"12.0")
+ end
+
end