Sha256: 5a239fda75513107b2ac2dd82ed0d0a7b429e9dd1a49f3709af2de354756581b

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

RSpec.describe "Streaming", type: :integration do
  xit "streams the body" do
    with_project do
      generate "action web home#index --url=/"

      # Require Rack::Chunked
      unshift "apps/web/app.rb", "require 'rack/chunked'"

      # Mount middleware
      replace "apps/web/app.rb", "# middleware.use", "middleware.use ::Rack::Chunked"
      replace "apps/web/app.rb", "controller.prepare do", "controller.format text: 'text/plain'\ncontroller.prepare do"

      rewrite "apps/web/controllers/home/index.rb", <<~EOF
        module Web::Controllers::Home
          class Index
            include Web::Action

            def call(params)
              self.format = :text
              self.body = Enumerator.new do |y|
                %w(one two three).each { |s| y << s }
              end
            end
          end
        end
      EOF

      server do
        get "/", {}, "HTTP_VERSION" => "HTTP/1.1"

        expect(last_response.headers).to_not have_key("Content-Length")
        expect(last_response.headers["Transfer-Encoding"]).to eq("chunked")

        expect(last_response.status).to eq(200)
        expect(last_response.body).to   eq("3\r\none\r\n3\r\ntwo\r\n5\r\nthree\r\n0\r\n\r\n")
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hanami-2.0.0.beta2 spec/integration/streaming_spec.rb
hanami-2.0.0.beta1.1 spec/integration/streaming_spec.rb
hanami-2.0.0.beta1 spec/integration/streaming_spec.rb