mp3file 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,13 +5,13 @@ include CommonHelpers
5
5
 
6
6
  describe Mp3file::MP3Header do
7
7
  it "raises an error if the first byte isn't 255" do
8
- lambda { Mp3file::MP3Header.new(create_io([ 0xAA, 0xF8, 0x10, 0x01 ])) }.
9
- should(raise_error(Mp3file::InvalidMP3HeaderError))
8
+ expect { Mp3file::MP3Header.new(create_io([ 0xAA, 0xF8, 0x10, 0x01 ])) }.
9
+ to(raise_error(Mp3file::InvalidMP3HeaderError))
10
10
  end
11
11
 
12
12
  it "raises an error if the second sync byte is wrong" do
13
- lambda { Mp3file::MP3Header.new(create_io([ 0xFF, 0xB8, 0x10, 0x01 ])) }.
14
- should(raise_error(Mp3file::InvalidMP3HeaderError))
13
+ expect { Mp3file::MP3Header.new(create_io([ 0xFF, 0xB8, 0x10, 0x01 ])) }.
14
+ to(raise_error(Mp3file::InvalidMP3HeaderError))
15
15
  end
16
16
 
17
17
  describe "#version" do
@@ -21,13 +21,13 @@ describe Mp3file::MP3Header do
21
21
  ].each do |bytes, version|
22
22
  it "recognizes #{version}" do
23
23
  h = Mp3file::MP3Header.new(create_io(bytes))
24
- h.version.should == version
24
+ expect(h.version).to eq(version)
25
25
  end
26
26
  end
27
27
 
28
28
  it "raises an error on an invalid version" do
29
- lambda { Mp3file::MP3Header.new(create_io([ 0xFF, 0b1110_1010, 0x10, 0x01 ])) }.
30
- should(raise_error(Mp3file::InvalidMP3HeaderError))
29
+ expect { Mp3file::MP3Header.new(create_io([ 0xFF, 0b1110_1010, 0x10, 0x01 ])) }.
30
+ to(raise_error(Mp3file::InvalidMP3HeaderError))
31
31
  end
32
32
  end
33
33
 
@@ -38,13 +38,13 @@ describe Mp3file::MP3Header do
38
38
  ].each do |bytes, layer|
39
39
  it "recognizes #{layer}" do
40
40
  h = Mp3file::MP3Header.new(create_io(bytes))
41
- h.layer.should == layer
41
+ expect(h.layer).to eq(layer)
42
42
  end
43
43
  end
44
44
 
45
45
  it "raises an error on an invalid version" do
46
- lambda { Mp3file::MP3Header.new(create_io([ 0xFF, 0b1111_1000, 0x10, 0x01 ])) }.
47
- should(raise_error(Mp3file::InvalidMP3HeaderError))
46
+ expect { Mp3file::MP3Header.new(create_io([ 0xFF, 0b1111_1000, 0x10, 0x01 ])) }.
47
+ to(raise_error(Mp3file::InvalidMP3HeaderError))
48
48
  end
49
49
  end
50
50
 
@@ -75,18 +75,18 @@ describe Mp3file::MP3Header do
75
75
  it "detects #{br} kbps" do
76
76
  io = create_io([ 0xFF, byte2, (i + 1) << 4, 0x01 ])
77
77
  h = Mp3file::MP3Header.new(io)
78
- h.bitrate.should == br * 1000
78
+ expect(h.bitrate).to eq(br * 1000)
79
79
  end
80
80
  end
81
81
 
82
82
  it "rejects a free bitrate" do
83
83
  io = create_io([ 0xFF, byte2, 0x00, 0x01 ])
84
- lambda { Mp3file::MP3Header.new(io) }.should(raise_error(Mp3file::InvalidMP3HeaderError))
84
+ expect { Mp3file::MP3Header.new(io) }.to(raise_error(Mp3file::InvalidMP3HeaderError))
85
85
  end
86
86
 
87
87
  it "rejects a bad bitrate" do
88
88
  io = create_io([ 0xFF, byte2, 0xF0, 0x01 ])
