typhoeus 1.0.2 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +11 -8
  3. data/CHANGELOG.md +29 -1
  4. data/CONTRIBUTING.md +4 -0
  5. data/Gemfile +10 -3
  6. data/README.md +66 -41
  7. data/lib/typhoeus/adapters/faraday.rb +29 -9
  8. data/lib/typhoeus/cache/dalli.rb +28 -0
  9. data/lib/typhoeus/cache/rails.rb +28 -0
  10. data/lib/typhoeus/cache/redis.rb +35 -0
  11. data/lib/typhoeus/config.rb +8 -1
  12. data/lib/typhoeus/easy_factory.rb +7 -2
  13. data/lib/typhoeus/hydra/cacheable.rb +1 -1
  14. data/lib/typhoeus/request/actions.rb +7 -7
  15. data/lib/typhoeus/request/cacheable.rb +14 -3
  16. data/lib/typhoeus/request/callbacks.rb +21 -3
  17. data/lib/typhoeus/request/marshal.rb +2 -2
  18. data/lib/typhoeus/request/streamable.rb +1 -1
  19. data/lib/typhoeus/request.rb +2 -0
  20. data/lib/typhoeus/response/header.rb +12 -5
  21. data/lib/typhoeus/response/informations.rb +7 -3
  22. data/lib/typhoeus/response/status.rb +22 -2
  23. data/lib/typhoeus/response.rb +1 -1
  24. data/lib/typhoeus/version.rb +1 -1
  25. data/lib/typhoeus.rb +19 -3
  26. data/spec/typhoeus/adapters/faraday_spec.rb +237 -191
  27. data/spec/typhoeus/cache/dalli_spec.rb +41 -0
  28. data/spec/typhoeus/cache/redis_spec.rb +41 -0
  29. data/spec/typhoeus/config_spec.rb +1 -1
  30. data/spec/typhoeus/easy_factory_spec.rb +6 -0
  31. data/spec/typhoeus/hydra/cacheable_spec.rb +31 -1
  32. data/spec/typhoeus/pool_spec.rb +4 -2
  33. data/spec/typhoeus/request/cacheable_spec.rb +24 -0
  34. data/spec/typhoeus/request/callbacks_spec.rb +2 -2
  35. data/spec/typhoeus/request/marshal_spec.rb +1 -1
  36. data/spec/typhoeus/request_spec.rb +21 -3
  37. data/spec/typhoeus/response/header_spec.rb +51 -1
  38. data/spec/typhoeus/response/informations_spec.rb +12 -1
  39. data/spec/typhoeus/response/status_spec.rb +54 -0
  40. metadata +10 -3
@@ -1,292 +1,338 @@
1
- require 'spec_helper'
2
- require 'typhoeus/adapters/faraday'
3
-
4
- describe Faraday::Adapter::Typhoeus do
5
- let(:base_url) { "http://localhost:3001" }
6
- let(:adapter) { described_class.new }
7
- let(:request) { Typhoeus::Request.new(base_url) }
8
- let(:conn) do
9
- Faraday.new(:url => base_url) do |faraday|
10
- faraday.adapter :typhoeus
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
- end
13
- let(:response) { conn.get("/") }
14
+ let(:response) { conn.get("/") }
14
15
 
15
- context "when parallel" do
16
- it "returns a faraday response" do
17
- response = nil
18
- conn.in_parallel { response = conn.get("/") }
19
- expect(response).to be_a(Faraday::Response)
20
- end
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
- it "succeeds" do
23
- response = nil
24
- conn.in_parallel { response = conn.get("/") }
25
- expect(response.status).to be(200)
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
- context "when not parallel" do
30
- it "returns a faraday response" do
31
- expect(response).to be_a(Faraday::Response)
32
- end
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
- it "succeeds" do
35
- expect(response.status).to be(200)
35
+ it "succeeds" do
36
+ expect(response.status).to be(200)
37
+ end
36
38
  end
37
- end
38
39
 
39
- context "when a response is stubbed" do
40
- before do
41
- stub = Typhoeus::Response.new \
42
- :code => 200,
43
- :headers => { "Foo" => "2", "Bar" => "3" },
44
- :body => "Hello",
45
- :mock => true
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
- Typhoeus.stub(base_url + '/').and_return(stub)
48
- end
48
+ Typhoeus.stub(base_url + '/').and_return(stub)
49
+ end
49
50
 
50
- it 'stubs the status code' do
51
- expect(response.status).to eq(200)
52
- end
51
+ it 'stubs the status code' do
52
+ expect(response.status).to eq(200)
53
+ end
53
54
 
54
- it 'stubs the response body' do
55
- expect(response.body).to eq("Hello")
56
- end
55
+ it 'stubs the response body' do
56
+ expect(response.body).to eq("Hello")
57
+ end
57
58
 
58
- it 'stubs the headers' do
59
- expect(response.headers).to eq("Foo" => "2", "Bar" => "3")
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
- describe "#perform_request" do
64
- let(:env) { {} }
64
+ describe "#initialize" do
65
+ let(:request) { adapter.method(:typhoeus_request).call({}) }
65
66
 
