Repository: rails/rails
File: actionpack/test/dispatch/debug_exceptions_test.rb (Ruby)

Code before:
      when "/utf8_template_error"
        begin
          eval "“fancy string”"
        rescue Exception
          raise ActionView::Template::Error.new(template)
        end
      else
        raise "puke!"
      end
    end
  end

  def self.build_app(app, *args)
    Rack::Lint.new(
      ActionDispatch::DebugExceptions.new(
        Rack::Lint.new(app), *args,
      ),
    )
  end

  Interceptor = proc { |request, exception| request.set_header("int", exception) }
  BadInterceptor = proc { |request, exception| raise "bad" }
  RoutesApp = Struct.new(:routes).new(SharedTestRoutes)
  ProductionApp  = build_app(Boomer.new(false), RoutesApp)
  DevelopmentApp = build_app(Boomer.new(true), RoutesApp)
  OpenInEditorApp = build_app(Boomer.new(true), RoutesApp)
  InterceptedApp = build_app(Boomer.new(true), RoutesApp, :default, [Interceptor])
  BadInterceptedApp = build_app(Boomer.new(true), RoutesApp, :default, [BadInterceptor])
  ApiApp = build_app(Boomer.new(true), RoutesApp, :api)

  test "skip diagnosis if not showing detailed exceptions" do
    @app = ProductionApp
    assert_raise RuntimeError do
      get "/", headers: { "action_dispatch.show_exceptions" => :all }
    end
  end

  test "skip diagnosis if not showing exceptions" do
    @app = DevelopmentApp
    assert_raise RuntimeError do
      get "/", headers: { "action_dispatch.show_exceptions" => :none }
    end
  end

  test "raise an exception on cascade pass" do
    @app = ProductionApp
    assert_raise ActionController::RoutingError do
      get "/pass", headers: { "action_dispatch.show_exceptions" => :all }
    end
  end


Review comment (suggestion):
No need for a new App, we can use the `DevelopmentApp` above.

Code after:
      when "/utf8_template_error"
        begin
          eval "“fancy string”"
        rescue Exception
          raise ActionView::Template::Error.new(template)
        end
      else
        raise "puke!"
      end
    end
  end

  def self.build_app(app, *args)
    Rack::Lint.new(
      ActionDispatch::DebugExceptions.new(
        Rack::Lint.new(app), *args,
      ),
    )
  end

  Interceptor = proc { |request, exception| request.set_header("int", exception) }
  BadInterceptor = proc { |request, exception| raise "bad" }
  RoutesApp = Struct.new(:routes).new(SharedTestRoutes)
  ProductionApp  = build_app(Boomer.new(false), RoutesApp)
  DevelopmentApp = build_app(Boomer.new(true), RoutesApp)
  InterceptedApp = build_app(Boomer.new(true), RoutesApp, :default, [Interceptor])
  BadInterceptedApp = build_app(Boomer.new(true), RoutesApp, :default, [BadInterceptor])
  ApiApp = build_app(Boomer.new(true), RoutesApp, :api)

  test "skip diagnosis if not showing detailed exceptions" do
    @app = ProductionApp
    assert_raise RuntimeError do
      get "/", headers: { "action_dispatch.show_exceptions" => :all }
    end
  end

  test "skip diagnosis if not showing exceptions" do
    @app = DevelopmentApp
    assert_raise RuntimeError do
      get "/", headers: { "action_dispatch.show_exceptions" => :none }
    end
  end

  test "raise an exception on cascade pass" do
    @app = ProductionApp
    assert_raise ActionController::RoutingError do
      get "/pass", headers: { "action_dispatch.show_exceptions" => :all }
    end
  end

  test "closes the response body on cascade pass" do