Sha256: 85175fa0f683b9d85f5f6afb046babe69f6c51e48b6ed3abaf7671fc46a859b8

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

describe NetworkExecutive::Lineup do

  let(:show) do
    show = double('show', program_name:'show 1')
  end

  let(:channel) do
    channel = double('channel', display_name:'channel a').as_null_object

    channel.stub(:whats_on?).and_yield( show ).and_return [ show ]

    channel
  end

  let(:channels) do
    [
      channel
    ]
  end

  before do
    Timecop.freeze Time.now.change hour:12, min:0, sec:0

    NetworkExecutive::Network.stub( :channels ).and_return channels
  end

  describe '#start_time' do
    context 'the default value' do
      subject { described_class.new.start_time }

      it 'should default to now' do
        subject.should eq Time.now
      end
    end

    context 'an explicit value' do
      let(:start) { Time.now.change hour:11, min:47, sec:54 }

      subject { described_class.new( start ).start_time }

      it 'should be rounded' do
        subject.should eq Time.now.change hour:11, min:45, sec:0
      end
    end
  end

  describe '#stop_time' do
    context 'the default value' do
      subject { described_class.new.stop_time }

      it 'should default to 1.5hours from now' do
        subject.should eq 1.5.hours.from_now
      end
    end

    context 'an explicit value' do
      let(:stop) { Time.now.change hour:13, min:47, sec:54 }

      subject { described_class.new( nil, stop ).stop_time }

      it 'should be rounded' do
        subject.should eq Time.now.change hour:13, min:45, sec:0
      end
    end
  end

  describe '#channels' do
    subject { described_class.new[:channels] }

    it { should be_an Array }

    it 'should contain a channel' do
      subject.first[:channel].should == channel
    end

    it 'should contain an array of scheduled programs' do
      subject.first[:schedule].should be_an Array
    end

    it 'should ask the channel what is on' do
      args = [ Time.now, 1.5.hours.from_now, kind_of(Hash) ]

      channels.first.should_receive(:whats_on?).with( *args )

      subject
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
network_executive-0.0.4 spec/models/lineup_spec.rb