From 874430289a29350967b28fa9c88b92a5f2ec7aa2 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Tue, 4 Jun 2024 09:26:38 -0700 Subject: [PATCH] Update specs to handle changes to Rack::Lint in rack main branch Rack::Lint is more strict in the rack main branch (what will be Rack 3.1). So some additional cases must be skipped when testing in lint mode. --- spec/matchers_spec.rb | 6 ++++-- spec/plugin/common_logger_spec.rb | 13 +++++++------ spec/plugin/early_hints_spec.rb | 4 ++-- spec/plugin/hash_routes_spec.rb | 6 ++++-- spec/plugin/placeholder_string_matchers_spec.rb | 13 +++++++++---- spec/plugin/relative_path_spec.rb | 12 ++++++------ spec/plugin/run_append_slash_spec.rb | 6 +++--- spec/plugin/run_require_slash_spec.rb | 11 ++++++++++- spec/plugin/type_routing_spec.rb | 2 +- 9 files changed, 46 insertions(+), 27 deletions(-) diff --git a/spec/matchers_spec.rb b/spec/matchers_spec.rb index 389e7dc52..8ac8d4a0c 100644 --- a/spec/matchers_spec.rb +++ b/spec/matchers_spec.rb @@ -225,7 +225,7 @@ body("/u:jdoe/posts:123").must_equal 'jdoe123' status("/u:jdoe/poss:123").must_equal 404 - end + end unless ENV['LINT'] it "symbol matching" do app do |r| @@ -658,7 +658,9 @@ end end - body("/events").must_equal 'Foo' + unless_lint do + body("/events").must_equal 'Foo' + end body("/events/").must_equal 'Hooray' status("/events/foo").must_equal 404 end diff --git a/spec/plugin/common_logger_spec.rb b/spec/plugin/common_logger_spec.rb index 7bdf048ee..cf067dab6 100644 --- a/spec/plugin/common_logger_spec.rb +++ b/spec/plugin/common_logger_spec.rb @@ -16,12 +16,6 @@ def cl_app(&block) @logger.rewind @logger.read.must_match(/\A- - - \[\d\d\/[A-Z][a-z]{2}\/\d\d\d\d:\d\d:\d\d:\d\d [-+]\d\d\d\d\] "GET \/ HTTP\/1.0" 200 1 0.\d\d\d\d\n\z/) - @logger.rewind - @logger.truncate(0) - body('', 'HTTP_X_FORWARDED_FOR'=>'1.1.1.1', 'REMOTE_USER'=>'je', 'REQUEST_METHOD'=>'POST', 'QUERY_STRING'=>'', "HTTP_VERSION"=>'HTTP/1.1').must_equal '' - @logger.rewind - @logger.read.must_match(/\A1\.1\.1\.1 - je \[\d\d\/[A-Z][a-z]{2}\/\d\d\d\d:\d\d:\d\d:\d\d [-+]\d\d\d\d\] "POST HTTP\/1.1" 200 - 0.\d\d\d\d\n\z/) - @logger.rewind @logger.truncate(0) body('/b', 'REMOTE_ADDR'=>'1.1.1.2', 'QUERY_STRING'=>'foo=bar', "HTTP_VERSION"=>'HTTP/1.0').must_equal '/b' @@ -42,6 +36,13 @@ def cl_app(&block) @logger.read.must_match(/\A- - - \[\d\d\/[A-Z][a-z]{2}\/\d\d\d\d:\d\d:\d\d:\d\d [-+]\d\d\d\d\] "GET \/ HTTP\/1.0" 200 1 0.\d\d\d\d\n\z/) end + it 'handles empty PATH_INFO' do + cl_app(&:path_info) + body('', 'HTTP_X_FORWARDED_FOR'=>'1.1.1.1', 'REMOTE_USER'=>'je', 'REQUEST_METHOD'=>'POST', 'QUERY_STRING'=>'', "HTTP_VERSION"=>'HTTP/1.1').must_equal '' + @logger.rewind + @logger.read.must_match(/\A1\.1\.1\.1 - je \[\d\d\/[A-Z][a-z]{2}\/\d\d\d\d:\d\d:\d\d:\d\d [-+]\d\d\d\d\] "POST HTTP\/1.1" 200 - 0.\d\d\d\d\n\z/) + end unless ENV['LINT'] + it 'skips timer information if not available' do cl_app do |r| @_request_timer = nil diff --git a/spec/plugin/early_hints_spec.rb b/spec/plugin/early_hints_spec.rb index f61f4d098..1a5e088db 100644 --- a/spec/plugin/early_hints_spec.rb +++ b/spec/plugin/early_hints_spec.rb @@ -4,7 +4,7 @@ it "allows sending early hints to rack.early_hints" do queue = [] app(:early_hints) do |r| - send_early_hints('Link'=>'; rel=preload; as=script') + send_early_hints('link'=>'; rel=preload; as=script') queue << 'OK' 'OK' end @@ -14,6 +14,6 @@ queue = [] body('rack.early_hints'=>proc{|h| queue << h}).must_equal 'OK' - queue.must_equal [{'Link'=>'; rel=preload; as=script'}, 'OK'] + queue.must_equal [{'link'=>'; rel=preload; as=script'}, 'OK'] end end diff --git a/spec/plugin/hash_routes_spec.rb b/spec/plugin/hash_routes_spec.rb index cef60bc85..41224048d 100644 --- a/spec/plugin/hash_routes_spec.rb +++ b/spec/plugin/hash_routes_spec.rb @@ -200,8 +200,10 @@ end end - body('').must_equal 'dg' - body('', 'REQUEST_METHOD'=>'POST').must_equal '' + unless_lint do + body('').must_equal 'dg' + body('', 'REQUEST_METHOD'=>'POST').must_equal '' + end body('/').must_equal 'n' end end diff --git a/spec/plugin/placeholder_string_matchers_spec.rb b/spec/plugin/placeholder_string_matchers_spec.rb index 84f2ef8e5..67194d7a4 100644 --- a/spec/plugin/placeholder_string_matchers_spec.rb +++ b/spec/plugin/placeholder_string_matchers_spec.rb @@ -40,13 +40,18 @@ end it "should handle colons by themselves" do - app(:placeholder_string_matchers) do |r| - r.on "u/:/:uid/posts/::id" do |uid, id| - uid + id + app(:bare) do + plugin :placeholder_string_matchers + plugin :unescape_path + + route do |r| + r.on "u/:/:uid/posts/::id" do |uid, id| + uid + id + end end end - body("/u/:/jdoe/posts/:123").must_equal 'jdoe123' + body("/u/%3A/jdoe/posts/%3A123").must_equal 'jdoe123' status("/u/a/jdoe/post/b123").must_equal 404 end diff --git a/spec/plugin/relative_path_spec.rb b/spec/plugin/relative_path_spec.rb index 5f7fc18a0..930b9ef8c 100644 --- a/spec/plugin/relative_path_spec.rb +++ b/spec/plugin/relative_path_spec.rb @@ -12,9 +12,9 @@ body('/a/b').must_equal '../a' body('/a/b/c').must_equal '../../a' body('/a/b/c', 'SCRIPT_NAME'=>'/d').must_equal '../../../a' - body('', 'SCRIPT_NAME'=>'/d').must_equal './a' - body('', 'SCRIPT_NAME'=>'').must_equal '/a' unless_lint do + body('', 'SCRIPT_NAME'=>'/d').must_equal './a' + body('', 'SCRIPT_NAME'=>'').must_equal '/a' body('a', 'SCRIPT_NAME'=>'').must_equal '/a' body('/', 'SCRIPT_NAME'=>'d').must_equal '/a' end @@ -31,9 +31,9 @@ body('/a/b').must_equal '../a' body('/a/b/c').must_equal '../../a' body('/a/b/c', 'SCRIPT_NAME'=>'/d').must_equal '../../../a' - body('', 'SCRIPT_NAME'=>'/d').must_equal './a' - body('', 'SCRIPT_NAME'=>'').must_equal '/a' unless_lint do + body('', 'SCRIPT_NAME'=>'/d').must_equal './a' + body('', 'SCRIPT_NAME'=>'').must_equal '/a' body('a', 'SCRIPT_NAME'=>'').must_equal '/a' body('/', 'SCRIPT_NAME'=>'d').must_equal '/a' end @@ -50,9 +50,9 @@ body('/a/b').must_equal '../a' body('/a/b/c').must_equal '../../a' body('/a/b/c', 'SCRIPT_NAME'=>'/d').must_equal '../../../a' - body('', 'SCRIPT_NAME'=>'/d').must_equal './a' - body('', 'SCRIPT_NAME'=>'').must_equal '/a' unless_lint do + body('', 'SCRIPT_NAME'=>'/d').must_equal './a' + body('', 'SCRIPT_NAME'=>'').must_equal '/a' body('a', 'SCRIPT_NAME'=>'').must_equal '/a' body('/', 'SCRIPT_NAME'=>'d').must_equal '/a' end diff --git a/spec/plugin/run_append_slash_spec.rb b/spec/plugin/run_append_slash_spec.rb index 05aa4c42f..47d7b7417 100644 --- a/spec/plugin/run_append_slash_spec.rb +++ b/spec/plugin/run_append_slash_spec.rb @@ -39,8 +39,7 @@ end end - it "internally appends a missing trailing slash to #run sub apps" do - # Without append slash + it "without plugin does not append a missing trailing slash to #run sub apps" do body.must_equal 'root' status('/sub').must_equal 404 body('/sub/').must_equal 'sub-root' @@ -49,8 +48,9 @@ body('/sub/bar/').must_equal 'sub-bar-root' body('/sub/bar/baz').must_equal 'sub-bar-baz' status('/sub/bar/baz/').must_equal 404 + end unless ENV['LINT'] - # With append slash + it "internally appends a missing trailing slash to #run sub apps" do app.plugin :run_append_slash body('/sub').must_equal 'sub-root' body('/sub/').must_equal 'sub-root' diff --git a/spec/plugin/run_require_slash_spec.rb b/spec/plugin/run_require_slash_spec.rb index b80430d58..a267c4ecb 100644 --- a/spec/plugin/run_require_slash_spec.rb +++ b/spec/plugin/run_require_slash_spec.rb @@ -1,7 +1,7 @@ require_relative "../spec_helper" describe "run_require_slash plugin" do - it "only dispatches to application " do + before do sub = app do |r| "sub-#{r.remaining_path}" end @@ -22,9 +22,18 @@ end end + end + + it "dispatches to application for empty PATH_INFO" do body("/a/b").must_equal 'sub-' body("/a/b/").must_equal 'sub-' + end unless ENV['LINT'] + + it "dispatches to application for PATH_INFO starting with /" do body("/a/b//").must_equal 'sub-/' + end + + it "does not dispatch to application for PATH_INFO not starting with /" do body("/a/b/1").must_equal 'b-1' end end diff --git a/spec/plugin/type_routing_spec.rb b/spec/plugin/type_routing_spec.rb index 435bdebaa..d1a19bfb8 100644 --- a/spec/plugin/type_routing_spec.rb +++ b/spec/plugin/type_routing_spec.rb @@ -103,8 +103,8 @@ end end - body('/subpath').must_equal 'a' unless_lint do + body('/subpath').must_equal 'a' body('/subpath.html').must_equal 'a' body('/subpath.json').must_equal '{b:1}' end