test/helper.rb in airbrake-3.1.11 vs test/helper.rb in airbrake-3.1.12
- old
+ new
@@ -3,11 +3,10 @@
$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
require 'thread'
-require 'shoulda'
require 'mocha'
require 'abstract_controller'
require 'action_controller'
require 'action_dispatch'
@@ -22,10 +21,13 @@
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
@@ -45,79 +47,78 @@
def call(env)
@stack.call(env)
end
end
-class ActionDispatch::IntegrationTest < ActiveSupport::TestCase
- setup do
- @routes = SharedTestRoutes
- end
-end
-
-class ActionController::IntegrationTest < ActiveSupport::TestCase
- def self.build_app(routes = nil)
- RoutedRackApp.new(routes || ActionDispatch::Routing::RouteSet.new) do |middleware|
- middleware.use "ActionDispatch::Callbacks"
- middleware.use "ActionDispatch::ParamsParser"
- middleware.use "ActionDispatch::Cookies"
- middleware.use "ActionDispatch::Flash"
- middleware.use "ActionDispatch::Head"
- yield(middleware) if block_given?
+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
- end
- self.app = build_app
+ self.app = build_app
- # 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
+ # 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 dispatch(controller, action, env)
- [200, {'Content-Type' => 'text/html'}, ["#{controller}##{action}"]]
+ 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
- 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) }
- 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
- 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
+ def with_autoload_path(path)
+ path = File.join(File.dirname(__FILE__), "fixtures", path)
+ if ActiveSupport::Dependencies.autoload_paths.include?(path)
yield
- ensure
- ActiveSupport::Dependencies.autoload_paths.reject! {|p| p == path}
- ActiveSupport::Dependencies.clear
+ else
+ begin
+ ActiveSupport::Dependencies.autoload_paths << path
+ yield
+ ensure
+ ActiveSupport::Dependencies.autoload_paths.reject! {|p| p == path}
+ ActiveSupport::Dependencies.clear
+ end
end
end
end
end
+
+class ActionDispatch::IntegrationTest < ActiveSupport::TestCase
+ setup do
+ @routes = SharedTestRoutes
+ end
+end
+
+
module ActionController
class Base
include ActionController::Testing
end