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.253 kb
c7dfca8 Ryan Tomayko Calculate Content-Length using #bytesize instead of #length
rtomayko authored
1 # encoding: utf-8
2
bc7a939 Ryan Tomayko General spec coverage improvements (rcov: 98%)
rtomayko authored
3 require File.dirname(__FILE__) + '/helper'
4
ff0d068 Simon Rozet Use contest instead of test/spec/mini
sr authored
5 class ResponseTest < Test::Unit::TestCase
6 setup do
bc7a939 Ryan Tomayko 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'
25 assert_equal 'Hello World', @response.body
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 Ryan Tomayko 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']
40 assert_equal @response.body, body
41 end
bc7a939 Ryan Tomayko General spec coverage improvements (rcov: 98%)
rtomayko authored
42 end
Something went wrong with that request. Please try again.