summaryrefslogtreecommitdiff
path: root/spec/ruby/library/cgi/shared
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-20 20:18:52 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-20 20:18:52 +0000
commit1d15d5f08032acf1b7bceacbb450d617ff6e0931 (patch)
treea3785a79899302bc149e4a6e72f624ac27dc1f10 /spec/ruby/library/cgi/shared
parent75bfc6440d595bf339007f4fb280fd4d743e89c1 (diff)
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory. [Misc #13792] [ruby-core:82287] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/library/cgi/shared')
-rw-r--r--spec/ruby/library/cgi/shared/http_header.rb112
1 files changed, 112 insertions, 0 deletions
diff --git a/spec/ruby/library/cgi/shared/http_header.rb b/spec/ruby/library/cgi/shared/http_header.rb
new file mode 100644
index 0000000000..ed65b20abd
--- /dev/null
+++ b/spec/ruby/library/cgi/shared/http_header.rb
@@ -0,0 +1,112 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'cgi'
+
+describe :cgi_http_header, shared: true do
+ describe "CGI#http_header when passed no arguments" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
+
+
+ it "returns a HTTP header specifiying the Content-Type as text/html" do
+ @cgi.send(@method).should == "Content-Type: text/html\r\n\r\n"
+ end
+
+ it "includes Cookies in the @output_cookies field" do
+ @cgi.instance_variable_set(:@output_cookies, ["multiple", "cookies"])
+ @cgi.send(@method).should == "Content-Type: text/html\r\nSet-Cookie: multiple\r\nSet-Cookie: cookies\r\n\r\n"
+ end
+ end
+
+ describe "CGI#http_header when passed String" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
+
+
+ it "returns a HTTP header specifiying the Content-Type as the passed String's content" do
+ @cgi.send(@method, "text/plain").should == "Content-Type: text/plain\r\n\r\n"
+ end
+
+ it "includes Cookies in the @output_cookies field" do
+ @cgi.instance_variable_set(:@output_cookies, ["multiple", "cookies"])
+ @cgi.send(@method, "text/plain").should == "Content-Type: text/plain\r\nSet-Cookie: multiple\r\nSet-Cookie: cookies\r\n\r\n"
+ end
+ end
+
+ describe "CGI#http_header when passed Hash" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
+
+
+ it "returns a HTTP header based on the Hash's key/value pairs" do
+ header = @cgi.send(@method, "type" => "text/plain")
+ header.should == "Content-Type: text/plain\r\n\r\n"
+
+ header = @cgi.send(@method, "type" => "text/plain", "charset" => "UTF-8")
+ header.should == "Content-Type: text/plain; charset=UTF-8\r\n\r\n"
+
+ header = @cgi.send(@method, "nph" => true)
+ header.should include("HTTP/1.0 200 OK\r\n")
+ header.should include("Date: ")
+ header.should include("Server: ")
+ header.should include("Connection: close\r\n")
+ header.should include("Content-Type: text/html\r\n")
+
+ header = @cgi.send(@method, "status" => "OK")
+ header.should == "Status: 200 OK\r\nContent-Type: text/html\r\n\r\n"
+
+ header = @cgi.send(@method, "status" => "PARTIAL_CONTENT")
+ header.should == "Status: 206 Partial Content\r\nContent-Type: text/html\r\n\r\n"
+
+ header = @cgi.send(@method, "status" => "MULTIPLE_CHOICES")
+ header.should == "Status: 300 Multiple Choices\r\nContent-Type: text/html\r\n\r\n"
+
+ header = @cgi.send(@method, "server" => "Server Software used")
+ header.should == "Server: Server Software used\r\nContent-Type: text/html\r\n\r\n"
+
+ header = @cgi.send(@method, "connection" => "connection type")
+ header.should == "Connection: connection type\r\nContent-Type: text/html\r\n\r\n"
+
+ header = @cgi.send(@method, "length" => 103)
+ header.should == "Content-Type: text/html\r\nContent-Length: 103\r\n\r\n"
+
+ header = @cgi.send(@method, "language" => "ja")
+ header.should == "Content-Type: text/html\r\nContent-Language: ja\r\n\r\n"
+
+ header = @cgi.send(@method, "expires" => Time.at(0))
+ header.should == "Content-Type: text/html\r\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\r\n\r\n"
+
+ header = @cgi.send(@method, "cookie" => "my cookie's content")
+ header.should == "Content-Type: text/html\r\nSet-Cookie: my cookie's content\r\n\r\n"
+
+ header = @cgi.send(@method, "cookie" => ["multiple", "cookies"])
+ header.should == "Content-Type: text/html\r\nSet-Cookie: multiple\r\nSet-Cookie: cookies\r\n\r\n"
+ end
+
+ it "includes Cookies in the @output_cookies field" do
+ @cgi.instance_variable_set(:@output_cookies, ["multiple", "cookies"])
+ @cgi.send(@method, {}).should == "Content-Type: text/html\r\nSet-Cookie: multiple\r\nSet-Cookie: cookies\r\n\r\n"
+ end
+
+ it "returns a HTTP header specifiying the Content-Type as text/html when passed an empty Hash" do
+ @cgi.send(@method, {}).should == "Content-Type: text/html\r\n\r\n"
+ end
+ end
+end