Sha256: d18b64614516d24800e211b9c391e13d7aaac9194ea6e134420d62e2ad097bf3

Contents?: true

Size: 1.7 KB

Versions: 2

Compression:

Stored size: 1.7 KB

Contents

require "#{File.dirname(__FILE__)}/spec_setup"
require 'rack/utils/environment_headers'

describe 'Rack::Utils::EnvironmentHeaders' do

  before :each do
    @now = Time.now.httpdate
    @env = {
      'CONTENT_TYPE'           => 'text/plain',
      'CONTENT_LENGTH'         => '0x1A4',
      'HTTP_X_FOO'             => 'BAR',
      'HTTP_IF_MODIFIED_SINCE' => @now,
      'rack.run_once'          => true
    }
    @h = Rack::Utils::EnvironmentHeaders.new(@env)
  end

  after(:each) {
    @env, @h = nil, nil
  }

  it 'retrieves headers with #[]' do
    @h.should.respond_to :[]
    @h['X-Foo'].should.equal 'BAR'
    @h['If-Modified-Since'].should.equal @now
  end

  it 'sets headers with #[]=' do
    @h.should.respond_to :[]=
    @h['X-Foo'] = 'BAZZLE'
    @h['X-Foo'].should.equal 'BAZZLE'
  end

  it 'sets values on the underlying environment hash' do
    @h['X-Something-Else'] = 'FOO'
    @env['HTTP_X_SOMETHING_ELSE'].should.equal 'FOO'
  end

  it 'handles Content-Type special case' do
    @h['Content-Type'].should.equal 'text/plain'
  end

  it 'handles Content-Length special case' do
    @h['Content-Length'].should.equal '0x1A4'
  end

  it 'implements #include? with RFC 2616 header name' do
    @h.should.include 'If-Modified-Since'
  end

  it 'deletes underlying env entries' do
    @h.delete('X-Foo')
    @env.should.not.include? 'HTTP_X_FOO'
  end

  it 'returns the underlying environment hash with #to_env' do
    @h.to_env.should.be @env
  end

  it 'iterates over all headers with #each' do
    hash = {}
    @h.each { |name,value| hash[name] = value }
    hash.should.equal 'Content-Type' => 'text/plain',
      'Content-Length' => '0x1A4',
      'X-Foo' => 'BAR',
      'If-Modified-Since' => @now
  end

end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
rtomayko-rack-cache-0.3.0 test/environment_headers_test.rb
rack-cache-0.3.0 test/environment_headers_test.rb