spec/compressor/gzip_spec.rb in backup-3.0.20 vs spec/compressor/gzip_spec.rb in backup-3.0.21

- old
+ new

@@ -3,56 +3,81 @@ require File.expand_path('../../spec_helper.rb', __FILE__) describe Backup::Compressor::Gzip do let(:compressor) { Backup::Compressor::Gzip.new } - before do - Backup::Model.extension = 'tar' - end + describe 'setting configuration defaults' do + after { Backup::Configuration::Compressor::Gzip.clear_defaults! } - describe 'the options' do - it do - compressor.send(:best).should == [] - end + it 'uses and overrides configuration defaults' do + Backup::Configuration::Compressor::Gzip.best.should be_false + Backup::Configuration::Compressor::Gzip.fast.should be_false - it do - compressor.send(:fast).should == [] + compressor = Backup::Compressor::Gzip.new + compressor.best.should be_false + compressor.fast.should be_false + + Backup::Configuration::Compressor::Gzip.defaults do |c| + c.best = true + c.fast = true + end + Backup::Configuration::Compressor::Gzip.best.should be_true + Backup::Configuration::Compressor::Gzip.fast.should be_true + + compressor = Backup::Compressor::Gzip.new + compressor.best.should be_true + compressor.fast.should be_true + + compressor = Backup::Compressor::Gzip.new do |c| + c.best = false + end + compressor.best.should be_false + compressor.fast.should be_true + + compressor = Backup::Compressor::Gzip.new do |c| + c.fast = false + end + compressor.best.should be_true + compressor.fast.should be_false end - end + end # describe 'setting configuration defaults' - describe '#perform!' do + describe '#compress_with' do before do - [:run, :utility].each { |method| compressor.stubs(method) } + compressor.expects(:log!) + compressor.expects(:utility).with(:gzip).returns('gzip') end - it 'should perform the compression' do - compressor.expects(:utility).with(:gzip).returns(:gzip) - compressor.expects(:run).with("gzip '#{ File.join(Backup::TMP_PATH, "#{ Backup::TIME }.#{ Backup::TRIGGER }.tar") }'") - compressor.perform! + it 'should yield with the --best option' do + compressor.best = true + compressor.compress_with do |cmd, ext| + cmd.should == 'gzip --best' + ext.should == '.gz' + end end - it 'should perform the compression with the --best and --fast options' do - compressor = Backup::Compressor::Gzip.new do |c| - c.best = true - c.fast = true + it 'should yield with the --fast option' do + compressor.fast = true + compressor.compress_with do |cmd, ext| + cmd.should == 'gzip --fast' + ext.should == '.gz' end - - compressor.stubs(:utility).returns(:gzip) - compressor.expects(:run).with("gzip --best --fast '#{ File.join(Backup::TMP_PATH, "#{ Backup::TIME }.#{ Backup::TRIGGER }.tar") }'") - compressor.perform! end - it 'should set the class variable @extension (Backup::Model.extension) to .gz' do - compressor.stubs(:utility).returns(:gzip) - compressor.expects(:run) - - Backup::Model.extension.should == 'tar' - compressor.perform! - Backup::Model.extension.should == 'tar.gz' + it 'should yield with the --best and --fast options' do + compressor.best = true + compressor.fast = true + compressor.compress_with do |cmd, ext| + cmd.should == 'gzip --best --fast' + ext.should == '.gz' + end end - it 'should log' do - Backup::Logger.expects(:message).with("Backup::Compressor::Gzip started compressing the archive.") - compressor.perform! + it 'should yield with no options' do + compressor.compress_with do |cmd, ext| + cmd.should == 'gzip' + ext.should == '.gz' + end end - end + end # describe '#compress_with' + end