Sha256: 5e3eb17bc484b21ad95502d9ee3719a0df27ea2fa6ea970d302f664ef2ee7334

Contents?: true

Size: 1.93 KB

Versions: 20

Compression:

Stored size: 1.93 KB

Contents

require 'spec_helper'

describe "Timespan" do
	subject { timespan }

  context 'From and To with 2 day apart' do
  	let(:timespan) { Timespan.new :from => from, :to => to}

  	let(:from) { 2.days.ago }
  	let(:to)   { Time.now }

    describe 'Compare' do
      describe '==' do  
      	specify do 
      		(subject == 2.days).should be_true
      	end  
      end

      describe '<' do    
      	specify do 
      		(subject < 2.day).should be_false
      	end

        specify do 
          (subject < 3.days).should be_true
        end
      end    

      describe '>' do    
      	specify do 
      		(subject > 2.day).should be_false
      	end

        specify do 
          (subject > 1.day).should be_true
        end
      end

      describe '>=' do    
        specify do 
          (subject >= 2.days).should be_true
        end
      end

      describe '<=' do    
        specify do 
          (subject <= 2.days).should be_true
        end
      end

      describe 'between? dates' do    
        specify do 
          subject.between?(2.days.ago, 1.minute.from_now).should be_true
        end

        specify do 
          subject.between?(Time.now, 1.day.from_now).should be_false
        end
      end

      describe 'between? durations' do    
        specify do 
          subject.between?(1.days, 3.days).should be_true
        end

        specify do 
          subject.between?(3.days, 4.days).should be_false
        end
      end
    end     
  end

  context 'From 2 days ago until today' do
    let(:timespan) { Timespan.new :from => "2 days ago", :to => "1 hour ago" }    

    describe '.time_left' do
      it 'should have 0 days left' do
        timespan.time_left.days.should == 0
      end

      it 'should have 1 hour left' do
        timespan.time_left.hrs.should == -1
      end
    end  

    describe '.expired?' do
      it 'should have 0 days left' do
        timespan.expired?.should be_true
      end
    end 
  end  
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
timespan-0.6.0 spec/timespan/compare_spec.rb
timespan-0.5.9 spec/timespan/compare_spec.rb
timespan-0.5.7 spec/timespan/compare_spec.rb
timespan-0.5.6.1 spec/timespan/compare_spec.rb
timespan-0.5.6 spec/timespan/compare_spec.rb
timespan-0.5.5 spec/timespan/compare_spec.rb
timespan-0.5.4 spec/timespan/compare_spec.rb
timespan-0.5.3 spec/timespan/compare_spec.rb
timespan-0.5.2 spec/timespan/compare_spec.rb
timespan-0.5.1 spec/timespan/compare_spec.rb
timespan-0.5.0 spec/timespan/compare_spec.rb
timespan-0.4.9 spec/timespan/compare_spec.rb
timespan-0.4.6 spec/timespan/compare_spec.rb
timespan-0.4.5 spec/timespan/compare_spec.rb
timespan-0.4.4 spec/timespan/compare_spec.rb
timespan-0.4.3 spec/timespan/compare_spec.rb
timespan-0.4.2 spec/timespan/compare_spec.rb
timespan-0.4.1 spec/timespan/compare_spec.rb
timespan-0.4.0 spec/timespan/compare_spec.rb
timespan-0.3.2 spec/timespan/compare_spec.rb