2011-01-04 16:54:01 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'apache/rake/support'
|
|
|
|
|
|
|
|
describe Apache::Rake::Support do
|
|
|
|
include Apache::Rake::Support
|
|
|
|
|
|
|
|
let(:source) { '/source' }
|
|
|
|
let(:destination) { '/destination/available' }
|
|
|
|
let(:symlink) { '/destination/enabled' }
|
|
|
|
|
2011-01-04 21:58:16 +00:00
|
|
|
describe 'config_paths!' do
|
|
|
|
before {
|
|
|
|
@config = {
|
|
|
|
:source => 'cats',
|
|
|
|
:destination => 'dogs',
|
|
|
|
:symlink => 'cows'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
subject { config_paths!; @config }
|
|
|
|
|
|
|
|
its([:source_path]) { should == File.expand_path('cats') }
|
|
|
|
its([:destination_path]) { should == File.expand_path('dogs') }
|
|
|
|
its([:symlink_path]) { should == File.expand_path('cows') }
|
|
|
|
end
|
|
|
|
|
2011-01-04 16:54:01 +00:00
|
|
|
describe 'symlink_configs!' do
|
|
|
|
before {
|
|
|
|
@config = {
|
|
|
|
:source_path => source,
|
|
|
|
:destination_path => destination,
|
|
|
|
:symlink_path => symlink
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
subject { symlink_configs! }
|
|
|
|
|
|
|
|
context 'source does not exist' do
|
|
|
|
before { File.expects(:directory?).with(destination).returns(false) }
|
|
|
|
|
|
|
|
it { expect { subject }.to raise_error(Errno::ENOENT) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'source does exist' do
|
|
|
|
before {
|
|
|
|
File.expects(:directory?).with(destination).returns(true)
|
|
|
|
FileUtils.expects(:rm_rf).with(symlink)
|
|
|
|
FileUtils.expects(:mkdir_p).with(symlink)
|
|
|
|
Dir.expects(:[]).with(File.join(destination, '**/*')).returns(dir_return)
|
|
|
|
}
|
|
|
|
|
|
|
|
context 'with no configs' do
|
|
|
|
let(:dir_return) { [] }
|
|
|
|
|
|
|
|
before { FileUtils.expects(:ln_sf).never }
|
|
|
|
|
|
|
|
it { subject }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with one config' do
|
|
|
|
let(:filename) { File.join(destination, 'dogs/cats') }
|
|
|
|
let(:dir_return) { [ filename ] }
|
|
|
|
|
2011-01-04 21:58:16 +00:00
|
|
|
before { File.expects(:file?).with(filename).returns(is_file_result) }
|
2011-01-04 16:54:01 +00:00
|
|
|
|
2011-01-04 21:58:16 +00:00
|
|
|
context 'is a directory' do
|
|
|
|
let(:is_file_result) { false }
|
2011-01-04 16:54:01 +00:00
|
|
|
|
|
|
|
it { subject }
|
|
|
|
end
|
|
|
|
|
2011-01-04 21:58:16 +00:00
|
|
|
context 'is a file' do
|
|
|
|
let(:is_file_result) { true }
|
2011-01-04 16:54:01 +00:00
|
|
|
|
2011-01-04 21:58:16 +00:00
|
|
|
before { File.expects(:read).with(filename).returns(read_result) }
|
2011-01-04 16:54:01 +00:00
|
|
|
|
2011-01-04 21:58:16 +00:00
|
|
|
context 'config should not be symlinked' do
|
|
|
|
let(:read_result) { ['# disabled'] }
|
|
|
|
|
|
|
|
before { FileUtils.expects(:ln_sf).never }
|
|
|
|
|
|
|
|
it { subject }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'config should be symlinked' do
|
|
|
|
let(:read_result) { ['# whatever'] }
|
|
|
|
|
|
|
|
before {
|
|
|
|
FileUtils.expects(:mkdir_p).with(File.join(symlink, 'dogs'))
|
|
|
|
FileUtils.expects(:ln_sf).with(filename, filename.gsub(destination, symlink))
|
|
|
|
}
|
|
|
|
|
|
|
|
it { subject }
|
|
|
|
end
|
2011-01-04 16:54:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|