typhoeus 1.4.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +43 -1
- data/lib/typhoeus/expectation.rb +4 -2
- data/lib/typhoeus/request/responseable.rb +1 -1
- data/lib/typhoeus/version.rb +1 -1
- data/typhoeus.gemspec +14 -4
- metadata +18 -97
- data/.github/workflows/ci.yml +0 -30
- data/.github/workflows/experimental.yml +0 -33
- data/.gitignore +0 -8
- data/.rspec +0 -4
- data/Gemfile +0 -36
- data/Guardfile +0 -9
- data/Rakefile +0 -38
- data/perf/profile.rb +0 -14
- data/perf/vs_nethttp.rb +0 -64
- data/spec/rack/typhoeus/middleware/params_decoder/helper_spec.rb +0 -156
- data/spec/rack/typhoeus/middleware/params_decoder_spec.rb +0 -31
- data/spec/spec_helper.rb +0 -29
- data/spec/support/localhost_server.rb +0 -94
- data/spec/support/memory_cache.rb +0 -15
- data/spec/support/server.rb +0 -116
- data/spec/typhoeus/adapters/faraday_spec.rb +0 -339
- data/spec/typhoeus/cache/dalli_spec.rb +0 -41
- data/spec/typhoeus/cache/redis_spec.rb +0 -41
- data/spec/typhoeus/config_spec.rb +0 -15
- data/spec/typhoeus/easy_factory_spec.rb +0 -143
- data/spec/typhoeus/errors/no_stub_spec.rb +0 -13
- data/spec/typhoeus/expectation_spec.rb +0 -280
- data/spec/typhoeus/hydra/addable_spec.rb +0 -22
- data/spec/typhoeus/hydra/before_spec.rb +0 -98
- data/spec/typhoeus/hydra/block_connection_spec.rb +0 -18
- data/spec/typhoeus/hydra/cacheable_spec.rb +0 -88
- data/spec/typhoeus/hydra/memoizable_spec.rb +0 -53
- data/spec/typhoeus/hydra/queueable_spec.rb +0 -98
- data/spec/typhoeus/hydra/runnable_spec.rb +0 -137
- data/spec/typhoeus/hydra/stubbable_spec.rb +0 -48
- data/spec/typhoeus/hydra_spec.rb +0 -22
- data/spec/typhoeus/pool_spec.rb +0 -137
- data/spec/typhoeus/request/actions_spec.rb +0 -19
- data/spec/typhoeus/request/before_spec.rb +0 -93
- data/spec/typhoeus/request/block_connection_spec.rb +0 -75
- data/spec/typhoeus/request/cacheable_spec.rb +0 -94
- data/spec/typhoeus/request/callbacks_spec.rb +0 -91
- data/spec/typhoeus/request/marshal_spec.rb +0 -60
- data/spec/typhoeus/request/memoizable_spec.rb +0 -34
- data/spec/typhoeus/request/operations_spec.rb +0 -101
- data/spec/typhoeus/request/responseable_spec.rb +0 -13
- data/spec/typhoeus/request/stubbable_spec.rb +0 -45
- data/spec/typhoeus/request_spec.rb +0 -256
- data/spec/typhoeus/response/header_spec.rb +0 -147
- data/spec/typhoeus/response/informations_spec.rb +0 -323
- data/spec/typhoeus/response/status_spec.rb +0 -256
- data/spec/typhoeus/response_spec.rb +0 -100
- data/spec/typhoeus_spec.rb +0 -105
@@ -1,137 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Typhoeus::Hydra::Runnable do
|
4
|
-
let(:base_url) { "localhost:3001" }
|
5
|
-
let(:options) { {} }
|
6
|
-
let(:hydra) { Typhoeus::Hydra.new(options) }
|
7
|
-
let(:receive_counter) { double :mark => :twain }
|
8
|
-
|
9
|
-
describe "#run" do
|
10
|
-
let(:requests) { [] }
|
11
|
-
|
12
|
-
before do
|
13
|
-
requests.each { |r| hydra.queue r }
|
14
|
-
end
|
15
|
-
|
16
|
-
it "runs multi#dequeue_many" do
|
17
|
-
expect(hydra).to receive(:dequeue_many)
|
18
|
-
hydra.run
|
19
|
-
end
|
20
|
-
|
21
|
-
it "runs multi#perform" do
|
22
|
-
expect(hydra.multi).to receive(:perform)
|
23
|
-
hydra.run
|
24
|
-
end
|
25
|
-
|
26
|
-
context "when request queued" do
|
27
|
-
let(:first) { Typhoeus::Request.new("localhost:3001/first") }
|
28
|
-
let(:requests) { [first] }
|
29
|
-
|
30
|
-
it "sends" do
|
31
|
-
hydra.run
|
32
|
-
expect(first.response).to be
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context "when three request queued" do
|
37
|
-
let(:first) { Typhoeus::Request.new("localhost:3001/first") }
|
38
|
-
let(:second) { Typhoeus::Request.new("localhost:3001/second") }
|
39
|
-
let(:third) { Typhoeus::Request.new("localhost:3001/third") }
|
40
|
-
let(:requests) { [first, second, third] }
|
41
|
-
|
42
|
-
it "sends first" do
|
43
|
-
hydra.run
|
44
|
-
expect(first.response).to be
|
45
|
-
end
|
46
|
-
|
47
|
-
it "sends second" do
|
48
|
-
hydra.run
|
49
|
-
expect(second.response).to be
|
50
|
-
end
|
51
|
-
|
52
|
-
it "sends third" do
|
53
|
-
hydra.run
|
54
|
-
expect(third.response).to be
|
55
|
-
end
|
56
|
-
|
57
|
-
it "sends first first" do
|
58
|
-
first.on_complete do
|
59
|
-
expect(second.response).to be_nil
|
60
|
-
expect(third.response).to be_nil
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
it "sends second second" do
|
65
|
-
first.on_complete do
|
66
|
-
expect(first.response).to be
|
67
|
-
expect(third.response).to be_nil
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
it "sends thirds last" do
|
72
|
-
first.on_complete do
|
73
|
-
expect(second.response).to be
|
74
|
-
expect(third.response).to be
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
context "when really queued request" do
|
80
|
-
let(:options) { {:max_concurrency => 1} }
|
81
|
-
let(:first) { Typhoeus::Request.new("localhost:3001/first") }
|
82
|
-
let(:second) { Typhoeus::Request.new("localhost:3001/second") }
|
83
|
-
let(:third) { Typhoeus::Request.new("localhost:3001/third") }
|
84
|
-
let(:requests) { [first, second, third] }
|
85
|
-
|
86
|
-
it "sends first" do
|
87
|
-
hydra.run
|
88
|
-
expect(first.response).to be
|
89
|
-
end
|
90
|
-
|
91
|
-
it "sends second" do
|
92
|
-
hydra.run
|
93
|
-
expect(second.response).to be
|
94
|
-
end
|
95
|
-
|
96
|
-
it "sends third" do
|
97
|
-
hydra.run
|
98
|
-
expect(third.response).to be
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
context "when request queued in callback" do
|
103
|
-
let(:first) do
|
104
|
-
Typhoeus::Request.new("localhost:3001/first").tap do |r|
|
105
|
-
r.on_complete{ hydra.queue(second) }
|
106
|
-
end
|
107
|
-
end
|
108
|
-
let(:second) { Typhoeus::Request.new("localhost:3001/second") }
|
109
|
-
let(:requests) { [first] }
|
110
|
-
|
111
|
-
before { Typhoeus.on_complete { |r| receive_counter.mark } }
|
112
|
-
after { Typhoeus.on_complete.clear; Typhoeus.before.clear }
|
113
|
-
|
114
|
-
context "when real request" do
|
115
|
-
context "when max_concurrency default" do
|
116
|
-
let(:options) { {} }
|
117
|
-
|
118
|
-
it "calls on_complete callback once for every response" do
|
119
|
-
expect(receive_counter).to receive(:mark).exactly(2).times
|
120
|
-
hydra.run
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context "when no real request" do
|
126
|
-
context "when before hook returns and finishes response" do
|
127
|
-
before { Typhoeus.before{ |request| request.finish(Typhoeus::Response.new) } }
|
128
|
-
|
129
|
-
it "simulates real multi run and adds and finishes both requests" do
|
130
|
-
expect(receive_counter).to receive(:mark).exactly(2).times
|
131
|
-
hydra.run
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Typhoeus::Hydra::Stubbable do
|
4
|
-
let(:base_url) { "localhost:3001" }
|
5
|
-
let(:request) { Typhoeus::Request.new(base_url) }
|
6
|
-
let(:response) { Typhoeus::Response.new }
|
7
|
-
let(:hydra) { Typhoeus::Hydra.new }
|
8
|
-
|
9
|
-
before { Typhoeus.stub(base_url).and_return(response) }
|
10
|
-
|
11
|
-
describe "#add" do
|
12
|
-
it "checks expectations" do
|
13
|
-
hydra.add(request)
|
14
|
-
end
|
15
|
-
|
16
|
-
context "when expectation found" do
|
17
|
-
it "calls on_headers callbacks" do
|
18
|
-
canary = :not_called
|
19
|
-
request.on_headers do
|
20
|
-
canary = :called
|
21
|
-
end
|
22
|
-
hydra.add(request)
|
23
|
-
hydra.run
|
24
|
-
expect(canary).to eq(:called)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "calls on_body callbacks" do
|
28
|
-
canary = :not_called
|
29
|
-
request.on_body do
|
30
|
-
canary = :called
|
31
|
-
end
|
32
|
-
hydra.add(request)
|
33
|
-
hydra.run
|
34
|
-
expect(canary).to eq(:called)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "finishes response" do
|
38
|
-
expect(request).to receive(:finish)
|
39
|
-
hydra.add(request)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "is a mock" do
|
43
|
-
hydra.add(request)
|
44
|
-
expect(request.response.mock).to be(true)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
data/spec/typhoeus/hydra_spec.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe Typhoeus::Hydra do
|
4
|
-
let(:base_url) { "localhost:3001" }
|
5
|
-
let(:options) { {} }
|
6
|
-
let(:hydra) { Typhoeus::Hydra.new(options) }
|
7
|
-
|
8
|
-
describe "#new" do
|
9
|
-
let(:options) { {:pipeling => true} }
|
10
|
-
|
11
|
-
it "passes options to multi" do
|
12
|
-
expect(Ethon::Multi).to receive(:new).with(options)
|
13
|
-
hydra
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "#hydra" do
|
18
|
-
it "returns a hydra" do
|
19
|
-
expect(Typhoeus::Hydra.hydra).to be_a(Typhoeus::Hydra)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/spec/typhoeus/pool_spec.rb
DELETED
@@ -1,137 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Typhoeus::Pool do
|
4
|
-
let(:easy) { Ethon::Easy.new }
|
5
|
-
after { Typhoeus::Pool.clear }
|
6
|
-
|
7
|
-
describe "#easies" do
|
8
|
-
it "returns array" do
|
9
|
-
expect(Typhoeus::Pool.send(:easies)).to be_a(Array)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "#release" do
|
14
|
-
it "resets easy" do
|
15
|
-
expect(easy).to receive(:reset)
|
16
|
-
Typhoeus::Pool.release(easy)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "flush cookies to disk" do
|
20
|
-
expect(easy).to receive(:cookielist=).with('flush')
|
21
|
-
expect(easy).to receive(:reset)
|
22
|
-
expect(easy).to receive(:cookielist=).with('all')
|
23
|
-
Typhoeus::Pool.release(easy)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "writes cookies to disk" do
|
27
|
-
tempfile1 = Tempfile.new('cookies')
|
28
|
-
tempfile2 = Tempfile.new('cookies')
|
29
|
-
|
30
|
-
easy.cookiejar = tempfile1.path
|
31
|
-
easy.url = "localhost:3001/cookies-test"
|
32
|
-
easy.perform
|
33
|
-
|
34
|
-
Typhoeus::Pool.release(easy)
|
35
|
-
|
36
|
-
expect(File.zero?(tempfile1.path)).to be(false)
|
37
|
-
expect(File.read(tempfile1.path)).to match(/\s+foo\s+bar$/)
|
38
|
-
expect(File.read(tempfile1.path)).to match(/\s+bar\s+foo$/)
|
39
|
-
|
40
|
-
# do it again - and check if tempfile1 wasn't change
|
41
|
-
easy.cookiejar = tempfile2.path
|
42
|
-
easy.url = "localhost:3001/cookies-test2"
|
43
|
-
easy.perform
|
44
|
-
|
45
|
-
Typhoeus::Pool.release(easy)
|
46
|
-
|
47
|
-
# tempfile 1
|
48
|
-
expect(File.zero?(tempfile1.path)).to be(false)
|
49
|
-
expect(File.read(tempfile1.path)).to match(/\s+foo\s+bar$/)
|
50
|
-
expect(File.read(tempfile1.path)).to match(/\s+bar\s+foo$/)
|
51
|
-
|
52
|
-
# tempfile2
|
53
|
-
expect(File.zero?(tempfile2.path)).to be(false)
|
54
|
-
expect(File.read(tempfile2.path)).to match(/\s+foo2\s+bar$/)
|
55
|
-
expect(File.read(tempfile2.path)).to match(/\s+bar2\s+foo$/)
|
56
|
-
end
|
57
|
-
|
58
|
-
it "puts easy back into pool" do
|
59
|
-
Typhoeus::Pool.release(easy)
|
60
|
-
expect(Typhoeus::Pool.send(:easies)).to include(easy)
|
61
|
-
end
|
62
|
-
|
63
|
-
context "when threaded access" do
|
64
|
-
it "releases correct number of easies" do
|
65
|
-
(0..9).map do |n|
|
66
|
-
Thread.new do
|
67
|
-
Typhoeus::Pool.release(Ethon::Easy.new)
|
68
|
-
end
|
69
|
-
end.map(&:join)
|
70
|
-
expect(Typhoeus::Pool.send(:easies).size).to eq(10)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe "#get" do
|
76
|
-
context "when easy in pool" do
|
77
|
-
before { Typhoeus::Pool.send(:easies) << easy }
|
78
|
-
|
79
|
-
it "takes" do
|
80
|
-
expect(Typhoeus::Pool.get).to eq(easy)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context "when no easy in pool" do
|
85
|
-
it "creates" do
|
86
|
-
expect(Typhoeus::Pool.get).to be_a(Ethon::Easy)
|
87
|
-
end
|
88
|
-
|
89
|
-
context "when threaded access" do
|
90
|
-
it "creates correct number of easies" do
|
91
|
-
queue = Queue.new
|
92
|
-
(0..9).map do |n|
|
93
|
-
Thread.new do
|
94
|
-
queue.enq(Typhoeus::Pool.get)
|
95
|
-
end
|
96
|
-
end.map(&:join)
|
97
|
-
|
98
|
-
array = Array.new(queue.size) { queue.pop }
|
99
|
-
expect(array.uniq.size).to eq(10)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context "when forked" do
|
105
|
-
before do
|
106
|
-
allow(Process).to receive(:pid).and_return(1)
|
107
|
-
Typhoeus::Pool.send(:easies) << easy
|
108
|
-
allow(Process).to receive(:pid).and_return(2)
|
109
|
-
end
|
110
|
-
|
111
|
-
after do
|
112
|
-
allow(Process).to receive(:pid).and_call_original
|
113
|
-
Typhoeus::Pool.instance_variable_set(:@pid, Process.pid)
|
114
|
-
end
|
115
|
-
|
116
|
-
it "creates" do
|
117
|
-
expect(Typhoeus::Pool.get).to_not eq(easy)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
describe "#with" do
|
123
|
-
it "is re-entrant" do
|
124
|
-
array = []
|
125
|
-
Typhoeus::Pool.with_easy do |e1|
|
126
|
-
array << e1
|
127
|
-
Typhoeus::Pool.with_easy do |e2|
|
128
|
-
array << e2
|
129
|
-
Typhoeus::Pool.with_easy do |e3|
|
130
|
-
array << e3
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
expect(array.uniq.size).to eq(3)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Typhoeus::Request::Actions do
|
4
|
-
[:get, :post, :put, :delete, :head, :patch, :options].each do |name|
|
5
|
-
describe ".#{name}" do
|
6
|
-
let(:response) { Typhoeus::Request.method(name).call("http://localhost:3001") }
|
7
|
-
|
8
|
-
it "returns ok" do
|
9
|
-
expect(response.return_code).to eq(:ok)
|
10
|
-
end
|
11
|
-
|
12
|
-
unless name == :head
|
13
|
-
it "makes #{name.to_s.upcase} Request" do
|
14
|
-
expect(response.response_body).to include("\"REQUEST_METHOD\":\"#{name.to_s.upcase}\"")
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,93 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Typhoeus::Request::Before do
|
4
|
-
let(:request) { Typhoeus::Request.new("") }
|
5
|
-
let(:receive_counter) { double :mark => :twain }
|
6
|
-
|
7
|
-
describe "#queue" do
|
8
|
-
context "when before" do
|
9
|
-
context "when one" do
|
10
|
-
it "executes" do
|
11
|
-
Typhoeus.before { |r| receive_counter.mark }
|
12
|
-
expect(receive_counter).to receive(:mark)
|
13
|
-
request.run
|
14
|
-
end
|
15
|
-
|
16
|
-
context "when true" do
|
17
|
-
it "calls super" do
|
18
|
-
Typhoeus.before { true }
|
19
|
-
expect(Typhoeus::Expectation).to receive(:response_for)
|
20
|
-
request.run
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "when false" do
|
25
|
-
it "doesn't call super" do
|
26
|
-
Typhoeus.before { false }
|
27
|
-
expect(Typhoeus::Expectation).to receive(:response_for).never
|
28
|
-
request.run
|
29
|
-
end
|
30
|
-
|
31
|
-
it "returns response" do
|
32
|
-
Typhoeus.before { |r| r.response = 1; false }
|
33
|
-
expect(request.run).to be(1)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "when a response" do
|
38
|
-
it "doesn't call super" do
|
39
|
-
Typhoeus.before { Typhoeus::Response.new }
|
40
|
-
expect(Typhoeus::Expectation).to receive(:response_for).never
|
41
|
-
request.run
|
42
|
-
end
|
43
|
-
|
44
|
-
it "returns response" do
|
45
|
-
Typhoeus.before { |r| r.response = Typhoeus::Response.new }
|
46
|
-
expect(request.run).to be_a(Typhoeus::Response)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context "when multi" do
|
52
|
-
context "when all true" do
|
53
|
-
before { 3.times { Typhoeus.before { |r| receive_counter.mark } } }
|
54
|
-
|
55
|
-
it "calls super" do
|
56
|
-
expect(Typhoeus::Expectation).to receive(:response_for)
|
57
|
-
request.run
|
58
|
-
end
|
59
|
-
|
60
|
-
it "executes all" do
|
61
|
-
expect(receive_counter).to receive(:mark).exactly(3)
|
62
|
-
request.run
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
context "when middle false" do
|
67
|
-
before do
|
68
|
-
Typhoeus.before { |r| receive_counter.mark }
|
69
|
-
Typhoeus.before { |r| receive_counter.mark; nil }
|
70
|
-
Typhoeus.before { |r| receive_counter.mark }
|
71
|
-
end
|
72
|
-
|
73
|
-
it "doesn't call super" do
|
74
|
-
expect(Typhoeus::Expectation).to receive(:response_for).never
|
75
|
-
request.run
|
76
|
-
end
|
77
|
-
|
78
|
-
it "executes only two" do
|
79
|
-
expect(receive_counter).to receive(:mark).exactly(2).times
|
80
|
-
request.run
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context "when no before" do
|
87
|
-
it "calls super" do
|
88
|
-
expect(Typhoeus::Expectation).to receive(:response_for)
|
89
|
-
request.run
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Typhoeus::Request::BlockConnection do
|
4
|
-
let(:base_url) { "localhost:3001" }
|
5
|
-
let(:request) { Typhoeus::Request.new(base_url, {:method => :get}) }
|
6
|
-
|
7
|
-
describe "run" do
|
8
|
-
context "when blocked" do
|
9
|
-
before { request.block_connection = true }
|
10
|
-
|
11
|
-
it "raises" do
|
12
|
-
expect{ request.run }.to raise_error(Typhoeus::Errors::NoStub)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context "when not blocked" do
|
17
|
-
before { request.block_connection = false }
|
18
|
-
|
19
|
-
it "doesn't raise" do
|
20
|
-
expect{ request.run }.to_not raise_error
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "#blocked?" do
|
26
|
-
context "when local block_connection" do
|
27
|
-
context "when true" do
|
28
|
-
before { request.block_connection = true }
|
29
|
-
|
30
|
-
it "returns true" do
|
31
|
-
expect(request.blocked?).to be_truthy
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "when false" do
|
36
|
-
before { request.block_connection = false }
|
37
|
-
|
38
|
-
it "returns false" do
|
39
|
-
expect(request.blocked?).to be_falsey
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context "when global block_connection" do
|
45
|
-
context "when true" do
|
46
|
-
before { Typhoeus::Config.block_connection = true }
|
47
|
-
after { Typhoeus::Config.block_connection = false }
|
48
|
-
|
49
|
-
it "returns true" do
|
50
|
-
expect(request.blocked?).to be_truthy
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context "when false" do
|
55
|
-
before { Typhoeus::Config.block_connection = false }
|
56
|
-
|
57
|
-
it "returns false" do
|
58
|
-
expect(request.blocked?).to be_falsey
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "when global and local block_connection" do
|
64
|
-
before do
|
65
|
-
Typhoeus::Config.block_connection = true
|
66
|
-
request.block_connection = false
|
67
|
-
end
|
68
|
-
after { Typhoeus::Config.block_connection = false }
|
69
|
-
|
70
|
-
it "takes local" do
|
71
|
-
expect(request.blocked?).to be_falsey
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,94 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Typhoeus::Request::Cacheable do
|
4
|
-
let(:cache) { MemoryCache.new }
|
5
|
-
let(:options) { {} }
|
6
|
-
let(:request) { Typhoeus::Request.new("http://localhost:3001", options) }
|
7
|
-
let(:response) { Typhoeus::Response.new }
|
8
|
-
|
9
|
-
before { Typhoeus::Config.cache = cache }
|
10
|
-
after { Typhoeus::Config.cache = false }
|
11
|
-
|
12
|
-
describe "#response=" do
|
13
|
-
context "when cache activated" do
|
14
|
-
context "when request new" do
|
15
|
-
it "caches response" do
|
16
|
-
request.response = response
|
17
|
-
expect(cache.memory[request]).to be
|
18
|
-
end
|
19
|
-
|
20
|
-
it "doesn't set cached on response" do
|
21
|
-
request.response = response
|
22
|
-
expect(request.response.cached?).to be_falsey
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "when request in memory" do
|
27
|
-
before { cache.memory[request] = response }
|
28
|
-
|
29
|
-
it "finishes request" do
|
30
|
-
expect(request).to receive(:finish).with(response)
|
31
|
-
request.run
|
32
|
-
end
|
33
|
-
|
34
|
-
it "sets cached to true for response" do
|
35
|
-
request.run
|
36
|
-
expect(request.response.cached?).to be_truthy
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "#run" do
|
43
|
-
context "when cache activated" do
|
44
|
-
context "when request new" do
|
45
|
-
it "fetches response" do
|
46
|
-
expect(request.response).to_not be(response)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context "when request in memory" do
|
51
|
-
before { cache.memory[request] = response }
|
52
|
-
|
53
|
-
it "finishes request" do
|
54
|
-
expect(request).to receive(:finish).with(response)
|
55
|
-
request.run
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context "when cache is specified on a request" do
|
60
|
-
before { Typhoeus::Config.cache = false }
|
61
|
-
|
62
|
-
context "when cache is false" do
|
63
|
-
let(:options) { { :cache => false } }
|
64
|
-
|
65
|
-
it "finishes request" do
|
66
|
-
expect(request.response).to_not be(response)
|
67
|
-
request.run
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context "when cache is defined" do
|
72
|
-
let(:options) { { :cache => cache } }
|
73
|
-
|
74
|
-
before { cache.memory[request] = response }
|
75
|
-
|
76
|
-
it "finishes request" do
|
77
|
-
expect(request).to receive(:finish).with(response)
|
78
|
-
request.run
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe "#cache_ttl" do
|
86
|
-
context "when option[:cache_ttl]" do
|
87
|
-
let(:options) { {:cache_ttl => 1} }
|
88
|
-
|
89
|
-
it "returns" do
|
90
|
-
expect(request.cache_ttl).to be(1)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|