Sha256: 5dc2bfab33db0ef60ead4d611b8c05c7ef4171e0da805cfd40e607f84dc9e92a

Contents?: true

Size: 1.5 KB

Versions: 6

Compression:

Stored size: 1.5 KB

Contents

require 'spec_helper'

module TimeClock
  describe Shift do

    let(:start_time) { Time.new(2013,8,19,6,0) }
    let(:end_time) { Time.new(2013,8,19,18,0) }

    subject do
      described_class.new(start_time, end_time)
    end

    it "should set the start time" do
      expect(subject.start_time).to eq start_time
    end

    it "should set the end time" do
      expect(subject.end_time).to eq end_time
    end

    it "should raise the right exception if the end time is before the start time" do
      expect{described_class.new(end_time, start_time)}.to raise_error Shift::EndTimeAfterStartTimeError
    end

    it "should be eq if the times are equal" do
      expect(subject).to eq subject.dup
    end

    context "when evaluating overlaps" do
      let(:overlapping_shift) { Shift.new(Time.new(2013,8,19,5), Time.new(2013,8,19,10)) }
      let(:non_overlapping_shift) { Shift.new(Time.new(2013,8,18,5), Time.new(2013,8,18,10)) }
      it "should know when it does" do
        expect(overlapping_shift.overlaps?(subject)).to be_true
      end
      it "should know when it doesn't" do
        expect(non_overlapping_shift.overlaps?(subject)).to_not be_true
      end
      it "should calculate the overlapping seconds when there is an overlap" do
        expect(overlapping_shift.overlapping_seconds(subject)).to eq 4 * 60 * 60
      end
      it "should calculate the overlapping seconds when there isn't an overlap" do
        expect(non_overlapping_shift.overlapping_seconds(subject)).to eq 0
      end
    end


  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
time_clock-0.0.8 spec/lib/time_clock/shift_spec.rb
time_clock-0.0.5 spec/lib/time_clock/shift_spec.rb
time_clock-0.0.4 spec/lib/time_clock/shift_spec.rb
time_clock-0.0.3 spec/lib/time_clock/shift_spec.rb
time_clock-0.0.2 spec/lib/time_clock/shift_spec.rb
time_clock-0.0.1 spec/lib/time_clock/shift_spec.rb