Sha256: f4983256aaa5d98cbe13330635d352914097a39b4fbd0204786f9387cf040f08

Contents?: true

Size: 1.75 KB

Versions: 2

Compression:

Stored size: 1.75 KB

Contents

require 'spec_helper'

describe WebTranslateIt::Safe::Archive do

  def def_config
    {
      :options => 'OPTS',
      :files   => 'apples',
      :exclude => 'oranges'
    }
  end

  def archive(id = :foo, config = def_config)
    WebTranslateIt::Safe::Archive.new(id, WebTranslateIt::Safe::Config::Node.new(nil, config))
  end

  after(:each) { WebTranslateIt::Safe::TmpFile.cleanup }

  describe :backup do
    before(:each) do
      @archive = archive
      stub(@archive).timestamp {'NOW'}
    end

    {
      :id => 'foo',
      :kind => 'archive',
      :extension => '.tar',
      :filename => 'archive-foo.NOW',
      :command => 'tar -cf - OPTS --exclude=oranges apples',
    }.each do |k, v|
      it "should set #{k} to #{v}" do
        @archive.backup.send(k).should == v
      end
    end
  end

  describe :tar_exclude_files do
    it "should return '' when no excludes" do
      archive(:foo, {}).send(:tar_exclude_files).should == ''
    end

    it 'should accept single exclude as string' do
      archive(:foo, {:exclude => 'bar'}).send(:tar_exclude_files).should == '--exclude=bar'
    end

    it 'should accept multiple exclude as array' do
      archive(:foo, {:exclude => ['foo', 'bar']}).send(:tar_exclude_files).should == '--exclude=foo --exclude=bar'
    end
  end

  describe :tar_files do
    it 'should raise RuntimeError when no files' do
      lambda {
        archive(:foo, {}).send(:tar_files)
      }.should raise_error(RuntimeError, 'missing files for tar')
    end

    it 'should accept single file as string' do
      archive(:foo, {:files => 'foo'}).send(:tar_files).should == 'foo'
    end

    it 'should accept multiple files as array' do
      archive(:foo, {:files => ['foo', 'bar']}).send(:tar_files).should == 'foo bar'
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
webtranslateit-safe-0.4.2 spec/webtranslateit/safe/archive_spec.rb
webtranslateit-safe-0.4.1 spec/webtranslateit/safe/archive_spec.rb