typhoeus 1.0.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +12 -7
- data/CHANGELOG.md +38 -2
- data/CONTRIBUTING.md +4 -0
- data/Gemfile +14 -3
- data/LICENSE +1 -1
- data/README.md +67 -42
- data/lib/typhoeus/adapters/faraday.rb +30 -9
- data/lib/typhoeus/cache/dalli.rb +28 -0
- data/lib/typhoeus/cache/rails.rb +28 -0
- data/lib/typhoeus/cache/redis.rb +35 -0
- data/lib/typhoeus/config.rb +8 -1
- data/lib/typhoeus/easy_factory.rb +10 -3
- data/lib/typhoeus/hydra/cacheable.rb +1 -1
- data/lib/typhoeus/pool.rb +2 -0
- data/lib/typhoeus/request/actions.rb +7 -7
- data/lib/typhoeus/request/cacheable.rb +14 -3
- data/lib/typhoeus/request/callbacks.rb +21 -3
- data/lib/typhoeus/request/marshal.rb +2 -2
- data/lib/typhoeus/request/streamable.rb +1 -1
- data/lib/typhoeus/request.rb +2 -0
- data/lib/typhoeus/response/header.rb +13 -5
- data/lib/typhoeus/response/informations.rb +7 -3
- data/lib/typhoeus/response/status.rb +22 -2
- data/lib/typhoeus/response.rb +1 -1
- data/lib/typhoeus/version.rb +1 -1
- data/lib/typhoeus.rb +19 -3
- data/spec/support/server.rb +8 -0
- data/spec/typhoeus/adapters/faraday_spec.rb +237 -191
- data/spec/typhoeus/cache/dalli_spec.rb +41 -0
- data/spec/typhoeus/cache/redis_spec.rb +41 -0
- data/spec/typhoeus/config_spec.rb +1 -1
- data/spec/typhoeus/easy_factory_spec.rb +6 -0
- data/spec/typhoeus/hydra/before_spec.rb +9 -8
- data/spec/typhoeus/hydra/cacheable_spec.rb +31 -1
- data/spec/typhoeus/hydra/runnable_spec.rb +4 -3
- data/spec/typhoeus/pool_spec.rb +43 -2
- data/spec/typhoeus/request/before_spec.rb +9 -8
- data/spec/typhoeus/request/cacheable_spec.rb +24 -0
- data/spec/typhoeus/request/callbacks_spec.rb +2 -2
- data/spec/typhoeus/request/marshal_spec.rb +1 -1
- data/spec/typhoeus/request_spec.rb +21 -3
- data/spec/typhoeus/response/header_spec.rb +51 -1
- data/spec/typhoeus/response/informations_spec.rb +12 -1
- data/spec/typhoeus/response/status_spec.rb +54 -0
- data/typhoeus.gemspec +1 -1
- metadata +12 -5
@@ -1,292 +1,338 @@
|
|
1
|
-
|
2
|
-
require '
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("1.9.0")
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'typhoeus/adapters/faraday'
|
4
|
+
|
5
|
+
describe Faraday::Adapter::Typhoeus do
|
6
|
+
let(:base_url) { "http://localhost:3001" }
|
7
|
+
let(:adapter) { described_class.new(nil) }
|
8
|
+
let(:request) { Typhoeus::Request.new(base_url) }
|
9
|
+
let(:conn) do
|
10
|
+
Faraday.new(:url => base_url) do |faraday|
|
11
|
+
faraday.adapter :typhoeus
|
12
|
+
end
|
11
13
|
end
|
12
|
-
|
13
|
-
let(:response) { conn.get("/") }
|
14
|
+
let(:response) { conn.get("/") }
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
context "when parallel" do
|
17
|
+
it "returns a faraday response" do
|
18
|
+
response = nil
|
19
|
+
conn.in_parallel { response = conn.get("/") }
|
20
|
+
expect(response).to be_a(Faraday::Response)
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
it "succeeds" do
|
24
|
+
response = nil
|
25
|
+
conn.in_parallel { response = conn.get("/") }
|
26
|
+
expect(response.status).to be(200)
|
27
|
+
end
|
26
28
|
end
|
27
|
-
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
context "when not parallel" do
|
31
|
+
it "returns a faraday response" do
|
32
|
+
expect(response).to be_a(Faraday::Response)
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
35
|
+
it "succeeds" do
|
36
|
+
expect(response.status).to be(200)
|
37
|
+
end
|
36
38
|
end
|
37
|
-
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
40
|
+
context "when a response is stubbed" do
|
41
|
+
before do
|
42
|
+
stub = Typhoeus::Response.new \
|
43
|
+
:code => 200,
|
44
|
+
:headers => { "Foo" => "2", "Bar" => "3" },
|
45
|
+
:body => "Hello",
|
46
|
+
:mock => true
|
46
47
|
|
47
|
-
|
48
|
-
|
48
|
+
Typhoeus.stub(base_url + '/').and_return(stub)
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
it 'stubs the status code' do
|
52
|
+
expect(response.status).to eq(200)
|
53
|
+
end
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
it 'stubs the response body' do
|
56
|
+
expect(response.body).to eq("Hello")
|
57
|
+
end
|
57
58
|
|
58
|
-
|
59
|
-
|
59
|
+
it 'stubs the headers' do
|
60
|
+
expect(response.headers).to eq("Foo" => "2", "Bar" => "3")
|
61
|
+
end
|
60
62
|
end
|
61
|
-
end
|
62
63
|
|
63
|
-
|
64
|
-
|
64
|
+
describe "#initialize" do
|
65
|
+
let(:request) { adapter.method(:typhoeus_request).call({}) }
|
65
66
|
|
66
|
-
|
67
|
-
|
67
|
+
context "when typhoeus request options specified" do
|
68
|
+
let(:adapter) { described_class.new(nil, { :forbid_reuse => true, :maxredirs => 1 }) }
|
68
69
|
|
69
|
-
|
70
|
-
|
70
|
+
it "should set option for request" do
|
71
|
+
expect(request.options[:forbid_reuse]).to be_truthy
|
72
|
+
expect(request.options[:maxredirs]).to eq(1)
|
73
|
+
end
|
71
74
|
end
|
72
75
|
end
|
73
76
|
|
74
|
-
|
75
|
-
|
76
|
-
let(:env) { { :parallel_manager => double(:queue => true), :ssl => {}, :request => {} } }
|
77
|
+
describe "#perform_request" do
|
78
|
+
let(:env) { {} }
|
77
79
|
|
78
|
-
|
79
|
-
|
80
|
+
context "when body" do
|
81
|
+
let(:env) { { :body => double(:read => "body") } }
|
82
|
+
|
83
|
+
it "reads body" do
|
84
|
+
expect(adapter.method(:read_body).call(env)).to eq("body")
|
80
85
|
end
|
81
86
|
end
|
82
87
|
|
83
|
-
context "
|
84
|
-
|
88
|
+
context "parallel_manager" do
|
89
|
+
context "when given" do
|
90
|
+
let(:env) { { :parallel_manager => double(:queue => true), :ssl => {}, :request => {} } }
|
85
91
|
|
86
|
-
|
87
|
-
|
88
|
-
|
92
|
+
it "uses" do
|
93
|
+
adapter.method(:perform_request).call(env)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "when not given" do
|
98
|
+
let(:env) { { :method => :get, :ssl => {}, :request => {} } }
|
99
|
+
|
100
|
+
it "falls back to single" do
|
101
|
+
expect(Typhoeus::Request).to receive(:new).and_return(double(:options => {}, :on_complete => [], :run => true))
|
102
|
+
adapter.method(:perform_request).call(env)
|
103
|
+
end
|
89
104
|
end
|
90
105
|
end
|
91
106
|
end
|
92
|
-
end
|
93
107
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
108
|
+
describe "#request" do
|
109
|
+
let(:env) do
|
110
|
+
{ :url => "url", :method => :get, :body => "body", :request_headers => {}, :ssl => {}, :request => {} }
|
111
|
+
end
|
98
112
|
|
99
|
-
|
113
|
+
let(:request) { adapter.method(:request).call(env) }
|
100
114
|
|
101
|
-
|
102
|
-
|
103
|
-
|
115
|
+
it "returns request" do
|
116
|
+
expect(request).to be_a(Typhoeus::Request)
|
117
|
+
end
|
104
118
|
|
105
|
-
|
106
|
-
|
107
|
-
|
119
|
+
it "sets url" do
|
120
|
+
expect(request.base_url).to eq("url")
|
121
|
+
end
|
108
122
|
|
109
|
-
|
110
|
-
|
111
|
-
|
123
|
+
it "sets http method" do
|
124
|
+
expect(request.original_options[:method]).to eq(:get)
|
125
|
+
end
|
112
126
|
|
113
|
-
|
114
|
-
|
115
|
-
|
127
|
+
it "sets body" do
|
128
|
+
expect(request.original_options[:body]).to eq("body")
|
129
|
+
end
|
116
130
|
|
117
|
-
|
118
|
-
|
119
|
-
|
131
|
+
it "sets headers" do
|
132
|
+
expect(request.original_options[:headers]).to eq({})
|
133
|
+
end
|
120
134
|
|
121
|
-
|
122
|
-
|
135
|
+
it "sets on_complete callback" do
|
136
|
+
expect(request.on_complete.size).to eq(1)
|
137
|
+
end
|
123
138
|
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe "#configure_socket" do
|
127
|
-
let(:env) { { :request => { :bind => { :host => "interface" } } } }
|
128
139
|
|
129
|
-
|
140
|
+
context "when the connection failed" do
|
141
|
+
before do
|
142
|
+
stub = Typhoeus::Response.new \
|
143
|
+
:response_code => 0,
|
144
|
+
:return_code => 0,
|
145
|
+
:mock => true
|
130
146
|
|
131
|
-
|
132
|
-
it "sets interface" do
|
133
|
-
expect(request.options[:interface]).to eq("interface")
|
147
|
+
Typhoeus.stub(base_url + '/').and_return(stub)
|
134
148
|
end
|
135
|
-
end
|
136
|
-
end
|
137
149
|
|
138
|
-
|
139
|
-
|
150
|
+
context "when parallel" do
|
151
|
+
it "isn't successful" do
|
152
|
+
response = nil
|
153
|
+
conn.in_parallel { response = conn.get("/") }
|
154
|
+
expect(response.success?).to be_falsey
|
155
|
+
end
|
140
156
|
|
141
|
-
|
142
|
-
|
157
|
+
it "translates the response code into an error message" do
|
158
|
+
response = nil
|
159
|
+
conn.in_parallel { response = conn.get("/") }
|
160
|
+
expect(response.env[:typhoeus_return_message]).to eq("No error")
|
161
|
+
end
|
162
|
+
end
|
143
163
|
|
144
|
-
|
145
|
-
|
164
|
+
context "when not parallel" do
|
165
|
+
it "raises an error" do
|
166
|
+
expect { conn.get("/") }.to raise_error(Faraday::ConnectionFailed, "No error")
|
167
|
+
end
|
146
168
|
end
|
147
169
|
end
|
148
170
|
|
149
|
-
|
150
|
-
let(:env) { { :request => { :
|
171
|
+
describe "#configure_socket" do
|
172
|
+
let(:env) { { :request => { :bind => { :host => "interface" } } } }
|
173
|
+
|
174
|
+
before { adapter.method(:configure_socket).call(request, env) }
|
151
175
|
|
152
|
-
|
153
|
-
|
176
|
+
context "when host" do
|
177
|
+
it "sets interface" do
|
178
|
+
expect(request.options[:interface]).to eq("interface")
|
179
|
+
end
|
154
180
|
end
|
155
181
|
end
|
156
|
-
end
|
157
182
|
|
158
|
-
|
159
|
-
|
183
|
+
describe "#configure_timeout" do
|
184
|
+
before { adapter.method(:configure_timeout).call(request, env) }
|
160
185
|
|
161
|
-
|
162
|
-
|
186
|
+
context "when timeout" do
|
187
|
+
let(:env) { { :request => { :timeout => 1 } } }
|
163
188
|
|
164
|
-
|
165
|
-
|
189
|
+
it "sets timeout_ms" do
|
190
|
+
expect(request.options[:timeout_ms]).to eq(1000)
|
191
|
+
end
|
166
192
|
end
|
167
193
|
|
168
|
-
context "when
|
169
|
-
let(:env)
|
170
|
-
{ :request => { :proxy => {
|
171
|
-
:uri => double(:scheme => 'http', :host => :a, :port => :b),
|
172
|
-
:user => "a",
|
173
|
-
:password => "b"
|
174
|
-
} } }
|
175
|
-
end
|
194
|
+
context "when open_timeout" do
|
195
|
+
let(:env) { { :request => { :open_timeout => 1 } } }
|
176
196
|
|
177
|
-
it "sets
|
178
|
-
expect(request.options[:
|
197
|
+
it "sets connecttimeout_ms" do
|
198
|
+
expect(request.options[:connecttimeout_ms]).to eq(1000)
|
179
199
|
end
|
180
200
|
end
|
181
201
|
end
|
182
|
-
end
|
183
202
|
|
184
|
-
|
185
|
-
|
203
|
+
describe "#configure_proxy" do
|
204
|
+
before { adapter.method(:configure_proxy).call(request, env) }
|
186
205
|
|
187
|
-
|
188
|
-
|
206
|
+
context "when proxy" do
|
207
|
+
let(:env) { { :request => { :proxy => { :uri => double(:scheme => 'http', :host => "localhost", :port => "3001") } } } }
|
189
208
|
|
190
|
-
|
191
|
-
|
209
|
+
it "sets proxy" do
|
210
|
+
expect(request.options[:proxy]).to eq("http://localhost:3001")
|
211
|
+
end
|
212
|
+
|
213
|
+
context "when username and password" do
|
214
|
+
let(:env) do
|
215
|
+
{ :request => { :proxy => {
|
216
|
+
:uri => double(:scheme => 'http', :host => :a, :port => :b),
|
217
|
+
:user => "a",
|
218
|
+
:password => "b"
|
219
|
+
} } }
|
220
|
+
end
|
221
|
+
|
222
|
+
it "sets proxyuserpwd" do
|
223
|
+
expect(request.options[:proxyuserpwd]).to eq("a:b")
|
224
|
+
end
|
225
|
+
end
|
192
226
|
end
|
193
227
|
end
|
194
228
|
|
195
|
-
|
196
|
-
|
229
|
+
describe "#configure_ssl" do
|
230
|
+
before { adapter.method(:configure_ssl).call(request, env) }
|
231
|
+
|
232
|
+
context "when version" do
|
233
|
+
let(:env) { { :ssl => { :version => "a" } } }
|
197
234
|
|
198
|
-
|
199
|
-
|
235
|
+
it "sets sslversion" do
|
236
|
+
expect(request.options[:sslversion]).to eq("a")
|
237
|
+
end
|
200
238
|
end
|
201
|
-
end
|
202
239
|
|
203
|
-
|
204
|
-
|
240
|
+
context "when client_cert" do
|
241
|
+
let(:env) { { :ssl => { :client_cert => "a" } } }
|
205
242
|
|
206
|
-
|
207
|
-
|
243
|
+
it "sets sslcert" do
|
244
|
+
expect(request.options[:sslcert]).to eq("a")
|
245
|
+
end
|
208
246
|
end
|
209
|
-
end
|
210
247
|
|
211
|
-
|
212
|
-
|
248
|
+
context "when client_key" do
|
249
|
+
let(:env) { { :ssl => { :client_key => "a" } } }
|
213
250
|
|
214
|
-
|
215
|
-
|
251
|
+
it "sets sslkey" do
|
252
|
+
expect(request.options[:sslkey]).to eq("a")
|
253
|
+
end
|
216
254
|
end
|
217
|
-
end
|
218
255
|
|
219
|
-
|
220
|
-
|
256
|
+
context "when ca_file" do
|
257
|
+
let(:env) { { :ssl => { :ca_file => "a" } } }
|
221
258
|
|
222
|
-
|
223
|
-
|
259
|
+
it "sets cainfo" do
|
260
|
+
expect(request.options[:cainfo]).to eq("a")
|
261
|
+
end
|
224
262
|
end
|
225
|
-
end
|
226
263
|
|
227
|
-
|
228
|
-
|
264
|
+
context "when ca_path" do
|
265
|
+
let(:env) { { :ssl => { :ca_path => "a" } } }
|
229
266
|
|
230
|
-
|
231
|
-
|
267
|
+
it "sets capath" do
|
268
|
+
expect(request.options[:capath]).to eq("a")
|
269
|
+
end
|
232
270
|
end
|
233
|
-
end
|
234
271
|
|
235
|
-
|
236
|
-
|
272
|
+
context "when client_cert_passwd" do
|
273
|
+
let(:env) { { :ssl => { :client_cert_passwd => "a" } } }
|
237
274
|
|
238
|
-
|
239
|
-
|
275
|
+
it "sets keypasswd to the value of client_cert_passwd" do
|
276
|
+
expect(request.options[:keypasswd]).to eq("a")
|
277
|
+
end
|
240
278
|
end
|
241
|
-
end
|
242
279
|
|
243
|
-
|
244
|
-
|
280
|
+
context "when client_certificate_password" do
|
281
|
+
let(:env) { { :ssl => { :client_certificate_password => "a" } } }
|
245
282
|
|
246
|
-
|
247
|
-
|
283
|
+
it "sets keypasswd to the value of client_cert_passwd" do
|
284
|
+
expect(request.options[:keypasswd]).to eq("a")
|
285
|
+
end
|
248
286
|
end
|
249
|
-
end
|
250
287
|
|
251
|
-
|
252
|
-
|
288
|
+
context "when no client_cert_passwd" do
|
289
|
+
let(:env) { { :ssl => { } } }
|
253
290
|
|
254
|
-
|
255
|
-
|
291
|
+
it "does not set keypasswd on options" do
|
292
|
+
expect(request.options).not_to have_key :keypasswd
|
293
|
+
end
|
256
294
|
end
|
257
295
|
|
258
|
-
|
259
|
-
|
260
|
-
end
|
261
|
-
end
|
296
|
+
context "when verify is false" do
|
297
|
+
let(:env) { { :ssl => { :verify => false } } }
|
262
298
|
|
263
|
-
|
264
|
-
|
299
|
+
it "sets ssl_verifyhost to 0" do
|
300
|
+
expect(request.options[:ssl_verifyhost]).to eq(0)
|
301
|
+
end
|
265
302
|
|
266
|
-
|
267
|
-
|
303
|
+
it "sets ssl_verifypeer to false" do
|
304
|
+
expect(request.options[:ssl_verifypeer]).to be_falsey
|
305
|
+
end
|
268
306
|
end
|
269
307
|
|
270
|
-
|
271
|
-
|
308
|
+
context "when verify is true" do
|
309
|
+
let(:env) { { :ssl => { :verify => true } } }
|
310
|
+
|
311
|
+
it "sets ssl_verifyhost to 2" do
|
312
|
+
expect(request.options[:ssl_verifyhost]).to eq(2)
|
313
|
+
end
|
314
|
+
|
315
|
+
it "sets ssl_verifypeer to true" do
|
316
|
+
expect(request.options[:ssl_verifypeer]).to be_truthy
|
317
|
+
end
|
272
318
|
end
|
273
319
|
end
|
274
|
-
end
|
275
320
|
|
276
|
-
|
277
|
-
|
278
|
-
|
321
|
+
describe "#parallel?" do
|
322
|
+
context "when parallel_manager" do
|
323
|
+
let(:env) { { :parallel_manager => true } }
|
279
324
|
|
280
|
-
|
281
|
-
|
325
|
+
it "returns true" do
|
326
|
+
expect(adapter.method(:parallel?).call(env)).to be_truthy
|
327
|
+
end
|
282
328
|
end
|
283
|
-
end
|
284
329
|
|
285
|
-
|
286
|
-
|
330
|
+
context "when no parallel_manager" do
|
331
|
+
let(:env) { { :parallel_manager => nil } }
|
287
332
|
|
288
|
-
|
289
|
-
|
333
|
+
it "returns false" do
|
334
|
+
expect(adapter.method(:parallel?).call(env)).to be_falsey
|
335
|
+
end
|
290
336
|
end
|
291
337
|
end
|
292
338
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("1.9.0")
|
2
|
+
require 'dalli'
|
3
|
+
require 'typhoeus/cache/dalli'
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
describe Typhoeus::Cache::Dalli do
|
7
|
+
let(:dalli) { instance_double(Dalli::Client) }
|
8
|
+
let(:cache) { Typhoeus::Cache::Dalli.new(dalli) }
|
9
|
+
|
10
|
+
let(:base_url) { "localhost:3001" }
|
11
|
+
let(:request) { Typhoeus::Request.new(base_url, {:method => :get}) }
|
12
|
+
let(:response) { Typhoeus::Response.new(:response_code => 0, :return_code => 0, :mock => true) }
|
13
|
+
|
14
|
+
describe "#set" do
|
15
|
+
it "sends the request to Dalli" do
|
16
|
+
expect(dalli).to receive(:set).with(request.cache_key, response, nil)
|
17
|
+
|
18
|
+
cache.set(request, response)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#get" do
|
23
|
+
it "returns nil when the key is not in the cache" do
|
24
|
+
expect(dalli).to receive(:get).with(request.cache_key).and_return(nil)
|
25
|
+
|
26
|
+
expect(cache.get(request)).to be_nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns the cached response when the key is in cache" do
|
30
|
+
expect(dalli).to receive(:get).with(request.cache_key).and_return(response)
|
31
|
+
|
32
|
+
result = cache.get(request)
|
33
|
+
expect(result).to_not be_nil
|
34
|
+
expect(result.response_code).to eq(response.response_code)
|
35
|
+
expect(result.return_code).to eq(response.return_code)
|
36
|
+
expect(result.headers).to eq(response.headers)
|
37
|
+
expect(result.body).to eq(response.body)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'redis'
|
2
|
+
require 'typhoeus/cache/redis'
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Typhoeus::Cache::Redis do
|
6
|
+
let(:redis) { instance_double(Redis) }
|
7
|
+
let(:cache) { Typhoeus::Cache::Redis.new(redis) }
|
8
|
+
|
9
|
+
let(:base_url) { "localhost:3001" }
|
10
|
+
let(:request) { Typhoeus::Request.new(base_url, {:method => :get}) }
|
11
|
+
let(:response) { Typhoeus::Response.new(:response_code => 0, :return_code => 0, :mock => true) }
|
12
|
+
let(:serialized_response) { Marshal.dump(response) }
|
13
|
+
|
14
|
+
describe "#set" do
|
15
|
+
it "sends the serialized request to Redis" do
|
16
|
+
expect(redis).to receive(:set).with(request.cache_key, serialized_response)
|
17
|
+
expect(redis).to_not receive(:expire).with(request.cache_key, request.cache_ttl)
|
18
|
+
|
19
|
+
cache.set(request, response)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#get" do
|
24
|
+
it "returns nil when the key is not in Redis" do
|
25
|
+
expect(redis).to receive(:get).with(request.cache_key).and_return(nil)
|
26
|
+
|
27
|
+
expect(cache.get(request)).to be_nil
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns the cached response when the key is in Redis" do
|
31
|
+
expect(redis).to receive(:get).with(request.cache_key).and_return(serialized_response)
|
32
|
+
|
33
|
+
result = cache.get(request)
|
34
|
+
expect(result).to_not be_nil
|
35
|
+
expect(result.response_code).to eq(response.response_code)
|
36
|
+
expect(result.return_code).to eq(response.return_code)
|
37
|
+
expect(result.headers).to eq(response.headers)
|
38
|
+
expect(result.body).to eq(response.body)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Typhoeus::Config do
|
4
4
|
let(:config) { Typhoeus::Config }
|
5
5
|
|
6
|
-
[:block_connection, :memoize, :verbose, :cache, :user_agent].each do |name|
|
6
|
+
[:block_connection, :memoize, :verbose, :cache, :user_agent, :proxy].each do |name|
|
7
7
|
it "responds to #{name}" do
|
8
8
|
expect(config).to respond_to(name)
|
9
9
|
end
|
@@ -104,6 +104,12 @@ describe Typhoeus::EasyFactory do
|
|
104
104
|
end
|
105
105
|
|
106
106
|
describe "#set_callback" do
|
107
|
+
it "sets easy.on_progress callback when an on_progress callback is provided" do
|
108
|
+
request.on_progress { 1 }
|
109
|
+
expect(easy_factory.easy).to receive(:on_progress)
|
110
|
+
easy_factory.send(:set_callback)
|
111
|
+
end
|
112
|
+
|
107
113
|
it "sets easy.on_complete callback" do
|
108
114
|
expect(easy_factory.easy).to receive(:on_complete)
|
109
115
|
easy_factory.send(:set_callback)
|