File: test.rb

package info (click to toggle)
ruby-async-http 0.94.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 916 kB
  • sloc: ruby: 5,224; javascript: 40; makefile: 4
file content (43 lines) | stat: -rw-r--r-- 787 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2019-2026, by Samuel Williams.

require "sus/fixtures/async"
require "async/http"

require "rack/test"
require "rack/builder"

describe Rack::Test do
	include Sus::Fixtures::Async::ReactorContext
	include Rack::Test::Methods
	
	let(:app) do
		Rack::Builder.new do
			def body(*chunks)
				body = Async::HTTP::Body::Writable.new
				
				Async do |task|
					chunks.each do |chunk|
						body.write(chunk)
						sleep(0.1)
					end
					
					body.close
				end
				
				return body
			end
			
			# This echos the body back.
			run lambda{|env| [200, {}, body("Hello", " ", "World", "!")]}
		end
	end
	
	it "can read response body" do
		get "/"
		
		expect(last_response.body).to be == "Hello World!"
	end
end