File: hijack.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 (48 lines) | stat: -rw-r--r-- 898 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
44
45
46
47
48
# frozen_string_literal: true

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

require "async/http/body/hijack"

require "sus/fixtures/async"

describe Async::HTTP::Body::Hijack do
	include Sus::Fixtures::Async::ReactorContext
	
	let(:body) do
		subject.wrap do |stream|
			3.times do 
				stream.write(content)
			end
			stream.close_write
		end
	end
	
	let(:content) {"Hello World!"}
	
	with "#call" do
		let(:stream) {Async::HTTP::Body::Writable.new}
		
		it "should generate body using direct invocation" do
			body.call(stream)
			
			3.times do
				expect(stream.read).to be == content
			end
			
			expect(stream.read).to be_nil
			expect(stream).to be(:empty?)
		end
		
		it "should generate body using stream" do
			3.times do
				expect(body.read).to be == content
			end
			
			expect(body.read).to be_nil
			
			expect(body).to be(:empty?)
		end
	end
end