OSDN Git Service

Replaced mongrel with thin
[redminele/redminele.git] / ruby / lib / ruby / gems / 1.8 / gems / thin-1.2.11-x86-mswin32 / spec / response_spec.rb
1 require File.dirname(__FILE__) + '/spec_helper'
2
3 describe Response do
4   before do
5     @response = Response.new
6     @response.headers['Content-Type'] = 'text/html'
7     @response.headers['Content-Length'] = '0'
8     @response.body = ''
9   end
10   
11   it 'should output headers' do
12     @response.headers_output.should include("Content-Type: text/html", "Content-Length: 0", "Connection: close")
13   end
14   
15   it 'should include server name header' do
16     @response.headers_output.should include("Server: thin")
17   end
18   
19   it 'should output head' do
20     @response.head.should include("HTTP/1.1 200 OK", "Content-Type: text/html", "Content-Length: 0",
21                                   "Connection: close", "\r\n\r\n")
22   end
23   
24   it 'should allow duplicates in headers' do
25     @response.headers['Set-Cookie'] = 'mium=7'
26     @response.headers['Set-Cookie'] = 'hi=there'
27     
28     @response.head.should include("Set-Cookie: mium=7", "Set-Cookie: hi=there")
29   end
30   
31   it 'should parse simple header values' do
32     @response.headers = {
33       'Host' => 'localhost'
34     }
35     
36     @response.head.should include("Host: localhost")
37   end
38   
39   it 'should parse multiline header values in several headers' do
40     @response.headers = {
41       'Set-Cookie' => "mium=7\nhi=there"
42     }
43     
44     @response.head.should include("Set-Cookie: mium=7", "Set-Cookie: hi=there")
45   end
46
47   it 'should ignore nil headers' do
48     @response.headers = nil
49     @response.headers = { 'Host' => 'localhost' }
50     @response.headers = { 'Set-Cookie' => nil }
51     @response.head.should include('Host: localhost')
52   end
53   
54   it 'should output body' do
55     @response.body = ['<html>', '</html>']
56     
57     out = ''
58     @response.each { |l| out << l }
59     out.should include("\r\n\r\n<html></html>")
60   end
61     
62   it 'should output String body' do
63     @response.body = '<html></html>'
64     
65     out = ''
66     @response.each { |l| out << l }
67     out.should include("\r\n\r\n<html></html>")
68   end
69     
70   it "should not be persistent by default" do
71     @response.should_not be_persistent
72   end
73   
74   it "should not be persistent when no Content-Length" do
75     @response = Response.new
76     @response.headers['Content-Type'] = 'text/html'
77     @response.body = ''
78     
79     @response.persistent!
80     @response.should_not be_persistent
81   end
82   
83   it "should be persistent when the status code implies it should stay open" do
84     @response = Response.new
85     @response.status = 100
86     # "There are no required headers for this class of status code" -- HTTP spec 10.1
87     @response.body = ''
88
89     # Specifying it as persistent in the code is NOT required
90     # @response.persistent!
91     @response.should be_persistent
92   end
93   
94   it "should be persistent when specified" do
95     @response.persistent!
96     @response.should be_persistent
97   end
98   
99   it "should be closeable" do
100     @response.close
101   end
102 end