lib/honeybadger/cli/helpers.rb in honeybadger-2.0.0.beta.9 vs lib/honeybadger/cli/helpers.rb in honeybadger-2.0.0.beta.10

- old
+ new

@@ -36,16 +36,11 @@ def load_rails_env(opts = {}) return false unless rails?(opts) puts('Loading Rails environment') if opts[:verbose] - begin - require File.expand_path('config/environment') - rescue LoadError - say('Error: could not load Rails environment. Please ensure you run this command from your project root.', :red) - exit(1) - end + ::Rails.application.require_environment! true end def rails_framework_opts @@ -121,30 +116,40 @@ say('Error: No ApplicationController found.', :red) return false end say('Setting up the Controller.') - ::ApplicationController.class_eval do + eval(<<-CONTROLLER) + class Honeybadger::TestController < ApplicationController # This is to bypass any filters that may prevent access to the action. prepend_before_filter :test_honeybadger + def test_honeybadger - puts "Raising '#{exception_class.name}' to simulate application failure." - raise exception_class.new, 'Testing honeybadger via "rake honeybadger:test". If you can see this, it works.' + puts "Raising '#{test_exception_class.name}' to simulate application failure." + raise #{test_exception_class}.new, 'Testing honeybadger via "honeybadger testhoneybadger test", it works.' end # Ensure we actually have an action to go to. def verify; end - - def exception_class - exception_name = ENV['EXCEPTION'] || 'HoneybadgerTestingException' - Object.const_get(exception_name) - rescue - Object.const_set(exception_name, Class.new(Exception)) - end end + CONTROLLER - ::Rails.application.routes.draw do - match 'verify' => 'application#verify', :as => 'verify', :via => :get + ::Rails.application.routes.tap do |r| + # RouteSet#disable_clear_and_finalize prevents existing routes from + # being cleared. We'll set it back to the original value when we're + # done so not to mess with Rails state. + d = r.disable_clear_and_finalize + begin + r.disable_clear_and_finalize = true + r.clear! + ::Rails.application.routes_reloader.paths.each{ |path| load(path) } + r.draw do + match 'verify' => 'honeybadger/test#verify', :as => 'verify', :via => :get + end + ::ActiveSupport.on_load(:action_controller) { r.finalize! } + ensure + r.disable_clear_and_finalize = d + end end say('Processing request.') ssl = defined?(::Rails.configuration.force_ssl) && ::Rails.configuration.force_ssl