Sha256: f5000e9b29ebee7353a4ca56fe3fc12ef9c069d4476473398feb38192d766f59

Contents?: true

Size: 1.1 KB

Versions: 21

Compression:

Stored size: 1.1 KB

Contents

require_relative "../spec_helper"

describe "head plugin" do 
  it "considers HEAD requests as GET requests which return no body" do
    app(:head) do |r|
      r.root do
        'root'
      end

      r.get 'a' do
        'a'
      end

      r.is 'b', :method=>[:get, :post] do
        'b'
      end
    end

    s, h, b = req
    s.must_equal 200
    h['Content-Length'].must_equal '4'
    b.must_equal ['root']

    s, h, b = req('REQUEST_METHOD' => 'HEAD')
    s.must_equal 200
    h['Content-Length'].must_equal '4'
    b.must_equal []

    body('/a').must_equal 'a'
    status('/a', 'REQUEST_METHOD' => 'HEAD').must_equal 200

    body('/b').must_equal 'b'
    status('/b', 'REQUEST_METHOD' => 'HEAD').must_equal 200
  end

  it "releases resources via body.close" do
    body = StringIO.new('hi')
    app(:head) do |r|
      r.root do
        r.halt [ 200, {}, body ]
      end
    end
    s, _, b = req('REQUEST_METHOD' => 'HEAD')
    s.must_equal 200
    res = String.new
    body.closed?.must_equal false
    b.each { |buf| res << buf }
    b.close
    body.closed?.must_equal true
    res.must_equal ''
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
roda-3.28.0 spec/plugin/head_spec.rb
roda-3.27.0 spec/plugin/head_spec.rb
roda-3.26.0 spec/plugin/head_spec.rb
roda-3.25.0 spec/plugin/head_spec.rb
roda-3.24.0 spec/plugin/head_spec.rb
roda-3.23.0 spec/plugin/head_spec.rb
roda-3.22.0 spec/plugin/head_spec.rb
roda-3.21.0 spec/plugin/head_spec.rb
roda-3.20.0 spec/plugin/head_spec.rb
roda-3.19.0 spec/plugin/head_spec.rb
roda-3.18.0 spec/plugin/head_spec.rb
roda-3.17.0 spec/plugin/head_spec.rb
roda-3.16.0 spec/plugin/head_spec.rb
roda-3.15.0 spec/plugin/head_spec.rb
roda-3.14.1 spec/plugin/head_spec.rb
roda-3.14.0 spec/plugin/head_spec.rb
roda-3.13.0 spec/plugin/head_spec.rb
roda-3.12.0 spec/plugin/head_spec.rb
roda-3.11.0 spec/plugin/head_spec.rb
roda-3.10.0 spec/plugin/head_spec.rb