spec/timespan_spec.rb in timespan-0.1.0 vs spec/timespan_spec.rb in timespan-0.1.2
- old
+ new
@@ -1,7 +1,46 @@
-require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+require 'spec_helper'
+require 'chronic'
describe "Timespan" do
- it "fails" do
- fail "hey buddy, you should probably rename this file and start specing for real"
+ subject { timespan }
+
+ let(:timespan) { TimeSpan.new :from => from, :to => to}
+
+ let(:from) { Chronic.parse("1 day ago") }
+ let(:to) { Time.now }
+
+ it "spans 1 day" do
+ timespan.to_d.should == 1
end
+
+ it "spans 86400 sec" do
+ timespan.to_secs.should == 86400
+ end
+
+ it "spans 86400 sec" do
+ timespan.to_mils.should be_within(10).of(86400000)
+ end
+
+ describe 'set with duration' do
+ let(:duration) { Duration.new(:days => 3) }
+ let(:timespan) { TimeSpan.new :from => from, :duration => duration }
+
+ it 'should be 3 days' do
+ timespan.to_d.should == 3
+ end
+ end
+
+ describe 'set start_time to new' do
+ let(:timespan) { TimeSpan.new :from => from, :to => to }
+
+ before :each do
+ @old_timespan = timespan.clone
+ @new_timespan = timespan.clone
+ @new_timespan.start_date = Chronic.parse("2 days ago")
+ end
+
+ it 'should have diff timespans' do
+ @old_timespan.to_d.should_not == @new_timespan.to_d
+ end
+ end
end