89
- lambda { Mp3file::MP3Header.new(io) }.should(raise_error(Mp3file::InvalidMP3HeaderError))
89
+ expect { Mp3file::MP3Header.new(io) }.to(raise_error(Mp3file::InvalidMP3HeaderError))
90
90
  end
91
91
  end
92
92
  end
@@ -102,13 +102,13 @@ describe Mp3file::MP3Header do
102
102
  it "detects #{sr} Hz" do
103
103
  io = create_io([ 0xFF, byte2, 0x10 + (i << 2), 0x01 ])
104
104
  h = Mp3file::MP3Header.new(io)
105
- h.samplerate.should == sr
105
+ expect(h.samplerate).to eq(sr)
106
106
  end
107
107
  end
108
108
 
109
109
  it "rejects reserved samplerate values" do
110
110
  io = create_io([ 0xFF, byte2, 0x1C, 0x01 ])
111
- lambda { Mp3file::MP3Header.new(io) }.should(raise_error(Mp3file::InvalidMP3HeaderError))
111
+ expect { Mp3file::MP3Header.new(io) }.to(raise_error(Mp3file::InvalidMP3HeaderError))
112
112
  end
113
113
  end
114
114
  end
@@ -118,13 +118,13 @@ describe Mp3file::MP3Header do
118
118
  it "detects if the frame is padded" do
119
119
  io = create_io([ 0xFF, 0xFB, 0b0001_1010, 0x01 ])
120
120
  h = Mp3file::MP3Header.new(io)
121
- h.has_padding.should == true
121
+ expect(h.has_padding).to eq(true)
122
122
  end
123
123
 
124
124
  it "detects if the frame is not padded" do
125
125
  io = create_io([ 0xFF, 0xFB, 0b0001_1000, 0x01 ])
126
126
  h = Mp3file::MP3Header.new(io)
127
- h.has_padding.should == false
127
+ expect(h.has_padding).to eq(false)
128
128
  end
129
129
  end
130
130
 
@@ -132,25 +132,25 @@ describe Mp3file::MP3Header do
132
132
  it "detects Stereo" do
133
133
  io = create_io([ 0xFF, 0xFB, 0x92, 0b0000_0001 ])
134
134
  h = Mp3file::MP3Header.new(io)
135
- h.mode.should == 'Stereo'
135
+ expect(h.mode).to eq('Stereo')
136
136
  end
137
137
 
138
138
  it "detects Joint Stereo" do
139
139
  io = create_io([ 0xFF, 0xFB, 0x92, 0b0100_0001 ])
140
140
  h = Mp3file::MP3Header.new(io)
141
- h.mode.should == 'Joint Stereo'
141
+ expect(h.mode).to eq('Joint Stereo')
142
142
  end
143
143
 
144
144
  it "detects Dual Channel" do
145
145
  io = create_io([ 0xFF, 0xFB, 0x92, 0b1000_0001 ])
146
146
  h = Mp3file::MP3Header.new(io)
147
- h.mode.should == 'Dual Channel'
147
+ expect(h.mode).to eq('Dual Channel')
148
148
  end
149
149
 
150
150
  it "detects Mono" do
151
151
  io = create_io([ 0xFF, 0xFB, 0x92, 0b1100_0001 ])
152
152
  h = Mp3file::MP3Header.new(io)
153
- h.mode.should == 'Mono'
153
+ expect(h.mode).to eq('Mono')
154
154
  end
155
155
  end
156
156
 
@@ -159,25 +159,25 @@ describe Mp3file::MP3Header do
159
159
  it "detects bands 4 to 31" do
160
160
  io = create_io([ 0xFF, 0xFE, 0x92, 0b0100_0001 ])
161
161
  h = Mp3file::MP3Header.new(io)
162
- h.mode_extension.should == 'bands 4 to 31'
162
+ expect(h.mode_extension).to eq('bands 4 to 31')
163
163
  end
164
164
 
165
165
  it "detects bands 8 to 31" do
166
166
  io = create_io([ 0xFF, 0xFD, 0x92, 0b0101_0001 ])
