Skip to content

Commit 68f0fc2

Browse files
committed
Add tests for rewindable.
1 parent bd2457c commit 68f0fc2

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

test/protocol/rack/rewindable.rb

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
describe Protocol::Rack::Rewindable do
1010
let(:headers) {Protocol::HTTP::Headers.new}
1111
let(:body) {Protocol::HTTP::Body::Readable.new}
12-
let(:app) {
13-
app = Object.new
14-
mock(app) do |mock|
15-
mock.replace(:call) do |request|
16-
Protocol::HTTP::Response[200, {}, []]
17-
end
12+
13+
let(:app) do
14+
proc do |request|
15+
Protocol::HTTP::Response[200, {}, []]
1816
end
19-
app
20-
}
17+
end
18+
19+
let(:rewindable) {subject.new(app)}
2120

2221
with "non-POST requests" do
2322
it "should rewind if it has a buffered media type" do
@@ -26,7 +25,6 @@
2625
)
2726
request.headers["content-type"] = "application/x-www-form-urlencoded"
2827

29-
rewindable = subject.new(nil)
3028
expect(rewindable.needs_rewind?(request)).to be == true
3129
end
3230
end
@@ -37,7 +35,6 @@
3735
"https", "example.com", "POST", "/", "HTTP/1.1", headers, body
3836
)
3937

40-
rewindable = subject.new(nil)
4138
expect(rewindable.needs_rewind?(request)).to be == true
4239
end
4340

@@ -47,7 +44,6 @@
4744
)
4845
request.headers["content-type"] = "application/x-www-form-urlencoded"
4946

50-
rewindable = subject.new(nil)
5147
expect(rewindable.needs_rewind?(request)).to be == true
5248
end
5349

@@ -57,7 +53,6 @@
5753
)
5854
request.headers["content-type"] = "multipart/form-data; boundary=----WebKitFormBoundary"
5955

60-
rewindable = subject.new(nil)
6156
expect(rewindable.needs_rewind?(request)).to be == true
6257
end
6358

@@ -67,7 +62,6 @@
6762
)
6863
request.headers["content-type"] = "multipart/related; boundary=----WebKitFormBoundary"
6964

70-
rewindable = subject.new(nil)
7165
expect(rewindable.needs_rewind?(request)).to be == true
7266
end
7367

@@ -77,7 +71,6 @@
7771
)
7872
request.headers["content-type"] = "multipart/mixed; boundary=----WebKitFormBoundary"
7973

80-
rewindable = subject.new(nil)
8174
expect(rewindable.needs_rewind?(request)).to be == true
8275
end
8376

@@ -87,7 +80,6 @@
8780
)
8881
request.headers["content-type"] = "application/json"
8982

90-
rewindable = subject.new(nil)
9183
expect(rewindable.needs_rewind?(request)).to be == false
9284
end
9385
end
@@ -99,7 +91,6 @@
9991
)
10092
request.headers["content-type"] = "application/x-www-form-urlencoded"
10193

102-
rewindable = subject.new(app)
10394
rewindable.call(request)
10495

10596
expect(request.body).to be_a(Protocol::HTTP::Body::Rewindable)
@@ -112,7 +103,6 @@
112103
)
113104
request.headers["content-type"] = "application/json"
114105

115-
rewindable = subject.new(app)
116106
rewindable.call(request)
117107

118108
expect(request.body).to be == body

0 commit comments

Comments
 (0)