diff --git a/features/rake.feature b/features/rake.feature index a5c7aba30..47c53b496 100644 --- a/features/rake.feature +++ b/features/rake.feature @@ -6,6 +6,10 @@ Feature: Use the Gem to catch errors in a Rake application When I run rake with airbrake Then Airbrake should catch the exception + Scenario: Falling back to default handler before Airbrake is configured + When I run rake with airbrake not yet configured + Then Airbrake should not catch the exception + Scenario: Disabling Rake exception catcher When I run rake with airbrake disabled Then Airbrake should not catch the exception diff --git a/features/support/rake/Rakefile b/features/support/rake/Rakefile index 41e0ce608..99c6c5620 100644 --- a/features/support/rake/Rakefile +++ b/features/support/rake/Rakefile @@ -36,6 +36,13 @@ task :airbrake_autodetect_not_from_terminal do raise_exception end +task :airbrake_not_yet_configured do + Airbrake.configuration.rescue_rake_exceptions = true + stub_tty_output(true) + stub_empty_sender + raise_exception +end + module Airbrake def self.notify(*args) # TODO if you need to check more params, you'll have to use json.dump or something @@ -43,6 +50,10 @@ module Airbrake end end +def stub_empty_sender + Airbrake.sender = nil +end + def stub_tty_output(value) Rake.application.instance_eval do @tty_output_stub = value diff --git a/lib/airbrake/rake_handler.rb b/lib/airbrake/rake_handler.rb index 560c80820..2bfc33b97 100644 --- a/lib/airbrake/rake_handler.rb +++ b/lib/airbrake/rake_handler.rb @@ -9,7 +9,7 @@ def self.included(klass) end def display_error_message_with_airbrake(ex) - if Airbrake.configuration && + if Airbrake.sender && Airbrake.configuration && (Airbrake.configuration.rescue_rake_exceptions || (Airbrake.configuration.rescue_rake_exceptions===nil && !self.tty_output?)) diff --git a/lib/airbrake/user_informer.rb b/lib/airbrake/user_informer.rb index 7cfd961c4..e25a2eee0 100644 --- a/lib/airbrake/user_informer.rb +++ b/lib/airbrake/user_informer.rb @@ -16,6 +16,7 @@ def call(env) body.each do |chunk| new_body << chunk.gsub("", replace) end + body.close if body.respond_to?(:close) headers['Content-Length'] = new_body.sum(&:length).to_s body = new_body end