Sha256: f3c125c31724b9de20d0636059d044255fd3f6d6735711ebbb9b802838f6c00e

Contents?: true

Size: 1.22 KB

Versions: 54

Compression:

Stored size: 1.22 KB

Contents

# encoding: utf-8

require File.dirname(__FILE__) + '/helper'

class ResponseTest < Test::Unit::TestCase
  setup do
    @response = Sinatra::Response.new
  end

  it "initializes with 200, text/html, and empty body" do
    assert_equal 200, @response.status
    assert_equal 'text/html', @response['Content-Type']
    assert_equal [], @response.body
  end

  it 'uses case insensitive headers' do
    @response['content-type'] = 'application/foo'
    assert_equal 'application/foo', @response['Content-Type']
    assert_equal 'application/foo', @response['CONTENT-TYPE']
  end

  it 'writes to body' do
    @response.body = 'Hello'
    @response.write ' World'
    assert_equal 'Hello World', @response.body
  end

  [204, 304].each do |status_code|
    it "removes the Content-Type header and body when response status is #{status_code}" do
      @response.status = status_code
      @response.body = ['Hello World']
      assert_equal [status_code, {}, []], @response.finish
    end
  end

  it 'Calculates the Content-Length using the bytesize of the body' do
    @response.body = ['Hello', 'World!', '✈']
    status, headers, body = @response.finish
    assert_equal '14', headers['Content-Length']
    assert_equal @response.body, body
  end
end

Version data entries

54 entries across 53 versions & 9 rubygems

Version Path
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/sinatra-1.0/test/response_test.rb
adamwiggins-sinatra-0.10.1 test/response_test.rb
sinatra-sinatra-0.10.0 test/response_test.rb
sinatra-sinatra-0.10.1 test/response_test.rb
sinatra-sinatra-0.9.1.3 test/response_test.rb
sinatra-sinatra-0.9.2 test/response_test.rb
sinatra-1.2.9 test/response_test.rb
sinatra-base-1.0 test/response_test.rb
sinatra-1.2.8 test/response_test.rb
sinatra-1.2.7 test/response_test.rb
sinatra-1.2.6 test/response_test.rb
sinatra-1.3.0.d test/response_test.rb
sinatra-1.3.0.c test/response_test.rb
sinatra-1.2.3 test/response_test.rb
sinatra-1.1.4 test/response_test.rb
sinatra-1.2.2 test/response_test.rb
sinatra-1.3.0.b test/response_test.rb
sinatra-1.3.0.a test/response_test.rb
sinatra-1.2.1 test/response_test.rb
sinatra-1.2.0 test/response_test.rb