66
- context "when body" do
67
- let(:env) { { :body => double(:read => "body") } }
67
+ context "when typhoeus request options specified" do
68
+ let(:adapter) { described_class.new(nil, { :forbid_reuse => true, :maxredirs => 1 }) }
68
69
 
69
- it "reads body" do
70
- expect(adapter.method(:read_body).call(env)).to eq("body")
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
- context "parallel_manager" do
75
- context "when given" do
76
- let(:env) { { :parallel_manager => double(:queue => true), :ssl => {}, :request => {} } }
77
+ describe "#perform_request" do
78
+ let(:env) { {} }
77
79
 
78
- it "uses" do
79
- adapter.method(:perform_request).call(env)
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 "when not given" do
84
- let(:env) { { :method => :get, :ssl => {}, :request => {} } }
88
+ context "parallel_manager" do
89
+ context "when given" do
90
+ let(:env) { { :parallel_manager => double(:queue => true), :ssl => {}, :request => {} } }
85
91
 
86
- it "falls back to single" do
87
- expect(Typhoeus::Request).to receive(:new).and_return(double(:options => {}, :on_complete => [], :run => true))
88
- adapter.method(:perform_request).call(env)
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
- describe "#request" do
95
- let(:env) do
96
- { :url => "url", :method => :get, :body => "body", :request_headers => {}, :ssl => {}, :request => {} }
97
- end
108
+ describe "#request" do
109
+ let(:env) do
110
+ { :url => "url", :method => :get, :body => "body", :request_headers => {}, :ssl => {}, :request => {} }
111
+ end
98
112
 
99
- let(:request) { adapter.method(:request).call(env) }
113
+ let(:request) { adapter.method(:request).call(env) }
100
114
 
101
- it "returns request" do
102
- expect(request).to be_a(Typhoeus::Request)
103
- end
115
+ it "returns request" do
116
+ expect(request).to be_a(Typhoeus::Request)
117
+ end
104
118
 
105
- it "sets url" do
106
- expect(request.base_url).to eq("url")
107
- end
119
+ it "sets url" do
120
+ expect(request.base_url).to eq("url")
121
+ end
108
122
 
109
- it "sets http method" do
110
- expect(request.original_options[:method]).to eq(:get)
111
- end
123
+ it "sets http method" do
124
+ expect(request.original_options[:method]).to eq(:get)
125
+ end
112
126
 
113
- it "sets body" do
114
- expect(request.original_options[:body]).to eq("body")
115
- end
127
+ it "sets body" do
128
+ expect(request.original_options[:body]).to eq("body")
129
+ end
116
130
 
117
- it "sets headers" do
118
- expect(request.original_options[:headers]).to eq({})
119
- end
131
+ it "sets headers" do
132
+ expect(request.original_options[:headers]).to eq({})
133
+ end
120
134
 
121
- it "sets on_complete callback" do
122
- expect(request.on_complete.size).to eq(1)
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
- before { adapter.method(:configure_socket).call(request, env) }
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
- context "when host" do
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
- describe "#configure_timeout" do
139
- before { adapter.method(:configure_timeout).call(request, env) }
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
- context "when timeout" do
142
- let(:env) { { :request => { :timeout => 1 } } }
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
- it "sets timeout_ms" do
145
- expect(request.options[:timeout_ms]).to eq(1000)
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
- context "when open_timeout" do
150
- let(:env) { { :request => { :open_timeout => 1 } } }
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
- it "sets connecttimeout_ms" do
153
- expect(request.options[:connecttimeout_ms]).to eq(1000)
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
- describe "#configure_proxy" do
159
- before { adapter.method(:configure_proxy).call(request, env) }
183
+ describe "#configure_timeout" do
184
+ before { adapter.method(:configure_timeout).call(request, env) }
160
185
 
161
- context "when proxy" do
162
- let(:env) { { :request => { :proxy => { :uri => double(:scheme => 'http', :host => "localhost", :port => "3001") } } } }
186
+ context "when timeout" do
187
+ let(:env) { { :request => { :timeout => 1 } } }
163
188
 
164
- it "sets proxy" do
165
- expect(request.options[:proxy]).to eq("http://localhost:3001")
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 username and password" do
169
- let(:env) do
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 proxyuserpwd" do
178
- expect(request.options[:proxyuserpwd]).to eq("a:b")
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
- describe "#configure_ssl" do
185
- before { adapter.method(:configure_ssl).call(request, env) }
203
+ describe "#configure_proxy" do
204
+ before { adapter.method(:configure_proxy).call(request, env) }
186
205
 
187
- context "when version" do
188
- let(:env) { { :ssl => { :version => "a" } } }
206
+ context "when proxy" do
207
+ let(:env) { { :request => { :proxy => { :uri => double(:scheme => 'http', :host => "localhost", :port => "3001") } } } }
189
208
 
