Files
redistat/spec/date_spec.rb
2010-07-19 01:06:45 +03:00

42 lines
1.3 KiB
Ruby

require "spec_helper"
describe Redistat::Date do
it "should initialize from Time object" do
now = Time.now
rdate = Redistat::Date.new(now)
[:year, :month, :day, :hour, :min, :sec].each { |k| rdate.send(k).should == now.send(k) }
end
it "should initialize from Date object" do
today = Date.today
rdate = Redistat::Date.new(today)
[:year, :month, :day].each { |k| rdate.send(k).should == today.send(k) }
[:hour, :min, :sec].each { |k| rdate.send(k).should == nil }
end
it "should initialize from String object" do
now = Time.now
rdate = Redistat::Date.new(now.to_s)
[:year, :month, :day, :hour, :min, :sec].each { |k| rdate.send(k).should == now.send(k) }
end
it "should convert to string with correct depths" do
today = Date.today
rdate = Redistat::Date.new(today)
props = [:year, :month, :day, nil]
props.each do
rdate.to_s(props.last).should == props.map { |k| today.send(k).to_s.rjust(2, '0') if !k.nil? }.join
props.pop
end
now = Time.now
rdate = Redistat::Date.new(now)
props = [:year, :month, :day, :hour, :min, :sec, nil]
props.each do
rdate.to_s(props.last).should == props.map { |k| now.send(k).to_s.rjust(2, '0') if !k.nil? }.join
props.pop
end
end
end