167
167
  h = Mp3file::MP3Header.new(io)
168
- h.mode_extension.should == 'bands 8 to 31'
168
+ expect(h.mode_extension).to eq('bands 8 to 31')
169
169
  end
170
170
 
171
171
  it "detects bands 12 to 31" do
172
172
  io = create_io([ 0xFF, 0xFE, 0x92, 0b0110_0001 ])
173
173
  h = Mp3file::MP3Header.new(io)
174
- h.mode_extension.should == 'bands 12 to 31'
174
+ expect(h.mode_extension).to eq('bands 12 to 31')
175
175
  end
176
176
 
177
177
  it "detects bands 16 to 31" do
178
178
  io = create_io([ 0xFF, 0xFD, 0x92, 0b0111_0001 ])
179
179
  h = Mp3file::MP3Header.new(io)
180
- h.mode_extension.should == 'bands 16 to 31'
180
+ expect(h.mode_extension).to eq('bands 16 to 31')
181
181
  end
182
182
  end
183
183
 
@@ -185,25 +185,25 @@ describe Mp3file::MP3Header do
185
185
  it "detects neither mode extension" do
186
186
  io = create_io([ 0xFF, 0xFB, 0x92, 0b0100_0001 ])
187
187
  h = Mp3file::MP3Header.new(io)
188
- h.mode_extension.should == nil
188
+ expect(h.mode_extension).to eq(nil)
189
189
  end
190
190
 
191
191
  it "detects only Intensity Stereo" do
192
192
  io = create_io([ 0xFF, 0xFB, 0x92, 0b0101_0001 ])
193
193
  h = Mp3file::MP3Header.new(io)
194
- h.mode_extension.should == 'Intensity Stereo'
194
+ expect(h.mode_extension).to eq('Intensity Stereo')
195
195
  end
196
196
 
197
197
  it "detects only M/S Stereo" do
198
198
  io = create_io([ 0xFF, 0xFB, 0x92, 0b0110_0001 ])
199
199
  h = Mp3file::MP3Header.new(io)
200
- h.mode_extension.should == 'M/S Stereo'
200
+ expect(h.mode_extension).to eq('M/S Stereo')
201
201
  end
202
202
 
203
203
  it "detects both Intensity Stereo & M/S Stereo" do
204
204
  io = create_io([ 0xFF, 0xFB, 0x92, 0b0111_0001 ])
205
205
  h = Mp3file::MP3Header.new(io)
206
- h.mode_extension.should == [ 'Intensity Stereo', 'M/S Stereo' ]
206
+ expect(h.mode_extension).to eq([ 'Intensity Stereo', 'M/S Stereo' ])
207
207
  end
208
208
  end
209
209
 
@@ -211,19 +211,19 @@ describe Mp3file::MP3Header do
211
211
  it "should return no mode extension for Stereo" do
212
212
  io = create_io([ 0xFF, 0xFE, 0x92, 0b0011_0001 ])
213
213
  h = Mp3file::MP3Header.new(io)
214
- h.mode_extension.should == nil
214
+ expect(h.mode_extension).to eq(nil)
215
215
  end
216
216
 
217
217
  it "should return no mode extension for Dual Channel" do
218
218
  io = create_io([ 0xFF, 0xFD, 0x92, 0b1011_0001 ])
219
219
  h = Mp3file::MP3Header.new(io)
220
- h.mode_extension.should == nil
220
+ expect(h.mode_extension).to eq(nil)
221
221
  end
222
222
 
223
223
  it "should return no mode extension for Mono" do
224
224
  io = create_io([ 0xFF, 0xFB, 0x92, 0b1111_0001 ])
225
225
  h = Mp3file::MP3Header.new(io)
226
- h.mode_extension.should == nil
226
+ expect(h.mode_extension).to eq(nil)
227
227
  end
228
228
  end
229
229
  end
@@ -232,13 +232,13 @@ describe Mp3file::MP3Header do
232
232
  it "detects copyrighted material" do
233
233
  io = create_io([ 0xFF, 0xFB, 0x92, 0b0111_1001 ])
