Sha256: f90423add86bea1231f5731bff17e9e4f07d0f7ce31fd9334f30b7cb1df90358

Contents?: true

Size: 1.76 KB

Versions: 61

Compression:

Stored size: 1.76 KB

Contents

# encoding: utf-8

require File.expand_path('../helper', __FILE__)

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.join
  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

  it 'does not call #to_ary or #inject on the body' do
    object = Object.new
    def object.inject(*) fail 'called' end
    def object.to_ary(*) fail 'called' end
    def object.each(*) end
    @response.body = object
    assert @response.finish
  end

  it 'does not nest a Sinatra::Response' do
    @response.body = Sinatra::Response.new ["foo"]
    assert_equal @response.body, ["foo"]
  end

  it 'does not nest a Rack::Response' do
    @response.body = Rack::Response.new ["foo"]
    assert_equal @response.body, ["foo"]
  end
end

Version data entries

61 entries across 61 versions & 6 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/sinatra-1.3.2/test/response_test.rb
classiccms-0.7.4 vendor/bundle/gems/sinatra-1.3.2/test/response_test.rb
classiccms-0.7.3 vendor/bundle/gems/sinatra-1.3.2/test/response_test.rb
classiccms-0.7.2 vendor/bundle/gems/sinatra-1.3.2/test/response_test.rb
classiccms-0.7.1 vendor/bundle/gems/sinatra-1.3.2/test/response_test.rb
classiccms-0.7.0 vendor/bundle/gems/sinatra-1.3.2/test/response_test.rb
classiccms-0.6.9 vendor/bundle/gems/sinatra-1.3.2/test/response_test.rb
classiccms-0.6.8 vendor/bundle/gems/sinatra-1.3.2/test/response_test.rb
classiccms-0.6.7 vendor/bundle/gems/sinatra-1.3.2/test/response_test.rb
classiccms-0.6.6 vendor/bundle/gems/sinatra-1.3.2/test/response_test.rb
jellyfish-0.5.0 sinatra/response_test.rb
classiccms-0.6.5 vendor/bundle/gems/sinatra-1.3.2/test/response_test.rb
classiccms-0.6.4 vendor/bundle/gems/sinatra-1.3.2/test/response_test.rb
classiccms-0.6.3 vendor/bundle/gems/sinatra-1.3.2/test/response_test.rb
classiccms-0.6.2 vendor/bundle/gems/sinatra-1.3.2/test/response_test.rb
classiccms-0.6.1 vendor/bundle/gems/sinatra-1.3.2/test/response_test.rb
classiccms-0.6.0 vendor/bundle/gems/sinatra-1.3.2/test/response_test.rb
classiccms-0.5.17 vendor/bundle/gems/sinatra-1.3.2/test/response_test.rb
classiccms-0.5.16 vendor/bundle/gems/sinatra-1.3.2/test/response_test.rb
classiccms-0.5.15 vendor/bundle/gems/sinatra-1.3.2/test/response_test.rb