spec/dslh_spec.rb in dslh-0.3.1 vs spec/dslh_spec.rb in dslh-0.3.2
- old
+ new
@@ -2529,10 +2529,22 @@
"key3"=>{100=>200, "XXX"=>:XXX},
"key4"=>{"system"=>{"300"=>"400", :FOO=>:BAR}, "key42"=>100}}}
)
end
+ it 'include time"' do
+ h = Dslh.eval do
+ key1 'value'
+ key2 Time.parse('2016/05/21 00:00 UTC')
+ end
+
+ expect(h).to eq(
+ {"key1"=>"value",
+ "key2"=>Time.parse('2016/05/21 00:00 UTC')}
+ )
+ end
+
it 'should convert hash to dsl (symbol key)' do
h = {:glossary=>
{:title=>"example glossary",
:GlossDiv=>
{:title=>"S",
@@ -2568,9 +2580,57 @@
end
GlossSee "markup"
end
end
end
+end
+ EOS
+ end
+
+ it 'should convert hash to dsl (inclute Time)' do
+ h = {:glossary=>
+ {:title=>"example glossary",
+ :date=>Time.parse('2016/05/21 00:00 UTC')}}
+
+ parse_method = Time.method(:parse)
+ time_cc = (class << Time; self; end)
+ time_cc.send(:undef_method, :parse)
+
+ dsl = Dslh.deval(h)
+ expect(dsl).to eq(<<-EOS)
+glossary do
+ title "example glossary"
+ date Time.at(1463788800, 0)
+end
+ EOS
+
+ time_cc.send(:define_method, :parse, &parse_method)
+ end
+
+ it 'should convert hash to dsl (inclute Time / use Time#parse)' do
+ h = {:glossary=>
+ {:title=>"example glossary",
+ :date=>Time.parse('2016/05/21 00:00 UTC')}}
+
+ dsl = Dslh.deval(h)
+ expect(dsl).to eq(<<-EOS)
+glossary do
+ title "example glossary"
+ date Time.parse("2016-05-21 00:00:00 UTC")
+end
+ EOS
+ end
+
+ it 'should convert hash to dsl (inclute Time / pass time_inspecter)' do
+ h = {:glossary=>
+ {:title=>"example glossary",
+ :date=>Time.parse('2016/05/21 00:00 UTC')}}
+
+ dsl = Dslh.deval(h, :time_inspecter => proc {|i| i.to_s.inspect })
+ expect(dsl).to eq(<<-EOS)
+glossary do
+ title "example glossary"
+ date "2016-05-21 00:00:00 UTC"
end
EOS
end
end