234
234
  h = Mp3file::MP3Header.new(io)
235
- h.copyright.should == true
235
+ expect(h.copyright).to eq(true)
236
236
  end
237
237
 
238
238
  it "detects non-copyrighted material" do
239
239
  io = create_io([ 0xFF, 0xFB, 0x92, 0b0111_0001 ])
240
240
  h = Mp3file::MP3Header.new(io)
241
- h.copyright.should == false
241
+ expect(h.copyright).to eq(false)
242
242
  end
243
243
  end
244
244
 
@@ -246,13 +246,13 @@ describe Mp3file::MP3Header do
246
246
  it "detects original material" do
247
247
  io = create_io([ 0xFF, 0xFB, 0x92, 0b0111_0101 ])
248
248
  h = Mp3file::MP3Header.new(io)
249
- h.original.should == true
249
+ expect(h.original).to eq(true)
250
250
  end
251
251
 
252
252
  it "detects non-original material" do
253
253
  io = create_io([ 0xFF, 0xFB, 0x92, 0b0111_0001 ])
254
254
  h = Mp3file::MP3Header.new(io)
255
- h.original.should == false
255
+ expect(h.original).to eq(false)
256
256
  end
257
257
  end
258
258
 
@@ -260,24 +260,24 @@ describe Mp3file::MP3Header do
260
260
  it "detects no emphasis" do
261
261
  io = create_io([ 0xFF, 0xFB, 0x92, 0b0111_0000 ])
262
262
  h = Mp3file::MP3Header.new(io)
263
- h.emphasis.should == 'none'
263
+ expect(h.emphasis).to eq('none')
264
264
  end
265
265
 
266
266
  it "detects 50/15 ms" do
267
267
  io = create_io([ 0xFF, 0xFB, 0x92, 0b0111_0001 ])
268
268
  h = Mp3file::MP3Header.new(io)
269
- h.emphasis.should == '50/15 ms'
269
+ expect(h.emphasis).to eq('50/15 ms')
270
270
  end
271
271
 
272
272
  it "raises an error on 2" do
273
273
  io = create_io([ 0xFF, 0xFB, 0x92, 0b0111_0010 ])
274
- lambda { Mp3file::MP3Header.new(io) }.should(raise_error(Mp3file::InvalidMP3HeaderError))
274
+ expect { Mp3file::MP3Header.new(io) }.to(raise_error(Mp3file::InvalidMP3HeaderError))
275
275
  end
276
276
 
277
277
  it "detects CCIT J.17" do
278
278
  io = create_io([ 0xFF, 0xFB, 0x92, 0b0111_0011 ])
279
279
  h = Mp3file::MP3Header.new(io)
280
- h.emphasis.should == 'CCIT J.17'
280
+ expect(h.emphasis).to eq('CCIT J.17')
281
281
  end
282
282
  end
283
283
 
@@ -297,7 +297,7 @@ describe Mp3file::MP3Header do
297
297
  it("for #{name}, returns %d samples" % [ samples ]) do
298
298
  io = create_io([ 0xFF, byte2, 0x92, 0xC1 ])
299
299
  h = Mp3file::MP3Header.new(io)
300
- h.samples.should == samples
300
+ expect(h.samples).to eq(samples)
301
301
  end
302
302
  end
303
303
  end
@@ -313,7 +313,7 @@ describe Mp3file::MP3Header do
313
313
  it "for #{name}, returns #{size} bytes" do
314
314
  io = create_io([ 0xFF, byte2, byte3, 0xC1 ])
315
315
  h = Mp3file::MP3Header.new(io)
316
- h.frame_size.should == size
316
+ expect(h.frame_size).to eq(size)
317
317
  end
318
318
  end
319
319
  end
@@ -329,7 +329,24 @@ describe Mp3file::MP3Header do
329
329
  it "for #{name}, returns #{side_bytes} bytes" do
330
330
  io = create_io([ 0xFF, b2, b3, b4 ])
331
331
  h = Mp3file::MP3Header.new(io)
