Sha256: fe2b243a0e767a4da7326231155566bbfd2f6a6df116fcd04fb2db75f2dd386b

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

require 'spec_helper'
require 'chronic'

describe "Timespan" do
	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 duration with String' do
		let(:timespan)  { TimeSpan.new :from => from, :duration => "3 days" }

  	it 'should be 3 days' do
  		timespan.to_d.should == 3
  	end
  end

  describe 'set duration with Spanner String including and' do
		let(:timespan)  { TimeSpan.new :from => from, :duration => "3 days and 2 hours" }

  	it 'should be 3 days and 2 hrs' do
  		timespan.to_h.should == (24 * 3) + 2
  	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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
timespan-0.1.4 spec/timespan_spec.rb