Permalink
Browse files

report to user lack of support for DJ < 1.8.5

  • Loading branch information...
1 parent e0229ce commit 53d7a3e933d15cc23253e6e354f79797bfa6e3ea @jjb committed Apr 29, 2012
Showing with 51 additions and 28 deletions.
  1. +13 −7 lib/exceptional/integration/dj.rb
  2. +38 −21 spec/dj_integration_spec.rb
@@ -1,9 +1,15 @@
-class Delayed::Worker
- def handle_failed_job_with_exceptional(job, e)
- Exceptional.handle(e, "Delayed::Worker \"#{self.name}\" died")
- handle_failed_job_without_exceptional(job, e)
- Exceptional.context.clear!
+if Delayed::Worker.method_defined? :handle_failed_job
+ class Delayed::Worker
+ def handle_failed_job_with_exceptional(job, e)
+ Exceptional.handle(e, "Delayed::Worker \"#{self.name}\" died")
+ handle_failed_job_without_exceptional(job, e)
+ Exceptional.context.clear!
+ end
+ alias_method_chain :handle_failed_job, :exceptional
+ Exceptional.logger.info "DJ integration enabled"
end
- alias_method_chain :handle_failed_job, :exceptional
- Exceptional.logger.info "DJ integration enabled"
+else
+ message = "\n\n\nThe Exceptional gem does not support Delayed Job 1.8.4 or earlier.\n\n\n"
+ STDERR.puts(message)
+ Exceptional.logger.error(message)
end
@@ -1,34 +1,51 @@
require File.dirname(__FILE__) + '/spec_helper'
-module Delayed
- class Worker
- def handle_failed_job(job, exception)
- # do nothing for now
- end
- def name
- "My worker"
+
+describe "Delayed Job integration for DJ < 1.8.5" do
+ before do
+ module Delayed
+ class Worker
+ end
end
end
+ it "should report the lack of support to STDERR" do
+ STDERR.should_receive(:puts).with("\n\n\nThe Exceptional gem does not support Delayed Job 1.8.4 or earlier.\n\n\n")
+ load File.join(File.dirname(__FILE__), '..', 'lib', 'exceptional', 'integration', 'dj.rb')
+ end
+ it "should report the lack of support to Exceptional.logger" do
+ STDERR.stub(:puts)
+ Exceptional.logger.should_receive(:error).with("\n\n\nThe Exceptional gem does not support Delayed Job 1.8.4 or earlier.\n\n\n")
+ load File.join(File.dirname(__FILE__), '..', 'lib', 'exceptional', 'integration', 'dj.rb')
+ end
end
-require File.join(File.dirname(__FILE__), '..', 'lib', 'exceptional', 'integration', 'dj')
-
-describe Delayed::Worker do
+describe 'Delayed Job integration' do
before :each do
+ module Delayed
+ class Worker
+ def handle_failed_job(job, exception); end
+ def name; "My worker"; end
+ end
+ end
+ load File.join(File.dirname(__FILE__), '..', 'lib', 'exceptional', 'integration', 'dj.rb')
@worker = Delayed::Worker.new
@exception = StandardError.new
@job = "dummy"
end
- it "should handle exceptions with Exceptional" do
- Exceptional.should_receive(:handle).with(@exception, 'Delayed::Worker "My worker" died')
- @worker.handle_failed_job(@job, @exception)
- end
- it "should clear context" do
- Exceptional.should_receive(:clear!)
- @worker.handle_failed_job(@job, @exception)
- end
- it "should invoke the original handle_failed_job" do
- @worker.should_receive(:handle_failed_job_without_exceptional).with(@job, @exception)
- @worker.handle_failed_job(@job, @exception)
+ describe "For Delayed Job > 1.8.5" do
+ before(:each) do
+ end
+ it "should handle exceptions with Exceptional" do
+ Exceptional.should_receive(:handle).with(@exception, 'Delayed::Worker "My worker" died')
+ @worker.handle_failed_job(@job, @exception)
+ end
+ it "should clear context" do
+ Exceptional.should_receive(:clear!)
+ @worker.handle_failed_job(@job, @exception)
+ end
+ it "should invoke the original handle_failed_job" do
+ @worker.should_receive(:handle_failed_job_without_exceptional).with(@job, @exception)
+ @worker.handle_failed_job(@job, @exception)
+ end
end
end

0 comments on commit 53d7a3e

Please sign in to comment.