332
- h.side_bytes.should == side_bytes
332
+ expect(h.side_bytes).to eq(side_bytes)
333
+ end
334
+ end
335
+ end
336
+
337
+ describe "#duration" do
338
+ combinations = [
339
+ [ "MPEG 1 Layer I 32 kHz", 0xFF, 0x1B, 384.0 / 32000.0 ],
340
+ [ "MPEG 1 Layer II 48 kHz", 0xFD, 0x34, 1152.0 / 48000.0 ],
341
+ [ "MPEG 1 Layer III 44.1 kHz", 0xFB, 0x53, 1152.0 / 44100.0 ],
342
+ [ "MPEG 2 Layer II 16 kHz", 0xF5, 0x48, 1152.0 / 16000.0 ],
343
+ [ "MPEG 2 Layer III 24 kHz", 0xF3, 0xD5, 576.0 / 24000.0 ],
344
+ ]
345
+ combinations.each do |name, b2, b3, duration|
346
+ it "for #{name}, returns #{duration} seconds" do
347
+ io = create_io([ 0xFF, b2, b3, 0xC1 ])
348
+ h = Mp3file::MP3Header.new(io)
349
+ expect(h.duration).to be_within(1e-5).of(duration)
333
350
  end
334
351
  end
335
352
  end
@@ -6,52 +6,132 @@ include CommonHelpers
6
6
  describe Mp3file::XingHeader do
7
7
  it 'raises an error if the first 4 bytes don\'t say "Xing"' do
8
8
  io = StringIO.new("Ping\x00\x00\x00\x00")
9
- lambda { Mp3file::XingHeader.new(io) }.should(raise_error(Mp3file::InvalidXingHeaderError))
9
+ expect { Mp3file::XingHeader.new(io) }.to(raise_error(Mp3file::InvalidXingHeaderError))
10
10
  end
11
11
 
12
12
  it 'raises an error if the next int is more than 15' do
13
13
  io = StringIO.new("Xing\x00\x00\x00\x10")
14
- lambda { Mp3file::XingHeader.new(io) }.should(raise_error(Mp3file::InvalidXingHeaderError))
14
+ expect { Mp3file::XingHeader.new(io) }.to(raise_error(Mp3file::InvalidXingHeaderError))
15
15
  end
16
16
 
17
17
  describe "with no parts" do
18
18
  subject { Mp3file::XingHeader.new(StringIO.new("Xing\x00\x00\x00\x00")) }
19
- its(:frames) { should == nil }
20
- its(:bytes) { should == nil }
21
- its(:toc) { should == nil }
22
- its(:quality) { should == nil }
19
+
20
+ describe '#frames' do
21
+ subject { super().frames }
22
+ it { is_expected.to eq(nil) }
23
+ end
24
+
25
+ describe '#bytes' do
26
+ subject { super().bytes }
27
+ it { is_expected.to eq(nil) }
28
+ end
29
+
30
+ describe '#toc' do
31
+ subject { super().toc }
32
+ it { is_expected.to eq(nil) }
33
+ end
34
+
35
+ describe '#quality' do
36
+ subject { super().quality }
37
+ it { is_expected.to eq(nil) }
38
+ end
23
39
  end
24
40
 
25
41
  describe "with only a frame count" do
26
42
  subject { Mp3file::XingHeader.new(StringIO.new("Xing\x00\x00\x00\x01\x00\x00\x14\xFA")) }
27
- its(:frames) { should == 5370 }
28
- its(:bytes) { should == nil }
29
- its(:toc) { should == nil }
30
- its(:quality) { should == nil }
43
+
44
+ describe '#frames' do
45
+ subject { super().frames }
46
+ it { is_expected.to eq(5370) }
47
+ end
48
+
49
+ describe '#bytes' do
50
+ subject { super().bytes }
51
+ it { is_expected.to eq(nil) }
52
+ end
53
+
54
+ describe '#toc' do
55
+ subject { super().toc }
56
+ it { is_expected.to eq(nil) }
57
+ end
58
+
59
+ describe '#quality' do
60
+ subject { super().quality }
61
+ it { is_expected.to eq(nil) }
62
+ end
31
63
  end
