Permalink
Browse files

moving the start/stop ping checks and informational messages out of r…

…ake tasks and into RabbitMQ helper class
  • Loading branch information...
rick committed Nov 26, 2008
1 parent 3fe5b7e commit de654c06cc83bc6c6d3fcd87f37e77c2b7cc128b
Showing with 84 additions and 84 deletions.
  1. +68 −68 spec/rake/rabbitmq.rake_spec.rb
  2. +16 −16 tasks/rabbitmq.rake
@@ -189,20 +189,42 @@
it 'should not allow arguments' do
lambda { RabbitMQ.stop(:foo) }.should raise_error(ArgumentError)
end
-
- it 'should configure the environment for localized running of rabbitmq' do
- mock(RabbitMQ).setup_environment
+
+ it 'should determine if the rabbitmq server is running' do
+ mock(RabbitMQ).running? { true }
RabbitMQ.stop
end
-
- it 'should stop the server from the rabbitmq sbin directory' do
- mock(Dir).chdir(File.expand_path(File.dirname(__FILE__) + '/../../run/rabbitmq/sbin/'))
- RabbitMQ.stop
+
+ describe 'when the rabbitmq server is not running' do
+ before :each do
+ stub(RabbitMQ).running? { false }
+ end
+
+ it 'should not stop the rabbitmq server' do
+ mock(RabbitMQ).system(anything).never
+ RabbitMQ.stop
+ end
end
- it 'should stop the rabbitmq server' do
- mock(RabbitMQ).system("./rabbitmqctl stop")
- RabbitMQ.stop
+ describe 'when the rabbitmq server is running' do
+ before :each do
+ stub(RabbitMQ).running? { true }
+ end
+
+ it 'should configure the environment for localized running of rabbitmq' do
+ mock(RabbitMQ).setup_environment
+ RabbitMQ.stop
+ end
+
+ it 'should stop the server from the rabbitmq sbin directory' do
+ mock(Dir).chdir(File.expand_path(File.dirname(__FILE__) + '/../../run/rabbitmq/sbin/'))
+ RabbitMQ.stop
+ end
+
+ it 'should stop the rabbitmq server' do
+ mock(RabbitMQ).system("./rabbitmqctl stop")
+ RabbitMQ.stop
+ end
end
end
@@ -221,19 +243,41 @@
lambda { RabbitMQ.start(:foo) }.should raise_error(ArgumentError)
end
- it 'should configure the environment for localized running of rabbitmq' do
- mock(RabbitMQ).setup_environment
+ it 'should determine if the rabbitmq server is running' do
+ mock(RabbitMQ).running? { true }
RabbitMQ.start
end
-
- it 'should run the server from the rabbitmq sbin directory' do
- mock(Dir).chdir(File.expand_path(File.dirname(__FILE__) + '/../../run/rabbitmq/sbin/'))
- RabbitMQ.start
+
+ describe 'when the rabbitmq server is already running' do
+ before :each do
+ stub(RabbitMQ).running? { true }
+ end
+
+ it 'should not start the rabbitmq server' do
+ mock(RabbitMQ).system(anything).never
+ RabbitMQ.start
+ end
end
-
- it 'should start the rabbitmq server' do
- mock(RabbitMQ).system("./rabbitmq-server")
- RabbitMQ.start
+
+ describe 'when the rabbitmq server is not running' do
+ before :each do
+ stub(RabbitMQ).running? { false }
+ end
+
+ it 'should configure the environment for localized running of rabbitmq' do
+ mock(RabbitMQ).setup_environment
+ RabbitMQ.start
+ end
+
+ it 'should run the server from the rabbitmq sbin directory' do
+ mock(Dir).chdir(File.expand_path(File.dirname(__FILE__) + '/../../run/rabbitmq/sbin/'))
+ RabbitMQ.start
+ end
+
+ it 'should start the rabbitmq server' do
+ mock(RabbitMQ).system("./rabbitmq-server")
+ RabbitMQ.start
+ end
end
end
@@ -258,32 +302,10 @@ def run_task
stub(RabbitMQ).stop
end
- it 'should determine if the rabbitmq server is running' do
- mock(RabbitMQ).running? { true }
+ it 'should stop the rabbitmq server' do
+ mock(RabbitMQ).stop
run_task
end
-
- describe 'when the rabbitmq server is not running' do
- before :each do
- stub(RabbitMQ).running? { false }
- end
-
- it 'should not stop the rabbitmq server' do
- mock(RabbitMQ).stop.never
- run_task
- end
- end
-
- describe 'when the rabbitmq server is running' do
- before :each do
- stub(RabbitMQ).running? { true }
- end
-
- it 'should stop the rabbitmq server' do
- mock(RabbitMQ).stop
- run_task
- end
- end
end
end
@@ -308,32 +330,10 @@ def run_task
stub(RabbitMQ).start
end
- it 'should determine if the rabbitmq server is running' do
- mock(RabbitMQ).running? { true }
+ it 'should start the rabbitmq server' do
+ mock(RabbitMQ).start
run_task
end
-
- describe 'when the rabbitmq server is already running' do
- before :each do
- stub(RabbitMQ).running? { true }
- end
-
- it 'should not start the rabbitmq server' do
- mock(RabbitMQ).start.never
- run_task
- end
- end
-
- describe 'when the rabbitmq server is not running' do
- before :each do
- stub(RabbitMQ).running? { false }
- end
-
- it 'should start the rabbitmq server' do
- mock(RabbitMQ).start
- run_task
- end
- end
end
end
end
View
@@ -48,15 +48,23 @@ class RabbitMQ
end
def start
- setup_environment
- Dir.chdir(File.expand_path(File.dirname(__FILE__) + '/../run/rabbitmq/sbin'))
- system("./rabbitmq-server")
+ if RabbitMQ.running?
+ puts "RabbitMQ server is already running."
+ else
+ setup_environment
+ Dir.chdir(File.expand_path(File.dirname(__FILE__) + '/../run/rabbitmq/sbin'))
+ system("./rabbitmq-server")
+ end
end
def stop
- setup_environment
- Dir.chdir(File.expand_path(File.dirname(__FILE__) + '/../run/rabbitmq/sbin'))
- system("./rabbitmqctl stop")
+ if RabbitMQ.running?
+ setup_environment
+ Dir.chdir(File.expand_path(File.dirname(__FILE__) + '/../run/rabbitmq/sbin'))
+ system("./rabbitmqctl stop")
+ else
+ puts "RabbitMQ server is not running."
+ end
end
end
end
@@ -66,21 +74,13 @@ namespace :rabbitmq do
task :start do
raise "RabbitMQ server is not installed -- please run 'rake install_dependencies' first." unless
RakeInstall.is_installed?('run/rabbitmq')
- if RabbitMQ.running?
- puts "RabbitMQ server is already running."
- else
- RabbitMQ.start
- end
+ RabbitMQ.start
end
desc 'stop the rabbitmq server'
task :stop do
raise "RabbitMQ server is not installed -- please run 'rake install_dependencies' first." unless
RakeInstall.is_installed?('run/rabbitmq')
- if RabbitMQ.running?
- RabbitMQ.stop
- else
- puts "RabbitMQ server is not running."
- end
+ RabbitMQ.stop
end
end

0 comments on commit de654c0

Please sign in to comment.