flac2mp3 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe 'flac2mp3 command' do
4
+ before :all do
5
+ path = File.join(File.dirname(__FILE__), *%w[.. bin])
6
+ ENV['PATH'] = [path, ENV['PATH']].join(':')
7
+ end
8
+
9
+ before :each do
10
+ Flac2mp3.stubs(:convert)
11
+ end
12
+
13
+ it 'should exist' do
14
+ pending 'figuring out how to test this command'
15
+
16
+ system('flac2mp3 blah').should be_true
17
+ end
18
+
19
+ it 'should require a filename' do
20
+ pending 'figuring out how to test this command'
21
+
22
+ `flac2mp3`.should match(/usage:.+filename/i)
23
+ end
24
+
25
+ it 'should pass the filename to Flac2mp3 for conversion' do
26
+ pending 'figuring out how to test this command'
27
+
28
+ Flac2mp3.expects(:convert).with('blah')
29
+ system('flac2mp3 blah')
30
+ end
31
+ end
@@ -0,0 +1,312 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Flac2mp3 do
4
+ it 'should convert' do
5
+ Flac2mp3.should respond_to(:convert)
6
+ end
7
+
8
+ it 'should provide output filename' do
9
+ Flac2mp3.should respond_to(:output_filename)
10
+ end
11
+
12
+ it 'should provide tag mapping' do
13
+ Flac2mp3.should respond_to(:tag_mapping)
14
+ end
15
+
16
+ it 'should get FLAC tag data' do
17
+ Flac2mp3.should respond_to(:flacdata)
18
+ end
19
+
20
+ it 'should set MP3 tag data' do
21
+ Flac2mp3.should respond_to(:mp3data)
22
+ end
23
+ end
24
+
25
+ describe Flac2mp3, 'when converting' do
26
+ before :each do
27
+ Flac2mp3.stubs(:system)
28
+ Flac2mp3.stubs(:flacdata)
29
+ Flac2mp3.stubs(:mp3data)
30
+ end
31
+
32
+ it 'should require a filename' do
33
+ lambda { Flac2mp3.convert }.should raise_error(ArgumentError)
34
+ end
35
+
36
+ it 'should accept a filename' do
37
+ lambda { Flac2mp3.convert('blah.flac') }.should_not raise_error(ArgumentError)
38
+ end
39
+
40
+ it 'should check if the filename belongs to a regular file' do
41
+ filename = 'blah.flac'
42
+ FileTest.expects(:file?).with(filename).returns(true)
43
+ Flac2mp3.convert(filename)
44
+ end
45
+ end
46
+
47
+ describe Flac2mp3, 'when converting and given a filename belonging to a regular file' do
48
+ before :each do
49
+ @filename = 'blah.flac'
50
+ FileTest.stubs(:file?).with(@filename).returns(true)
51
+ @output_filename = 'blah.mp3'
52
+ Flac2mp3.stubs(:output_filename).with(@filename).returns(@output_filename)
53
+ Flac2mp3.stubs(:system)
54
+
55
+ @flacdata = {}
56
+ Flac2mp3.stubs(:flacdata).with(@filename).returns(@flacdata)
57
+ Flac2mp3.stubs(:mp3data)
58
+ end
59
+
60
+ it 'should not error' do
61
+ lambda { Flac2mp3.convert(@filename) }.should_not raise_error(TypeError)
62
+ end
63
+
64
+ it 'should extend the filename with the string extensions' do
65
+ @filename.expects(:extend).with(Flac2mp3::StringExtensions).returns(@filename)
66
+ @filename.stubs(:safequote)
67
+ Flac2mp3.convert(@filename)
68
+ end
69
+
70
+ it 'should get the output filename' do
71
+ Flac2mp3.expects(:output_filename).with(@filename).returns('outfile')
72
+ Flac2mp3.convert(@filename)
73
+ end
74
+
75
+ it 'should extend the output filename with the string extensions' do
76
+ @output_filename.expects(:extend).with(Flac2mp3::StringExtensions).returns(@output_filename)
77
+ @output_filename.stubs(:safequote)
78
+ Flac2mp3.convert(@filename)
79
+ end
80
+
81
+ it 'should use system commands to convert the FLAC to an MP3' do
82
+ @filename.stubs(:safequote).returns('-blah-flac-')
83
+ @output_filename.stubs(:safequote).returns('-blah-mp3-')
84
+ Flac2mp3.expects(:system).with("flac -c -d #{@filename.safequote} | lame --preset standard - #{@output_filename.safequote}")
85
+
86
+ Flac2mp3.convert(@filename)
87
+ end
88
+
89
+ it 'should set the MP3 tags from the FLAC data' do
90
+ Flac2mp3.expects(:mp3data).with(@output_filename, @flacdata)
91
+ Flac2mp3.convert(@filename)
92
+ end
93
+ end
94
+
95
+ describe Flac2mp3, 'when converting and given a filename not belonging to a regular file' do
96
+ before :each do
97
+ @filename = 'blah.flac'
98
+ FileTest.stubs(:file?).with(@filename).returns(false)
99
+ end
100
+
101
+ it 'should error' do
102
+ lambda { Flac2mp3.convert(@filename) }.should raise_error(TypeError)
103
+ end
104
+ end
105
+
106
+ describe Flac2mp3, 'when getting an output filename' do
107
+ it 'should require a filename' do
108
+ lambda { Flac2mp3.output_filename }.should raise_error(ArgumentError)
109
+ end
110
+
111
+ it 'should accept a filename' do
112
+ lambda { Flac2mp3.output_filename('blah.flac') }.should_not raise_error(ArgumentError)
113
+ end
114
+
115
+ it 'should convert a .flac extension to an .mp3 extension' do
116
+ Flac2mp3.output_filename('blah.flac').should == 'blah.mp3'
117
+ end
118
+
119
+ it 'should append an .mp3 extension if no .flac extension exists' do
120
+ Flac2mp3.output_filename('blah').should == 'blah.mp3'
121
+ end
122
+ end
123
+
124
+ describe Flac2mp3, 'providing a mapping of tags' do
125
+ it 'should return a hash' do
126
+ Flac2mp3.tag_mapping.should be_kind_of(Hash)
127
+ end
128
+
129
+ it "should map 'album' to 'album'" do
130
+ Flac2mp3.tag_mapping[:album].should == :album
131
+ end
132
+
133
+ it "should map 'artist' to 'artist'" do
134
+ Flac2mp3.tag_mapping[:artist].should == :artist
135
+ end
136
+
137
+ it "should map 'bpm' to 'bpm'" do
138
+ Flac2mp3.tag_mapping[:bpm].should == :bpm
139
+ end
140
+
141
+ it "should map 'comment' to 'comments'" do
142
+ Flac2mp3.tag_mapping[:comment].should == :comments
143
+ end
144
+
145
+ it "should map 'composer' to 'composer'" do
146
+ Flac2mp3.tag_mapping[:composer].should == :composer
147
+ end
148
+
149
+ it "should map 'date' to 'year'" do
150
+ Flac2mp3.tag_mapping[:date].should == :year
151
+ end
152
+
153
+ it "should map 'genre' to 'genre_s'" do
154
+ Flac2mp3.tag_mapping[:genre].should == :genre_s
155
+ end
156
+
157
+ it "should map 'title' to 'title'" do
158
+ Flac2mp3.tag_mapping[:title].should == :title
159
+ end
160
+
161
+ it "should map 'tracknumber' to 'tracknum'" do
162
+ Flac2mp3.tag_mapping[:tracknumber].should == :tracknum
163
+ end
164
+ end
165
+
166
+ describe Flac2mp3, 'when getting FLAC tag data' do
167
+ before :each do
168
+ @filename = 'blah.flac'
169
+ @tags = {}
170
+ @flacinfo = stub('flacinfo', :tags => @tags)
171
+ FlacInfo.stubs(:new).with(@filename).returns(@flacinfo)
172
+ end
173
+
174
+ it 'should require a filename' do
175
+ lambda { Flac2mp3.flacdata }.should raise_error(ArgumentError)
176
+ end
177
+
178
+ it 'should accept a filename' do
179
+ lambda { Flac2mp3.flacdata('blah.flac') }.should_not raise_error(ArgumentError)
180
+ end
181
+
182
+ it 'should create a FlacInfo object' do
183
+ FlacInfo.expects(:new).with(@filename).returns(@flacinfo)
184
+ Flac2mp3.flacdata(@filename)
185
+ end
186
+
187
+ it 'should use the FlacInfo object tags' do
188
+ @flacinfo.expects(:tags).returns(@tags)
189
+ Flac2mp3.flacdata(@filename)
190
+ end
191
+
192
+ it 'should return a hash of the tag data' do
193
+ @tags[:artist] = 'blah'
194
+ @tags[:blah] = 'boo'
195
+ @tags[:comment] = 'hey'
196
+
197
+ data = Flac2mp3.flacdata(@filename)
198
+ data[:artist].should == 'blah'
199
+ data[:blah].should == 'boo'
200
+ data[:comment].should == 'hey'
201
+ end
202
+
203
+ it 'should convert tags to symbols' do
204
+ @tags['artist'] = 'blah'
205
+ @tags['blah'] = 'boo'
206
+ @tags['comment'] = 'hey'
207
+
208
+ data = Flac2mp3.flacdata(@filename)
209
+ data[:artist].should == 'blah'
210
+ data[:blah].should == 'boo'
211
+ data[:comment].should == 'hey'
212
+
213
+ data.should_not have_key('artist')
214
+ data.should_not have_key('blah')
215
+ data.should_not have_key('comment')
216
+ end
217
+
218
+ it 'should convert tags to lowercase' do
219
+ @tags['Artist'] = 'blah'
220
+ @tags[:BLAH] = 'boo'
221
+ @tags['cOmMeNt'] = 'hey'
222
+
223
+ data = Flac2mp3.flacdata(@filename)
224
+ data[:artist].should == 'blah'
225
+ data[:blah].should == 'boo'
226
+ data[:comment].should == 'hey'
227
+
228
+ data.should_not have_key('Artist')
229
+ data.should_not have_key(:BLAH)
230
+ data.should_not have_key('cOmMeNt')
231
+ end
232
+
233
+ it 'should convert values consisting only of digits to actual numbers' do
234
+ @tags[:track] = '12'
235
+
236
+ data = Flac2mp3.flacdata(@filename)
237
+ data[:track].should == 12
238
+ end
239
+ end
240
+
241
+ describe Flac2mp3, 'when setting MP3 tag data' do
242
+ before :each do
243
+ @filename = 'blah.mp3'
244
+ @tags = {}
245
+ @mp3tags = stub('mp3info tags')
246
+ @mp3info = stub('mp3info obj', :tag => @mp3tags)
247
+ Mp3Info.stubs(:open).with(@filename).yields(@mp3info)
248
+ end
249
+
250
+ it 'should require a filename' do
251
+ lambda { Flac2mp3.mp3data }.should raise_error(ArgumentError)
252
+ end
253
+
254
+ it 'should require tag data' do
255
+ lambda { Flac2mp3.mp3data('blah.mp3') }.should raise_error(ArgumentError)
256
+ end
257
+
258
+ it 'should accept a filename and tag data' do
259
+ lambda { Flac2mp3.mp3data('blah.mp3', 'tags') }.should_not raise_error(ArgumentError)
260
+ end
261
+
262
+ it 'should require a hash of tags' do
263
+ lambda { Flac2mp3.mp3data('blah.mp3', 'blah') }.should raise_error(TypeError)
264
+ end
265
+
266
+ it 'should accept a hash of tags' do
267
+ lambda { Flac2mp3.mp3data('blah.mp3', {}) }.should_not raise_error(TypeError)
268
+ end
269
+
270
+ it 'should use an Mp3Info object' do
271
+ Mp3Info.expects(:open).with(@filename).yields(@mp3info)
272
+ Flac2mp3.mp3data(@filename, @tags)
273
+ end
274
+
275
+ it 'should set tags in the Mp3Info object' do
276
+ @tags[:album] = 'blah'
277
+ @tags[:artist] = 'boo'
278
+ @tags[:genre] = 'bang'
279
+
280
+ @mp3tags.expects(:album=).with(@tags[:album])
281
+ @mp3tags.expects(:artist=).with(@tags[:artist])
282
+ @mp3tags.expects(:genre_s=).with(@tags[:genre])
283
+
284
+ Flac2mp3.mp3data(@filename, @tags)
285
+ end
286
+
287
+ it 'should not set tags not given' do
288
+ @tags[:album] = 'blah'
289
+ @tags[:artist] = 'boo'
290
+ @tags[:genre] = 'bang'
291
+
292
+ @mp3tags.stubs(:album=)
293
+ @mp3tags.stubs(:artist=)
294
+ @mp3tags.stubs(:genre_s=)
295
+
296
+ @mp3tags.expects(:bpm=).never
297
+ @mp3tags.expects(:comments=).never
298
+ @mp3tags.expects(:year=).never
299
+
300
+ Flac2mp3.mp3data(@filename, @tags)
301
+ end
302
+
303
+ it 'should not set tags not known' do
304
+ @tags[:blah] = 'blah'
305
+ @tags[:bang] = 'bang'
306
+
307
+ @mp3tags.expects(:blah=).never
308
+ @mp3tags.expects(:bang=).never
309
+
310
+ Flac2mp3.mp3data(@filename, @tags)
311
+ end
312
+ end
@@ -0,0 +1,3 @@
1
+ --format
2
+ s
3
+ --colour
@@ -0,0 +1,24 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ # this is my favorite way to require ever
10
+ begin
11
+ require 'mocha'
12
+ rescue LoadError
13
+ require 'rubygems'
14
+ gem 'mocha'
15
+ require 'mocha'
16
+ end
17
+
18
+ Spec::Runner.configure do |config|
19
+ config.mock_with :mocha
20
+ end
21
+
22
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
23
+
24
+ require 'flac2mp3'
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe String, 'in general' do
4
+ it 'should not safequote' do
5
+ String.new.should_not respond_to(:safequote)
6
+ end
7
+ end
8
+
9
+ describe String, 'extended with string extensions' do
10
+ it 'should safequote' do
11
+ str = String.new
12
+ str.extend(Flac2mp3::StringExtensions)
13
+ str.should respond_to(:safequote)
14
+ end
15
+ end
16
+
17
+ describe String, 'safequoting' do
18
+ it 'should leave alphanumeric characters alone' do
19
+ str = 'abc_123'
20
+ str.extend(Flac2mp3::StringExtensions)
21
+ str.safequote.should == 'abc_123'
22
+ end
23
+
24
+ it 'should escape non-alphanumeric characters' do
25
+ str = %q[a-b"c 12'3]
26
+ str.extend(Flac2mp3::StringExtensions)
27
+ str.safequote.should == %q[a\-b\"c\ 12\'3]
28
+ end
29
+ end
@@ -0,0 +1,34 @@
1
+ desc 'Release the website and new gem version'
2
+ task :deploy => [:check_version, :website, :release] do
3
+ puts "Remember to create SVN tag:"
4
+ puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
5
+ "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
6
+ puts "Suggested comment:"
7
+ puts "Tagging release #{CHANGES}"
8
+ end
9
+
10
+ desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
11
+ task :local_deploy => [:website_generate, :install_gem]
12
+
13
+ task :check_version do
14
+ unless ENV['VERSION']
15
+ puts 'Must pass a VERSION=x.y.z release version'
16
+ exit
17
+ end
18
+ unless ENV['VERSION'] == VERS
19
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
20
+ exit
21
+ end
22
+ end
23
+
24
+ desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
25
+ task :install_gem_no_doc => [:clean, :package] do
26
+ sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
27
+ end
28
+
29
+ namespace :manifest do
30
+ desc 'Recreate Manifest.txt to include ALL files'
31
+ task :refresh do
32
+ `rake check_manifest | patch -p0 > Manifest.txt`
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ task :ruby_env do
2
+ RUBY_APP = if RUBY_PLATFORM =~ /java/
3
+ "jruby"
4
+ else
5
+ "ruby"
6
+ end unless defined? RUBY_APP
7
+ end