summary refs log tree commit
path: root/test/spec_content_type.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/spec_content_type.rb')
-rw-r--r--test/spec_content_type.rb30
1 files changed, 21 insertions, 9 deletions
diff --git a/test/spec_content_type.rb b/test/spec_content_type.rb
index 281879f3..53f1d172 100644
--- a/test/spec_content_type.rb
+++ b/test/spec_content_type.rb
@@ -1,4 +1,6 @@
-require 'minitest/autorun'
+# frozen_string_literal: true
+
+require 'minitest/global_expectations/autorun'
 require 'rack/content_type'
 require 'rack/lint'
 require 'rack/mock'
@@ -26,21 +28,31 @@ describe Rack::ContentType do
   end
 
   it "not change Content-Type if it is already set" do
-    app = lambda { |env| [200, {'Content-Type' => 'foo/bar'}, "Hello, World!"] }
+    app = lambda { |env| [200, { 'Content-Type' => 'foo/bar' }, "Hello, World!"] }
     headers = content_type(app).call(request)[1]
     headers['Content-Type'].must_equal 'foo/bar'
   end
 
   it "detect Content-Type case insensitive" do
-    app = lambda { |env| [200, {'CONTENT-Type' => 'foo/bar'}, "Hello, World!"] }
+    app = lambda { |env| [200, { 'CONTENT-Type' => 'foo/bar' }, "Hello, World!"] }
     headers = content_type(app).call(request)[1]
-    headers.to_a.select { |k,v| k.downcase == "content-type" }.
-      must_equal [["CONTENT-Type","foo/bar"]]
+    headers.to_a.select { |k, v| k.downcase == "content-type" }.
+      must_equal [["CONTENT-Type", "foo/bar"]]
+  end
+
+  [100, 204, 304].each do |code|
+    it "not set Content-Type on #{code} responses" do
+      app = lambda { |env| [code, {}, []] }
+      response = content_type(app, "text/html").call(request)
+      response[1]['Content-Type'].must_be_nil
+    end
   end
 
-  it "not set Content-Type on 304 responses" do
-    app = lambda { |env| [304, {}, []] }
-    response = content_type(app, "text/html").call(request)
-    response[1]['Content-Type'].must_equal nil
+  ['100', '204', '304'].each do |code|
+    it "not set Content-Type on #{code} responses if status is a string" do
+      app = lambda { |env| [code, {}, []] }
+      response = content_type(app, "text/html").call(request)
+      response[1]['Content-Type'].must_be_nil
+    end
   end
 end