fix the error_highlight test
This commit is contained in:
parent
d05c008c71
commit
45ec085722
66
Internal-Sinatra-errors-now-extend-Sinatra-Error-test.patch
Normal file
66
Internal-Sinatra-errors-now-extend-Sinatra-Error-test.patch
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
From d8c35ce7bc6320e5805b106e1bec39d0b64b9306 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Jordan Owens <jkowens@gmail.com>
|
||||||
|
Date: Thu, 31 Jan 2019 22:32:45 -0500
|
||||||
|
Subject: [PATCH] Internal Sinatra errors now extend Sinatra::Error
|
||||||
|
|
||||||
|
---
|
||||||
|
test/mapped_error_test.rb | 6 +++---
|
||||||
|
test/result_test.rb | 15 +++++++++++++++
|
||||||
|
2 files changed, 18 insertions(+), 3 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/test/mapped_error_test.rb b/test/mapped_error_test.rb
|
||||||
|
index cb158a2..562e509 100644
|
||||||
|
--- a/test/mapped_error_test.rb
|
||||||
|
+++ b/test/mapped_error_test.rb
|
||||||
|
@@ -6,15 +6,15 @@ end
|
||||||
|
class FooNotFound < Sinatra::NotFound
|
||||||
|
end
|
||||||
|
|
||||||
|
-class FooSpecialError < RuntimeError
|
||||||
|
+class FooSpecialError < Sinatra::Error
|
||||||
|
def http_status; 501 end
|
||||||
|
end
|
||||||
|
|
||||||
|
-class FooStatusOutOfRangeError < RuntimeError
|
||||||
|
+class FooStatusOutOfRangeError < Sinatra::Error
|
||||||
|
def code; 4000 end
|
||||||
|
end
|
||||||
|
|
||||||
|
-class FooWithCode < RuntimeError
|
||||||
|
+class FooWithCode < Sinatra::Error
|
||||||
|
def code; 419 end
|
||||||
|
end
|
||||||
|
|
||||||
|
diff --git a/test/result_test.rb b/test/result_test.rb
|
||||||
|
index cbb7813..cc9990f 100644
|
||||||
|
--- a/test/result_test.rb
|
||||||
|
+++ b/test/result_test.rb
|
||||||
|
@@ -1,5 +1,9 @@
|
||||||
|
require File.expand_path('../helper', __FILE__)
|
||||||
|
|
||||||
|
+class ThirdPartyError < RuntimeError
|
||||||
|
+ def http_status; 400 end
|
||||||
|
+end
|
||||||
|
+
|
||||||
|
class ResultTest < Minitest::Test
|
||||||
|
it "sets response.body when result is a String" do
|
||||||
|
mock_app { get('/') { 'Hello World' } }
|
||||||
|
@@ -73,4 +77,15 @@ class ResultTest < Minitest::Test
|
||||||
|
assert_equal 205, status
|
||||||
|
assert_equal '', body
|
||||||
|
end
|
||||||
|
+
|
||||||
|
+ it "sets status to 500 when raised error is not Sinatra::Error" do
|
||||||
|
+ mock_app do
|
||||||
|
+ set :raise_errors, false
|
||||||
|
+ get('/') { raise ThirdPartyError }
|
||||||
|
+ end
|
||||||
|
+
|
||||||
|
+ get '/'
|
||||||
|
+ assert_equal 500, status
|
||||||
|
+ assert_equal '<h1>Internal Server Error</h1>', body
|
||||||
|
+ end
|
||||||
|
end
|
||||||
|
--
|
||||||
|
2.27.0
|
||||||
|
|
||||||
57
Internal-Sinatra-errors-now-extend-Sinatra-Error.patch
Normal file
57
Internal-Sinatra-errors-now-extend-Sinatra-Error.patch
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
From 084cf2ade353d3bf5f1a76aade87efd2f887bdd5 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Jordan Owens <jkowens@gmail.com>
|
||||||
|
Date: Thu, 31 Jan 2019 22:32:45 -0500
|
||||||
|
Subject: [PATCH] Internal Sinatra errors now extend Sinatra::Error
|
||||||
|
|
||||||
|
---
|
||||||
|
lib/sinatra/base.rb | 22 +++++++++++++---------
|
||||||
|
1 file changed, 13 insertions(+), 9 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb
|
||||||
|
index f5d7729..aebd025 100644
|
||||||
|
--- a/lib/sinatra/base.rb
|
||||||
|
+++ b/lib/sinatra/base.rb
|
||||||
|
@@ -233,11 +233,14 @@ module Sinatra
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
- class BadRequest < TypeError #:nodoc:
|
||||||
|
+ class Error < StandardError #:nodoc:
|
||||||
|
+ end
|
||||||
|
+
|
||||||
|
+ class BadRequest < Error #:nodoc:
|
||||||
|
def http_status; 400 end
|
||||||
|
end
|
||||||
|
|
||||||
|
- class NotFound < NameError #:nodoc:
|
||||||
|
+ class NotFound < Error #:nodoc:
|
||||||
|
def http_status; 404 end
|
||||||
|
end
|
||||||
|
|
||||||
|
@@ -1114,15 +1117,16 @@ module Sinatra
|
||||||
|
end
|
||||||
|
@env['sinatra.error'] = boom
|
||||||
|
|
||||||
|
- if boom.respond_to? :http_status
|
||||||
|
- status(boom.http_status)
|
||||||
|
- elsif settings.use_code? and boom.respond_to? :code and boom.code.between? 400, 599
|
||||||
|
- status(boom.code)
|
||||||
|
- else
|
||||||
|
- status(500)
|
||||||
|
+ http_status = if boom.kind_of? Sinatra::Error
|
||||||
|
+ if boom.respond_to? :http_status
|
||||||
|
+ boom.http_status
|
||||||
|
+ elsif settings.use_code? && boom.respond_to?(:code)
|
||||||
|
+ boom.code
|
||||||
|
+ end
|
||||||
|
end
|
||||||
|
|
||||||
|
- status(500) unless status.between? 400, 599
|
||||||
|
+ http_status = 500 unless http_status && http_status.between?(400, 599)
|
||||||
|
+ status(http_status)
|
||||||
|
|
||||||
|
boom_message = boom.message if boom.message && boom.message != boom.class.name
|
||||||
|
if server_error?
|
||||||
|
--
|
||||||
|
2.27.0
|
||||||
|
|
||||||
@ -3,7 +3,7 @@
|
|||||||
Summary: Ruby-based web application framework
|
Summary: Ruby-based web application framework
|
||||||
Name: rubygem-%{gem_name}
|
Name: rubygem-%{gem_name}
|
||||||
Version: 2.0.8.1
|
Version: 2.0.8.1
|
||||||
Release: 1
|
Release: 2
|
||||||
License: MIT
|
License: MIT
|
||||||
URL: http://www.sinatrarb.com/
|
URL: http://www.sinatrarb.com/
|
||||||
Source0: https://rubygems.org/gems/%{gem_name}-%{version}.gem
|
Source0: https://rubygems.org/gems/%{gem_name}-%{version}.gem
|
||||||
@ -13,6 +13,8 @@ Source1: %{gem_name}-%{version}-test.tar.gz
|
|||||||
# Fix test failure due to Rack 2.2.2 incompatibility.
|
# Fix test failure due to Rack 2.2.2 incompatibility.
|
||||||
# https://github.com/sinatra/sinatra/pull/1605
|
# https://github.com/sinatra/sinatra/pull/1605
|
||||||
Patch0: rubygem-sinatra-2.0.8.1-Fix-failing-tests.patch
|
Patch0: rubygem-sinatra-2.0.8.1-Fix-failing-tests.patch
|
||||||
|
Patch1: Internal-Sinatra-errors-now-extend-Sinatra-Error-test.patch
|
||||||
|
Patch2: Internal-Sinatra-errors-now-extend-Sinatra-Error.patch
|
||||||
BuildRequires: rubygems-devel ruby(release) ruby >= 2.2.0
|
BuildRequires: rubygems-devel ruby(release) ruby >= 2.2.0
|
||||||
%if ! 0%{?bootstrap}
|
%if ! 0%{?bootstrap}
|
||||||
BuildRequires: rubygem(rack) >= 2.0 rubygem(rack-protection) = %{version} rubygem(tilt)
|
BuildRequires: rubygem(rack) >= 2.0 rubygem(rack-protection) = %{version} rubygem(tilt)
|
||||||
@ -37,8 +39,11 @@ This package contains documentation for %{name}.
|
|||||||
|
|
||||||
pushd %{_builddir}
|
pushd %{_builddir}
|
||||||
%patch0 -p1
|
%patch0 -p1
|
||||||
|
%patch1 -p1
|
||||||
popd
|
popd
|
||||||
|
|
||||||
|
%patch2 -p1
|
||||||
|
|
||||||
%build
|
%build
|
||||||
gem build ../%{gem_name}-%{version}.gemspec
|
gem build ../%{gem_name}-%{version}.gemspec
|
||||||
%gem_install
|
%gem_install
|
||||||
@ -82,6 +87,9 @@ popd
|
|||||||
%{gem_instdir}/examples
|
%{gem_instdir}/examples
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Tue Jan 17 2023 wulei <wulei80@h-partners.com> - 1:2.0.8.1-2
|
||||||
|
- fix the error_highlight test
|
||||||
|
|
||||||
* Thu Feb 24 2022 liyanan <liyanan32@huawei.com> - 2.0.8.1-1
|
* Thu Feb 24 2022 liyanan <liyanan32@huawei.com> - 2.0.8.1-1
|
||||||
- update to 2.0.8.1
|
- update to 2.0.8.1
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user