32
64
 
33
65
  describe "with only a byte count" do
34
66
  subject { Mp3file::XingHeader.new(StringIO.new("Xing\x00\x00\x00\x02\x00\x00\x14\xFA")) }
35
- its(:frames) { should == nil }
36
- its(:bytes) { should == 5370 }
37
- its(:toc) { should == nil }
38
- its(:quality) { should == nil }
67
+
68
+ describe '#frames' do
69
+ subject { super().frames }
70
+ it { is_expected.to eq(nil) }
71
+ end
72
+
73
+ describe '#bytes' do
74
+ subject { super().bytes }
75
+ it { is_expected.to eq(5370) }
76
+ end
77
+
78
+ describe '#toc' do
79
+ subject { super().toc }
80
+ it { is_expected.to eq(nil) }
81
+ end
82
+
83
+ describe '#quality' do
84
+ subject { super().quality }
85
+ it { is_expected.to eq(nil) }
86
+ end
39
87
  end
40
88
 
41
89
  describe "with only a TOC" do
42
90
  subject { Mp3file::XingHeader.new(StringIO.new("Xing\x00\x00\x00\x04" + ("\x00" * 100))) }
43
- its(:frames) { should == nil }
44
- its(:bytes) { should == nil }
45
- its(:toc) { should == [ 0 ] * 100 }
46
- its(:quality) { should == nil }
91
+
92
+ describe '#frames' do
93
+ subject { super().frames }
94
+ it { is_expected.to eq(nil) }
95
+ end
96
+
97
+ describe '#bytes' do
98
+ subject { super().bytes }
99
+ it { is_expected.to eq(nil) }
100
+ end
101
+
102
+ describe '#toc' do
103
+ subject { super().toc }
104
+ it { is_expected.to eq([ 0 ] * 100) }
105
+ end
106
+
107
+ describe '#quality' do
108
+ subject { super().quality }
109
+ it { is_expected.to eq(nil) }
110
+ end
47
111
  end
48
112
 
49
113
  describe "with only a quality" do
50
114
  subject { Mp3file::XingHeader.new(StringIO.new("Xing\x00\x00\x00\x08\x00\x00\x00\x55")) }
51
- its(:frames) { should == nil }
52
- its(:bytes) { should == nil }
53
- its(:toc) { should == nil }
54
- its(:quality) { should == 85 }
115
+
116
+ describe '#frames' do
117
+ subject { super().frames }
118
+ it { is_expected.to eq(nil) }
119
+ end
120
+
121
+ describe '#bytes' do
122
+ subject { super().bytes }
123
+ it { is_expected.to eq(nil) }
124
+ end
125
+
126
+ describe '#toc' do
127
+ subject { super().toc }
128
+ it { is_expected.to eq(nil) }
129
+ end
130
+
131
+ describe '#quality' do
132
+ subject { super().quality }
133
+ it { is_expected.to eq(85) }
134
+ end
55
135
  end
56
136
 
57
137
  describe "with all four" do
@@ -67,9 +147,24 @@ describe Mp3file::XingHeader do
67
147
  Mp3file::XingHeader.new(StringIO.new(str))
68
148
  end
69
149
 
70
- its(:frames) { should == 4977792 }
71
- its(:bytes) { should == 1866672 }
72
- its(:toc) { should == [ 0 ] * 100 }
73
- its(:quality) { should == 85 }
150
+ describe '#frames' do
151
+ subject { super().frames }
152
+ it { is_expected.to eq(4977792) }
153
+ end
154
+
155
+ describe '#bytes' do
156
+ subject { super().bytes }
157
+ it { is_expected.to eq(1866672) }
158
+ end
159
+
160
+ describe '#toc' do
161
+ subject { super().toc }
162
+ it { is_expected.to eq([ 0 ] * 100) }
163
+ end
164
+
165
+ describe '#quality' do
166
+ subject { super().quality }
167
+ it { is_expected.to eq(85) }
168
+ end
74
169
  end
75
170
  end