Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

specs for install_dependencies (1 pending) and install_rabbit_mq rake…

… tasks
  • Loading branch information...
commit f37adf4a04db4d778c3d912ef3768685428fcc7f 1 parent cb0c1a1
@rick authored
Showing with 170 additions and 8 deletions.
  1. +143 −0 spec/rake/dependencies.rake_spec.rb
  2. +27 −8 tasks/dependencies.rake
View
143 spec/rake/dependencies.rake_spec.rb
@@ -0,0 +1,143 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
+require 'fileutils'
+require 'rake'
+
+describe 'rake tasks to setup for automated build' do
+ before :each do
+ Rake.application = @rake = Rake::Application.new
+ load File.expand_path(File.dirname(__FILE__) + '/../../tasks/dependencies.rake')
+ end
+
+ after :each do
+ Rake.application = nil
+ end
+
+ describe 'when checking installation' do
+ it 'should allow a path argument' do
+ lambda { RakeInstall.is_installed?('foo') }.should_not raise_error(ArgumentError)
+ end
+
+ it 'should require a path argument' do
+ lambda { RakeInstall.is_installed? }.should raise_error(ArgumentError)
+ end
+
+ it 'should return true if the named path in our tree exists' do
+ RakeInstall.is_installed?(__FILE__).should be_true
+ end
+
+ it 'should return false if the named path in our tree does not exist' do
+ RakeInstall.is_installed?(__FILE__ + '-nonsensical.txt').should be_false
+ end
+
+ it 'should identify installed directories' do
+ RakeInstall.is_installed?(File.dirname(__FILE__)).should be_true
+ end
+ end
+
+ describe 'when unpacking a tarball' do
+ before :each do
+ stub(Dir).chdir(anything)
+ stub(RakeInstall).system(anything)
+ end
+
+ it 'should allow a tarball path argument' do
+ lambda { RakeInstall.unpack_tarball('/foo') }.should_not raise_error(ArgumentError)
+ end
+
+ it 'should require a tarball path argument' do
+ lambda { RakeInstall.unpack_tarball }.should raise_error(ArgumentError)
+ end
+
+ it 'should unpack the tarball in run/' do
+ mock(Dir).chdir(File.expand_path(File.dirname(__FILE__) + '/../../run'))
+ RakeInstall.unpack_tarball('foo')
+ end
+
+ it 'should unpack the named tarball from vendor/ to run/' do
+ vendor = File.expand_path(File.dirname(__FILE__) + '/../../vendor')
+ mock(RakeInstall).system("tar xvfz #{vendor}/foo")
+ RakeInstall.unpack_tarball('foo')
+ end
+ end
+
+ describe 'when renaming a server directory' do
+ before :each do
+ stub(Dir).chdir(anything)
+ stub(RakeInstall).system(anything)
+ end
+
+ it 'should allow a path name and a destination name' do
+ lambda { RakeInstall.rename_server_path('from', 'to') }.should_not raise_error(ArgumentError)
+ end
+
+ it 'should require a path name and a destination name' do
+ lambda { RakeInstall.rename_server_path('from') }.should raise_error(ArgumentError)
+ end
+
+ it 'should make the name changes in run/' do
+ mock(Dir).chdir(File.expand_path(File.dirname(__FILE__) + '/../../run'))
+ RakeInstall.rename_server_path('from', 'to')
+ end
+
+ it 'should rename the path to the destination name' do
+ mock(RakeInstall).system("mv from to")
+ RakeInstall.rename_server_path('from', 'to')
+ end
+ end
+
+ describe 'when running install_dependencies' do
+ before :each do
+ stub(@rake["install_rabbit_mq"]).invoke
+ end
+
+ def run_task
+ @rake["install_dependencies"].invoke
+ end
+
+ it 'should install RabbitMQ' do
+ pending('learning how to set this mock expectation')
+ mock(@rake[:install_rabbit_mq]).invoke
+ @rake["install_dependencies"].invoke
+ end
+ end
+
+ describe 'when running install_rabbit_mq' do
+ def run_task
+ @rake["install_rabbit_mq"].invoke
+ end
+
+ describe 'when rabbitmq is already unpacked' do
+ before :each do
+ stub(RakeInstall).is_installed?(anything) { true }
+ end
+
+ it 'should not unpack the rabbitmq tarball from vendor' do
+ mock(RakeInstall).unpack_tarball(anything).never
+ run_task
+ end
+
+ it 'should not rename the rabbitmq install server directory' do
+ mock(FileUtils).mv(anything, anything).never
+ end
+ end
+
+ describe 'when rabbitmq is not already unpacked' do
+ before :each do
+ stub(RakeInstall).is_installed?(anything) { false }
+ stub(RakeInstall).unpack_tarball(anything)
+ stub(RakeInstall).rename_server_path(anything, anything)
+ end
+
+ it 'should unpack the vendored rabbitmq tarball into run/' do
+ mock(RakeInstall).unpack_tarball('rabbitmq-server*.tar.gz')
+ run_task
+ end
+
+ it 'should rename the rabbitmq install server directory to rabbitmq' do
+ mock(RakeInstall).rename_server_path('rabbitmq_*', 'rabbitmq')
+ run_task
+ end
+ end
+ end
+end
+
View
35 tasks/dependencies.rake
@@ -1,9 +1,30 @@
require 'fileutils'
here = File.dirname(__FILE__)
-vendor = File.expand_path(here + '/../vendor/')
run = File.expand_path(here + '/../run/')
+class RakeInstall
+ class << self
+ def is_installed?(path)
+ File.exists?(File.expand_path(File.dirname(__FILE__) + '/../' + path))
+ end
+
+ def unpack_tarball(path)
+ Dir.chdir(File.expand_path(File.dirname(__FILE__) + '/../run/'))
+ system("tar xvfz #{vendor}/#{path}")
+ end
+
+ def rename_server_path(source, target)
+ Dir.chdir(File.expand_path(File.dirname(__FILE__) + '/../run/'))
+ system("mv #{source} #{target}")
+ end
+
+ def vendor
+ File.expand_path(File.expand_path(File.dirname(__FILE__) + '/../vendor/'))
+ end
+ end
+end
+
desc 'install dependencies'
task :install_dependencies => [ :install_rabbit_mq ] do
puts "Done."
@@ -11,14 +32,12 @@ end
desc 'install the RabbitMQ message server'
task :install_rabbit_mq do
- target = File.expand_path(run+'/rabbitmq')
- if File.directory?(target)
- puts "RabbitMQ already installed in [#{target}]"
+ target = 'run/rabbitmq'
+ if RakeInstall.is_installed?('run/rabbitmq')
+ puts "RabbitMQ already installed in [#{target}]."
else
puts "installing RabbitMQ in [#{target}]..."
-
- tarball = vendor + '/rabbitmq-server*.tar.gz'
- `cd #{run}; tar xfvz #{tarball}`
- `cd #{run}; mv rabbitmq* rabbitmq`
+ RakeInstall.unpack_tarball('rabbitmq-server*.tar.gz')
+ RakeInstall.rename_server_path('rabbitmq_*', 'rabbitmq')
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.