test/helper.rb in airbrake-3.1.12 vs test/helper.rb in airbrake-3.1.13
- old
+ new
@@ -1,150 +1,42 @@
-require 'test/unit'
-require 'rubygems'
+$VERBOSE = ENV["VERBOSE"]
-$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
-
-require 'thread'
-
-require 'mocha'
-
-require 'abstract_controller'
-require 'action_controller'
-require 'action_dispatch'
-require 'active_support/dependencies'
-require 'active_model'
-require 'active_record'
-require 'active_support/core_ext/kernel/reporting'
-
-require 'nokogiri'
-require 'rack'
-require 'bourne'
-require 'sham_rack'
-require 'json-schema'
-
-require "airbrake"
-
-require "shoulda-matchers"
-require "shoulda-context"
-
-begin require 'redgreen'; rescue LoadError; end
-
-# Show backtraces for deprecated behavior for quicker cleanup.
-ActiveSupport::Deprecation.debug = true
-
-FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
-FIXTURES = Pathname.new(FIXTURE_LOAD_PATH)
-
-SharedTestRoutes = ActionDispatch::Routing::RouteSet.new
-
-class RoutedRackApp
- attr_reader :routes
-
- def initialize(routes, &blk)
- @routes = routes
- @stack = ActionDispatch::MiddlewareStack.new(&blk).build(@routes)
+module Kernel
+ def silence_warnings
+ with_warnings(nil) { yield }
end
- def call(env)
- @stack.call(env)
+ def with_warnings(flag)
+ old_verbose, $VERBOSE = $VERBOSE, flag
+ yield
+ ensure
+ $VERBOSE = old_verbose
end
end
-unless defined?(ActionDispatch::IntegrationTest)
- class ActionController::IntegrationTest < ActiveSupport::TestCase
- def self.build_app(routes = nil)
- RoutedRackApp.new(routes || ActionDispatch::Routing::RouteSet.new) do |middleware|
- yield(middleware) if block_given?
- end
- end
+silence_warnings do
+ require 'test/unit'
+ require 'rubygems'
- self.app = build_app
+ require 'thread'
- # Stub Rails dispatcher so it does not get controller references and
- # simply return the controller#action as Rack::Body.
- class StubDispatcher < ::ActionDispatch::Routing::RouteSet::Dispatcher
- protected
- def controller_reference(controller_param)
- controller_param
- end
-
- def dispatch(controller, action, env)
- [200, {'Content-Type' => 'text/html'}, ["#{controller}##{action}"]]
- end
- end
-
- def self.stub_controllers
- old_dispatcher = ActionDispatch::Routing::RouteSet::Dispatcher
- ActionDispatch::Routing::RouteSet.module_eval { remove_const :Dispatcher }
- ActionDispatch::Routing::RouteSet.module_eval { const_set :Dispatcher, StubDispatcher }
- yield ActionDispatch::Routing::RouteSet.new
- ensure
- ActionDispatch::Routing::RouteSet.module_eval { remove_const :Dispatcher }
- ActionDispatch::Routing::RouteSet.module_eval { const_set :Dispatcher, old_dispatcher }
- end
-
- def with_routing(&block)
- temporary_routes = ActionDispatch::Routing::RouteSet.new
- old_app, self.class.app = self.class.app, self.class.build_app(temporary_routes)
- old_routes = SharedTestRoutes
- silence_warnings { Object.const_set(:SharedTestRoutes, temporary_routes) }
-
- yield temporary_routes
- ensure
- self.class.app = old_app
- silence_warnings { Object.const_set(:SharedTestRoutes, old_routes) }
- end
-
- def with_autoload_path(path)
- path = File.join(File.dirname(__FILE__), "fixtures", path)
- if ActiveSupport::Dependencies.autoload_paths.include?(path)
- yield
- else
- begin
- ActiveSupport::Dependencies.autoload_paths << path
- yield
- ensure
- ActiveSupport::Dependencies.autoload_paths.reject! {|p| p == path}
- ActiveSupport::Dependencies.clear
- end
- end
- end
- end
+ require 'mocha/setup'
+ require 'nokogiri'
+ require 'rack'
+ require 'bourne'
+ require 'sham_rack'
+ require 'json-schema'
+ require "shoulda-matchers"
+ require "shoulda-context"
+ begin require 'redgreen'; rescue LoadError; end
end
-class ActionDispatch::IntegrationTest < ActiveSupport::TestCase
- setup do
- @routes = SharedTestRoutes
- end
-end
+$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
+require "airbrake"
-module ActionController
- class Base
- include ActionController::Testing
- end
-
- Base.view_paths = FIXTURE_LOAD_PATH
-
- class TestCase
- include ActionDispatch::TestProcess
-
- setup do
- @routes = SharedTestRoutes
- end
- end
-end
-
-# This stub emulates the Railtie including the URL helpers from a Rails application
-module ActionController
- class Base
- include SharedTestRoutes.url_helpers
- end
-end
-
-
module TestMethods
def rescue_action e
raise e
end
@@ -285,31 +177,10 @@
Object.const_set(name, value)
@defined_constants << name
end
end
-# Also stolen from AS 2.3.2
-class Array
- # Wraps the object in an Array unless it's an Array. Converts the
- # object to an Array using #to_ary if it implements that.
- def self.wrap(object)
- case object
- when nil
- []
- when self
- object
- else
- if object.respond_to?(:to_ary)
- object.to_ary
- else
- [object]
- end
- end
- end
-
-end
-
class CollectingSender
attr_reader :collected
def initialize
@collected = []
@@ -320,15 +191,18 @@
end
end
class BacktracedException < Exception
attr_accessor :backtrace
+
def initialize(opts)
@backtrace = opts[:backtrace]
end
+
def set_backtrace(bt)
@backtrace = bt
end
+
def message
"Something went wrong. Did you press the red button?"
end
end