PHP 8.2.31
Preview: spec_showexceptions.rb Size: 2.01 KB
/proc/thread-self/root/opt/alt/ruby23/lib64/ruby/gems/2.3.0/gems/rack-1.6.4/test/spec_showexceptions.rb

require 'rack/showexceptions'
require 'rack/lint'
require 'rack/mock'

describe Rack::ShowExceptions do
  def show_exceptions(app)
    Rack::Lint.new Rack::ShowExceptions.new(app)
  end
  
  it "catches exceptions" do
    res = nil

    req = Rack::MockRequest.new(
      show_exceptions(
        lambda{|env| raise RuntimeError }
    ))

    lambda{
      res = req.get("/", "HTTP_ACCEPT" => "text/html")
    }.should.not.raise

    res.should.be.a.server_error
    res.status.should.equal 500

    res.should =~ /RuntimeError/
    res.should =~ /ShowExceptions/
  end

  it "responds with HTML only to requests accepting HTML" do
    res = nil

    req = Rack::MockRequest.new(
      show_exceptions(
        lambda{|env| raise RuntimeError, "It was never supposed to work" }
    ))

    [
      # Serve text/html when the client accepts text/html
      ["text/html", ["/", {"HTTP_ACCEPT" => "text/html"}]],
      ["text/html", ["/", {"HTTP_ACCEPT" => "*/*"}]],
      # Serve text/plain when the client does not accept text/html
      ["text/plain", ["/"]],
      ["text/plain", ["/", {"HTTP_ACCEPT" => "application/json"}]]
    ].each do |exmime, rargs|
      lambda{
        res = req.get(*rargs)
      }.should.not.raise

      res.should.be.a.server_error
      res.status.should.equal 500

      res.content_type.should.equal exmime

      res.body.should.include "RuntimeError"
      res.body.should.include "It was never supposed to work"

      if exmime == "text/html"
        res.body.should.include '</html>'
      else
        res.body.should.not.include '</html>'
      end
    end
  end

  it "handles exceptions without a backtrace" do
    res = nil

    req = Rack::MockRequest.new(
      show_exceptions(
        lambda{|env| raise RuntimeError, "", [] }
      )
    )

    lambda{
      res = req.get("/", "HTTP_ACCEPT" => "text/html")
    }.should.not.raise

    res.should.be.a.server_error
    res.status.should.equal 500

    res.should =~ /RuntimeError/
    res.should =~ /ShowExceptions/
    res.should =~ /unknown location/
  end
end

Directory Contents

Dirs: 7 × Files: 51

Name Size Perms Modified Actions
builder DIR
- drwxr-xr-x 2024-03-03 22:53:12
Edit Download
cgi DIR
- drwxr-xr-x 2024-03-03 22:53:12
Edit Download
multipart DIR
- drwxr-xr-x 2024-03-03 22:53:12
Edit Download
rackup DIR
- drwxr-xr-x 2024-03-03 22:53:12
Edit Download
- drwxr-xr-x 2024-03-03 22:53:12
Edit Download
static DIR
- drwxr-xr-x 2024-03-03 22:53:12
Edit Download
- drwxr-xr-x 2024-03-03 22:53:12
Edit Download
298 B lrw-r--r-- 2019-12-05 23:22:18
Edit Download
2.26 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
8.08 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
2.20 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
6.20 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
2.11 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
2.92 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
3.87 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
2.37 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
3.28 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
544 B lrw-r--r-- 2019-12-05 23:22:18
Edit Download
2.80 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
1.47 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
10.04 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
2.19 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
3.84 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
3.08 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
6.32 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
1.87 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
1.36 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
19.23 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
1.23 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
4.33 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
622 B lrw-r--r-- 2019-12-05 23:22:18
Edit Download
2.38 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
1.81 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
9.34 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
5.73 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
23.62 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
514 B lrw-r--r-- 2019-12-05 23:22:18
Edit Download
1.83 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
42.52 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
10.08 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
2.78 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
1.53 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
4.12 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
5.57 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
1.29 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
12.94 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
11.12 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
6.53 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
2.01 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
2.74 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
4.60 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
1.57 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
2.55 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
8.82 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
24.89 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
504 B lrw-r--r-- 2019-12-05 23:22:18
Edit Download
5.50 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
1.96 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).