Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ConversionObserver::Consumer#run

Set up getting a file and either converting the file and returning true or, if no file, doing nothing and returning nil.
  • Loading branch information...
commit 274c82174250a92e659a537b0b1c3e4f3df044d2 1 parent a349ff1
@ymendel authored
View
4 lib/conversion_observer.rb
@@ -1,4 +1,8 @@
module ConversionObserver
+ class << self
+ def file_to_convert
+ end
+ end
end
require 'conversion_observer/consumer'
View
9 lib/conversion_observer/consumer.rb
@@ -1,5 +1,14 @@
module ConversionObserver
class Consumer
+ def run
+ file = ConversionObserver.file_to_convert
+
+ if file
+ convert(file)
+ true
+ end
+ end
+
def convert(file)
system('flac2mp3', '--delete', file)
end
View
37 spec/consumer_spec.rb
@@ -5,17 +5,46 @@
@consumer = ConversionObserver::Consumer.new
end
- it 'should run'
+ it 'should run' do
+ @consumer.should respond_to(:run)
+ end
describe 'when running' do
- it 'should request a file to convert'
+ it 'should request a file to convert' do
+ ConversionObserver.expects(:file_to_convert)
+ @consumer.run
+ end
describe 'when there is a file to convert' do
- it 'should convert the file'
+ before :each do
+ @file = stub('file')
+ ConversionObserver.stubs(:file_to_convert).returns(@file)
+ @consumer.stubs(:convert)
+ end
+
+ it 'should convert the file' do
+ @consumer.expects(:convert).with(@file)
+ @consumer.run
+ end
+
+ it 'should return true' do
+ @consumer.run.should be(true)
+ end
end
describe 'when there is no file to convert' do
- it 'should pass'
+ before :each do
+ ConversionObserver.stubs(:file_to_convert).returns(nil)
+ end
+
+ it 'should return nil' do
+ @consumer.run.should be_nil
+ end
+
+ it 'should not convert' do
+ @consumer.expects(:convert).never
+ @consumer.run
+ end
end
end
View
3  spec/conversion_observer_spec.rb
@@ -1,4 +1,7 @@
require File.dirname(__FILE__) + '/spec_helper.rb'
describe ConversionObserver do
+ it 'should give a file to convert' do
+ ConversionObserver.should respond_to(:file_to_convert)
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.