spec/lib/m3u8/reader_spec.rb in m3u8-0.7.1 vs spec/lib/m3u8/reader_spec.rb in m3u8-0.8.0

- old
+ new

@@ -1,16 +1,18 @@ # frozen_string_literal: true require 'spec_helper' describe M3u8::Reader do + let(:reader) { described_class.new } + describe '#read' do - it 'should parse master playlist' do + it 'parses master playlist' do file = File.open('spec/fixtures/master.m3u8') reader = M3u8::Reader.new playlist = reader.read(file) expect(playlist.master?).to be true - + expect(playlist.discontinuity_sequence).to be_nil expect(playlist.independent_segments).to be true item = playlist.items[0] expect(item).to be_a(M3u8::SessionKeyItem) expect(item.method).to eq('AES-128') @@ -48,11 +50,11 @@ item = playlist.items.last expect(item.resolution).to be_nil end - it 'should parse master playlist with I-Frames' do + it 'parses master playlist with I-Frames' do file = File.open('spec/fixtures/master_iframes.m3u8') reader = M3u8::Reader.new playlist = reader.read(file) expect(playlist.master?).to be true @@ -63,17 +65,18 @@ expect(item.bandwidth).to eq(86_000) expect(item.iframe).to be true expect(item.uri).to eq('low/iframe.m3u8') end - it 'should parse segment playlist' do + it 'parses media playlist' do file = File.open('spec/fixtures/playlist.m3u8') reader = M3u8::Reader.new playlist = reader.read(file) expect(playlist.master?).to be false expect(playlist.version).to eq(4) expect(playlist.sequence).to eq(1) + expect(playlist.discontinuity_sequence).to eq(8) expect(playlist.cache).to be false expect(playlist.target).to eq(12) expect(playlist.type).to eq('VOD') item = playlist.items[0] @@ -86,11 +89,11 @@ expect(item.time).to eq(Time.iso8601('2010-02-19T14:54:23Z')) expect(playlist.items.size).to eq(140) end - it 'should parse I-Frame playlist' do + it 'parses I-Frame playlist' do file = File.open('spec/fixtures/iframes.m3u8') reader = M3u8::Reader.new playlist = reader.read(file) expect(playlist.iframes_only).to be true @@ -106,11 +109,11 @@ item = playlist.items[1] expect(item.byterange.length).to eq(7144) expect(item.byterange.start).to be_nil end - it 'should parse segment playlist with comments' do + it 'parses segment playlist with comments' do file = File.open('spec/fixtures/playlist_with_comments.m3u8') reader = M3u8::Reader.new playlist = reader.read(file) expect(playlist.master?).to be false expect(playlist.version).to eq(4) @@ -128,11 +131,11 @@ expect(item).to be_a(M3u8::DiscontinuityItem) expect(playlist.items.size).to eq(139) end - it 'should parse variant playlist with audio options and groups' do + it 'parses variant playlist with audio options and groups' do file = File.open('spec/fixtures/variant_audio.m3u8') reader = M3u8::Reader.new playlist = reader.read(file) expect(playlist.master?).to be true @@ -149,11 +152,11 @@ expect(item.default).to be true expect(item.uri).to eq('englo/prog_index.m3u8') expect(item.forced).to be true end - it 'should parse variant playlist with camera angles' do + it 'parses variant playlist with camera angles' do file = File.open('spec/fixtures/variant_angles.m3u8') reader = M3u8::Reader.new playlist = reader.read(file) expect(playlist.master?).to be true @@ -175,11 +178,11 @@ expect(item.video).to eq('200kbs') expect(item.closed_captions).to eq('captions') expect(item.subtitles).to eq('subs') end - it 'should process multiple reads as separate playlists' do + it 'processes multiple reads as separate playlists' do file = File.open('spec/fixtures/master.m3u8') reader = M3u8::Reader.new playlist = reader.read(file) expect(playlist.items.size).to eq(8) @@ -188,11 +191,11 @@ playlist = reader.read(file) expect(playlist.items.size).to eq(8) end - it 'should parse playlist with session data' do + it 'parses playlist with session data' do file = File.open('spec/fixtures/session_data.m3u8') reader = M3u8::Reader.new playlist = reader.read(file) expect(playlist.items.size).to eq(3) @@ -201,11 +204,11 @@ expect(item).to be_a(M3u8::SessionDataItem) expect(item.data_id).to eq('com.example.lyrics') expect(item.uri).to eq('lyrics.json') end - it 'should parse encrypted playlist' do + it 'parses encrypted playlist' do file = File.open('spec/fixtures/encrypted.m3u8') reader = M3u8::Reader.new playlist = reader.read(file) expect(playlist.items.size).to eq(6) @@ -214,11 +217,11 @@ expect(item).to be_a(M3u8::KeyItem) expect(item.method).to eq('AES-128') expect(item.uri).to eq('https://priv.example.com/key.php?r=52') end - it 'should parse map (media intialization section) playlists' do + it 'parses map (media intialization section) playlists' do file = File.open('spec/fixtures/map_playlist.m3u8') reader = M3u8::Reader.new playlist = reader.read(file) expect(playlist.items.size).to eq(1) @@ -228,32 +231,39 @@ expect(item.uri).to eq('frelo/prog_index.m3u8') expect(item.byterange.length).to eq(4500) expect(item.byterange.start).to eq(600) end - it 'should read segment with timestamp' do + it 'reads segment with timestamp' do file = File.open('spec/fixtures/timestamp_playlist.m3u8') reader = M3u8::Reader.new playlist = reader.read(file) expect(playlist.items.count).to eq(6) item_date_time = playlist.items.first.program_date_time expect(item_date_time).to be_a(M3u8::TimeItem) expect(item_date_time.time).to eq(Time.iso8601('2016-04-11T15:24:31Z')) end - context 'playlist with daterange' do - it 'parses playlist' do - file = File.open('spec/fixtures/date_range_scte35.m3u8') - reader = M3u8::Reader.new - playlist = reader.read(file) - expect(playlist.items.count).to eq(5) + it 'parses playlist with daterange' do + file = File.open('spec/fixtures/date_range_scte35.m3u8') + reader = M3u8::Reader.new + playlist = reader.read(file) + expect(playlist.items.count).to eq(5) - item = playlist.items[0] - expect(item).to be_a(M3u8::DateRangeItem) + item = playlist.items[0] + expect(item).to be_a(M3u8::DateRangeItem) - item = playlist.items[4] - expect(item).to be_a(M3u8::DateRangeItem) + item = playlist.items[4] + expect(item).to be_a(M3u8::DateRangeItem) + end + + context 'when playlist source is invalid' do + it 'raises error with message' do + message = 'Playlist must start with a #EXTM3U tag, line read ' \ + 'contained the value: /path/to/file' + expect { reader.read('/path/to/file') } + .to raise_error(M3u8::InvalidPlaylistError, message) end end end end