Skip to content

Commit

Permalink
Update specs to handle changes to Rack::Lint in rack main branch
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jeremyevans committed Jun 4, 2024
1 parent a0f10b4 commit 8744302
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 27 deletions.
6 changes: 4 additions & 2 deletions spec/matchers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions spec/plugin/common_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/plugin/early_hints_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
it "allows sending early hints to rack.early_hints" do
queue = []
app(:early_hints) do |r|
send_early_hints('Link'=>'</foo.js>; rel=preload; as=script')
send_early_hints('link'=>'</foo.js>; rel=preload; as=script')
queue << 'OK'
'OK'
end
Expand All @@ -14,6 +14,6 @@

queue = []
body('rack.early_hints'=>proc{|h| queue << h}).must_equal 'OK'
queue.must_equal [{'Link'=>'</foo.js>; rel=preload; as=script'}, 'OK']
queue.must_equal [{'link'=>'</foo.js>; rel=preload; as=script'}, 'OK']
end
end
6 changes: 4 additions & 2 deletions spec/plugin/hash_routes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions spec/plugin/placeholder_string_matchers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions spec/plugin/relative_path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/plugin/run_append_slash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down
11 changes: 10 additions & 1 deletion spec/plugin/run_require_slash_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion spec/plugin/type_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8744302

Please sign in to comment.