190
- it "sets sslversion" do
191
- expect(request.options[:sslversion]).to eq("a")
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
- context "when client_cert" do
196
- let(:env) { { :ssl => { :client_cert => "a" } } }
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
- it "sets sslcert" do
199
- expect(request.options[:sslcert]).to eq("a")
235
+ it "sets sslversion" do
236
+ expect(request.options[:sslversion]).to eq("a")
237
+ end
200
238
  end
201
- end
202
239
 
203
- context "when client_key" do
204
- let(:env) { { :ssl => { :client_key => "a" } } }
240
+ context "when client_cert" do
241
+ let(:env) { { :ssl => { :client_cert => "a" } } }
205
242
 
206
- it "sets sslkey" do
207
- expect(request.options[:sslkey]).to eq("a")
243
+ it "sets sslcert" do
244
+ expect(request.options[:sslcert]).to eq("a")
245
+ end
208
246
  end
209
- end
210
247
 
211
- context "when ca_file" do
212
- let(:env) { { :ssl => { :ca_file => "a" } } }
248
+ context "when client_key" do
249
+ let(:env) { { :ssl => { :client_key => "a" } } }
213
250
 
214
- it "sets cainfo" do
215
- expect(request.options[:cainfo]).to eq("a")
251
+ it "sets sslkey" do
252
+ expect(request.options[:sslkey]).to eq("a")
253
+ end
216
254
  end
217
- end
218
255
 
219
- context "when ca_path" do
220
- let(:env) { { :ssl => { :ca_path => "a" } } }
256
+ context "when ca_file" do
257
+ let(:env) { { :ssl => { :ca_file => "a" } } }
221
258
 
222
- it "sets capath" do
223
- expect(request.options[:capath]).to eq("a")
259
+ it "sets cainfo" do
260
+ expect(request.options[:cainfo]).to eq("a")
261
+ end
224
262
  end
225
- end
226
263
 
227
- context "when client_cert_passwd" do
228
- let(:env) { { :ssl => { :client_cert_passwd => "a" } } }
264
+ context "when ca_path" do
265
+ let(:env) { { :ssl => { :ca_path => "a" } } }
229
266
 
230
- it "sets keypasswd to the value of client_cert_passwd" do
231
- expect(request.options[:keypasswd]).to eq("a")
267
+ it "sets capath" do
268
+ expect(request.options[:capath]).to eq("a")
269
+ end
232
270
  end
233
- end
234
271
 
235
- context "when client_certificate_password" do
236
- let(:env) { { :ssl => { :client_certificate_password => "a" } } }
272
+ context "when client_cert_passwd" do
273
+ let(:env) { { :ssl => { :client_cert_passwd => "a" } } }
237
274
 
238
- it "sets keypasswd to the value of client_cert_passwd" do
239
- expect(request.options[:keypasswd]).to eq("a")
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
- context "when no client_cert_passwd" do
244
- let(:env) { { :ssl => { } } }
280
+ context "when client_certificate_password" do
281
+ let(:env) { { :ssl => { :client_certificate_password => "a" } } }
245
282
 
246
- it "does not set keypasswd on options" do
247
- expect(request.options).not_to have_key :keypasswd
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
- context "when verify is false" do
252
- let(:env) { { :ssl => { :verify => false } } }
288
+ context "when no client_cert_passwd" do
289
+ let(:env) { { :ssl => { } } }
253
290
 
254
- it "sets ssl_verifyhost to 0" do
255
- expect(request.options[:ssl_verifyhost]).to eq(0)
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
- it "sets ssl_verifypeer to false" do
259
- expect(request.options[:ssl_verifypeer]).to be_falsey
260
- end
261
- end
296
+ context "when verify is false" do
297
+ let(:env) { { :ssl => { :verify => false } } }
262
298
 
263
- context "when verify is true" do
264
- let(:env) { { :ssl => { :verify => true } } }
299
+ it "sets ssl_verifyhost to 0" do
300
+ expect(request.options[:ssl_verifyhost]).to eq(0)
301
+ end
265
302
 
266
- it "sets ssl_verifyhost to 2" do
267
- expect(request.options[:ssl_verifyhost]).to eq(2)
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
- it "sets ssl_verifypeer to true" do
271
- expect(request.options[:ssl_verifypeer]).to be_truthy
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
- describe "#parallel?" do
277
- context "when parallel_manager" do
278
- let(:env) { { :parallel_manager => true } }
321
+ describe "#parallel?" do
322
+ context "when parallel_manager" do
323
+ let(:env) { { :parallel_manager => true } }
279
324
 
280
- it "returns true" do
281
- expect(adapter.method(:parallel?).call(env)).to be_truthy
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
- context "when no parallel_manager" do
286
- let(:env) { { :parallel_manager => nil } }
330
+ context "when no parallel_manager" do
331
+ let(:env) { { :parallel_manager => nil } }
287
332
 
288
- it "returns false" do
289
- expect(adapter.method(:parallel?).call(env)).to be_falsey
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)