aboutsummaryrefslogtreecommitdiffstats
path: root/spec/lib/time_duration_spec.rb
blob: 1cba1f6d55562198c71eff72ee5551418a35bd3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'spec_helper'

describe TimeDuration do
  describe ".exceeds_gap?" do
    context "when duration is 4.hours" do
      it "should return false if gap < 1.hour" do
        t1 = Time.now
        t2 = Time.now + 3.minutes
        expect(TimeDuration.exceeds_gap?(4.hours, t1, t2)).to be_falsey
      end

      it "should return true if gap > 4.hour" do
        t1 = Time.now
        t2 = Time.now + (4.hours + 1.minutes)
        expect(TimeDuration.exceeds_gap?(4.hours, t1, t2)).to be_truthy
      end

      it "returns true when `earlier` is later than `later`" do
        earlier = Time.new(2000, 1, 1, 11, 0, 0, 0)
        later = Time.new(2000, 1, 1, 12, 0, 0, 0)

        expect(TimeDuration.exceeds_gap?(4.hours, later, earlier)).to be true
      end

      it "returns false when `earlier` == `later`" do
        earlier = Time.new(2000, 1, 1, 1, 0, 0, 0)
        later = earlier

        expect(TimeDuration.exceeds_gap?(4.hours, later, earlier)).to be false
      end
    end
  end
end