Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 43 lines (35 sloc) 1.268 kb
c7dfca8 @rtomayko Calculate Content-Length using #bytesize instead of #length
rtomayko authored
1 # encoding: utf-8
2
e001d62 @rkh adjust require lines for test helper, so it also works properly on 1.9.2
rkh authored
3 require File.expand_path('../helper', __FILE__)
bc7a939 @rtomayko General spec coverage improvements (rcov: 98%)
rtomayko authored
4
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
5 class ResponseTest < Test::Unit::TestCase
6 setup do
bc7a939 @rtomayko General spec coverage improvements (rcov: 98%)
rtomayko authored
7 @response = Sinatra::Response.new
8 end
9
10 it "initializes with 200, text/html, and empty body" do
11 assert_equal 200, @response.status
12 assert_equal 'text/html', @response['Content-Type']
13 assert_equal [], @response.body
14 end
15
16 it 'uses case insensitive headers' do
17 @response['content-type'] = 'application/foo'
18 assert_equal 'application/foo', @response['Content-Type']
19 assert_equal 'application/foo', @response['CONTENT-TYPE']
20 end
21
22 it 'writes to body' do
23 @response.body = 'Hello'
24 @response.write ' World'
8eb1abd @rkh fix handling of response.body
rkh authored
25 assert_equal 'Hello World', @response.body.join
bc7a939 @rtomayko General spec coverage improvements (rcov: 98%)
rtomayko authored
26 end
27
28 [204, 304].each do |status_code|
29 it "removes the Content-Type header and body when response status is #{status_code}" do
30 @response.status = status_code
31 @response.body = ['Hello World']
32 assert_equal [status_code, {}, []], @response.finish
33 end
34 end
c7dfca8 @rtomayko Calculate Content-Length using #bytesize instead of #length
rtomayko authored
35
36 it 'Calculates the Content-Length using the bytesize of the body' do
37 @response.body = ['Hello', 'World!', '']
38 status, headers, body = @response.finish
39 assert_equal '14', headers['Content-Length']
8eb1abd @rkh fix handling of response.body
rkh authored
40 assert_equal @response.body, body.body
c7dfca8 @rtomayko Calculate Content-Length using #bytesize instead of #length
rtomayko authored
41 end
bc7a939 @rtomayko General spec coverage improvements (rcov: 98%)
rtomayko authored
42 end
Something went wrong with that request. Please try again.