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,91 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Typhoeus::Request::Callbacks do
|
4
|
-
let(:request) { Typhoeus::Request.new("fubar") }
|
5
|
-
|
6
|
-
[:on_complete, :on_success, :on_failure, :on_progress].each do |callback|
|
7
|
-
describe "##{callback}" do
|
8
|
-
it "responds" do
|
9
|
-
expect(request).to respond_to(callback)
|
10
|
-
end
|
11
|
-
|
12
|
-
context "when no block given" do
|
13
|
-
it "returns @#{callback}" do
|
14
|
-
expect(request.method(callback).call).to eq([])
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
context "when block given" do
|
19
|
-
it "stores" do
|
20
|
-
request.method(callback).call { p 1 }
|
21
|
-
expect(request.instance_variable_get("@#{callback}").size).to eq(1)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context "when multiple blocks given" do
|
26
|
-
it "stores" do
|
27
|
-
request.method(callback).call { p 1 }
|
28
|
-
request.method(callback).call { p 2 }
|
29
|
-
expect(request.instance_variable_get("@#{callback}").size).to eq(2)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "#execute_callbacks" do
|
36
|
-
[:on_complete, :on_success, :on_failure, :on_progress].each do |callback|
|
37
|
-
context "when #{callback}" do
|
38
|
-
context "when local callback" do
|
39
|
-
before do
|
40
|
-
code = if callback == :on_failure
|
41
|
-
500
|
42
|
-
else
|
43
|
-
200
|
44
|
-
end
|
45
|
-
request.response = Typhoeus::Response.new(:mock => true, :response_code => code)
|
46
|
-
request.method(callback).call {|r| expect(r).to be_a(Typhoeus::Response) }
|
47
|
-
end
|
48
|
-
|
49
|
-
it "executes blocks and passes response" do
|
50
|
-
request.execute_callbacks
|
51
|
-
end
|
52
|
-
|
53
|
-
it "sets handled_response" do
|
54
|
-
request.method(callback).call { 1 }
|
55
|
-
request.execute_callbacks
|
56
|
-
expect(request.response.handled_response).to be(1)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context "when global callback" do
|
61
|
-
before do
|
62
|
-
request.response = Typhoeus::Response.new
|
63
|
-
Typhoeus.method(callback).call {|r| expect(r).to be_a(Typhoeus::Response) }
|
64
|
-
end
|
65
|
-
|
66
|
-
it "executes blocks and passes response" do
|
67
|
-
request.execute_callbacks
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context "when global and local callbacks" do
|
72
|
-
before do
|
73
|
-
request.response = Typhoeus::Response.new
|
74
|
-
Typhoeus.method(callback).call {|r| r.instance_variable_set(:@fu, 1) }
|
75
|
-
request.method(callback).call {|r| expect(r.instance_variable_get(:@fu)).to eq(1) }
|
76
|
-
end
|
77
|
-
|
78
|
-
it "runs global first" do
|
79
|
-
request.execute_callbacks
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context "when local on_complete and gobal on_success" do
|
86
|
-
it "runs all global callbacks first" do
|
87
|
-
skip
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Typhoeus::Request::Marshal do
|
4
|
-
let(:base_url) { "localhost:3001" }
|
5
|
-
let(:request) { Typhoeus::Request.new(base_url) }
|
6
|
-
|
7
|
-
describe "#marshal_dump" do
|
8
|
-
%w(on_complete on_success on_failure on_progress).each do |name|
|
9
|
-
context "when #{name} handler" do
|
10
|
-
before { request.instance_variable_set("@#{name}", Proc.new{}) }
|
11
|
-
|
12
|
-
it "doesn't include @#{name}" do
|
13
|
-
expect(request.send(:marshal_dump).map(&:first)).to_not include("@#{name}")
|
14
|
-
end
|
15
|
-
|
16
|
-
it "doesn't raise when dumped" do
|
17
|
-
expect { Marshal.dump(request) }.to_not raise_error
|
18
|
-
end
|
19
|
-
|
20
|
-
context "when loading" do
|
21
|
-
let(:loaded) { Marshal.load(Marshal.dump(request)) }
|
22
|
-
|
23
|
-
it "includes base_url" do
|
24
|
-
expect(loaded.base_url).to eq(request.base_url)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "doesn't include #{name}" do
|
28
|
-
expect(loaded.instance_variables).to_not include("@#{name}")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'when run through hydra' do
|
35
|
-
let(:options) { {} }
|
36
|
-
let(:hydra) { Typhoeus::Hydra.new(options) }
|
37
|
-
|
38
|
-
before(:each) do
|
39
|
-
hydra.queue(request)
|
40
|
-
hydra.run
|
41
|
-
end
|
42
|
-
|
43
|
-
it "doesn't include @hydra" do
|
44
|
-
expect(request.send(:marshal_dump).map(&:first)).to_not include("@hydra")
|
45
|
-
end
|
46
|
-
|
47
|
-
context 'when loading' do
|
48
|
-
let(:loaded) { Marshal.load(Marshal.dump(request)) }
|
49
|
-
|
50
|
-
it "includes base_url" do
|
51
|
-
expect(loaded.base_url).to eq(request.base_url)
|
52
|
-
end
|
53
|
-
|
54
|
-
it "doesn't include #{name}" do
|
55
|
-
expect(loaded.instance_variables).to_not include("@hydra")
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Typhoeus::Request::Memoizable do
|
4
|
-
let(:options) { {} }
|
5
|
-
let(:request) { Typhoeus::Request.new("fu", options) }
|
6
|
-
let(:response) { Typhoeus::Response.new }
|
7
|
-
let(:hydra) { Typhoeus::Hydra.new }
|
8
|
-
|
9
|
-
describe "#response=" do
|
10
|
-
context "when memoization activated" do
|
11
|
-
before { Typhoeus::Config.memoize = true }
|
12
|
-
after { Typhoeus::Config.memoize = false }
|
13
|
-
|
14
|
-
context "when GET request" do
|
15
|
-
let(:options) { {:method => :get} }
|
16
|
-
before { request.hydra = hydra }
|
17
|
-
|
18
|
-
it "stores response in memory" do
|
19
|
-
request.response = response
|
20
|
-
expect(hydra.memory[request]).to be
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "when no GET request" do
|
25
|
-
let(:options) { {:method => :post} }
|
26
|
-
|
27
|
-
it "doesn't store response in memory" do
|
28
|
-
request.response = response
|
29
|
-
expect(hydra.memory[request]).to be_nil
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Typhoeus::Request::Operations do
|
4
|
-
let(:base_url) { "localhost:3001" }
|
5
|
-
let(:options) { {} }
|
6
|
-
let(:request) { Typhoeus::Request.new(base_url, options) }
|
7
|
-
|
8
|
-
describe "#run" do
|
9
|
-
let(:easy) { Ethon::Easy.new }
|
10
|
-
before { expect(Typhoeus::Pool).to receive(:get).and_return(easy) }
|
11
|
-
|
12
|
-
it "grabs an easy" do
|
13
|
-
request.run
|
14
|
-
end
|
15
|
-
|
16
|
-
it "generates settings" do
|
17
|
-
expect(easy).to receive(:http_request)
|
18
|
-
request.run
|
19
|
-
end
|
20
|
-
|
21
|
-
it "performs" do
|
22
|
-
expect(easy).to receive(:perform)
|
23
|
-
request.run
|
24
|
-
end
|
25
|
-
|
26
|
-
it "sets response" do
|
27
|
-
request.run
|
28
|
-
expect(request.response).to be
|
29
|
-
end
|
30
|
-
|
31
|
-
it "releases easy" do
|
32
|
-
expect(Typhoeus::Pool).to receive(:release)
|
33
|
-
request.run
|
34
|
-
end
|
35
|
-
|
36
|
-
it "calls on_body" do
|
37
|
-
on_body_called = false
|
38
|
-
request.on_body { |body, response| on_body_called = true }
|
39
|
-
request.run
|
40
|
-
expect(on_body_called).to be_truthy
|
41
|
-
expect(request.response.body).to satisfy { |v| v.nil? || v == '' }
|
42
|
-
end
|
43
|
-
|
44
|
-
it "makes response headers available to on_body" do
|
45
|
-
headers = nil
|
46
|
-
request.on_body { |body, response| headers = response.headers }
|
47
|
-
request.run
|
48
|
-
expect(headers).to be
|
49
|
-
expect(headers).to eq(request.response.headers)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "calls on_headers and on_body" do
|
53
|
-
headers = nil
|
54
|
-
request.on_headers { |response| headers = response.headers }
|
55
|
-
request.on_body { |body, response| expect(headers).not_to be_nil ; expect(response.headers).to eq(headers) }
|
56
|
-
request.on_complete { |response| expect(response).not_to be_nil ; expect(response.headers).to eq(headers) ; expect(response.body).to be_empty }
|
57
|
-
request.run
|
58
|
-
end
|
59
|
-
|
60
|
-
it "calls on_headers and on_complete" do
|
61
|
-
headers = nil
|
62
|
-
request.on_headers { |response| headers = response.headers }
|
63
|
-
request.on_complete { |response| expect(response).not_to be_nil ; expect(response.headers).to eq(headers) ; expect(response.body).not_to be_empty }
|
64
|
-
request.run
|
65
|
-
end
|
66
|
-
|
67
|
-
it "calls on_complete" do
|
68
|
-
callback = double(:call)
|
69
|
-
expect(callback).to receive(:call)
|
70
|
-
request.instance_variable_set(:@on_complete, [callback])
|
71
|
-
request.run
|
72
|
-
end
|
73
|
-
|
74
|
-
it "returns a response" do
|
75
|
-
expect(request.run).to be_a(Typhoeus::Response)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe "#finish" do
|
80
|
-
let(:response) { Typhoeus::Response.new }
|
81
|
-
|
82
|
-
it "assigns response" do
|
83
|
-
request.finish(response)
|
84
|
-
expect(request.response).to be(response)
|
85
|
-
end
|
86
|
-
|
87
|
-
it "assigns request to response" do
|
88
|
-
request.finish(response)
|
89
|
-
expect(request.response.request).to be(request)
|
90
|
-
end
|
91
|
-
|
92
|
-
it "executes callbacks" do
|
93
|
-
expect(request).to receive(:execute_callbacks)
|
94
|
-
request.finish(response)
|
95
|
-
end
|
96
|
-
|
97
|
-
it "returns response" do
|
98
|
-
expect(request.finish(response)).to be(response)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Typhoeus::Request::Responseable do
|
4
|
-
let(:request) { Typhoeus::Request.new("base_url", {}) }
|
5
|
-
let(:response) { Typhoeus::Response.new }
|
6
|
-
|
7
|
-
describe "#response=" do
|
8
|
-
it "stores response" do
|
9
|
-
request.response = response
|
10
|
-
expect(request.response).to eq(response)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Typhoeus::Request::Stubbable do
|
4
|
-
let(:base_url) { "localhost:3001" }
|
5
|
-
let(:request) { Typhoeus::Request.new(base_url) }
|
6
|
-
let(:response) { Typhoeus::Response.new }
|
7
|
-
|
8
|
-
before { Typhoeus.stub(base_url).and_return(response) }
|
9
|
-
|
10
|
-
describe "#run" do
|
11
|
-
it "checks expectations" do
|
12
|
-
request.run
|
13
|
-
end
|
14
|
-
|
15
|
-
context "when expectation found" do
|
16
|
-
it "calls on_headers callbacks" do
|
17
|
-
canary = :not_called
|
18
|
-
request.on_headers do
|
19
|
-
canary = :called
|
20
|
-
end
|
21
|
-
request.run
|
22
|
-
expect(canary).to eq(:called)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "calls on_body callbacks" do
|
26
|
-
canary = :not_called
|
27
|
-
request.on_body do
|
28
|
-
canary = :called
|
29
|
-
end
|
30
|
-
request.run
|
31
|
-
expect(canary).to eq(:called)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "finishes request" do
|
35
|
-
expect(request).to receive(:finish)
|
36
|
-
request.run
|
37
|
-
end
|
38
|
-
|
39
|
-
it "sets mock on response" do
|
40
|
-
request.run
|
41
|
-
expect(request.response.mock).to be(true)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,256 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Typhoeus::Request do
|
4
|
-
let(:base_url) { "localhost:3001" }
|
5
|
-
let(:options) do
|
6
|
-
{
|
7
|
-
verbose: true,
|
8
|
-
headers: { "User-Agent" => "Fubar", "Expect" => "" },
|
9
|
-
maxredirs: 50
|
10
|
-
}
|
11
|
-
end
|
12
|
-
let(:request) { Typhoeus::Request.new(base_url, options) }
|
13
|
-
|
14
|
-
describe ".url" do
|
15
|
-
context "when no parameters" do
|
16
|
-
it "returns base_url" do
|
17
|
-
expect(request.url).to eq(request.base_url)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context "when parameters" do
|
22
|
-
let(:options) { {:params => {:a => 1}} }
|
23
|
-
|
24
|
-
it "returns full url" do
|
25
|
-
expect(request.url).to eq("#{request.base_url}?a=1")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
it "pushes an easy back into the pool" do
|
30
|
-
easy = double.as_null_object
|
31
|
-
allow(Typhoeus::Pool).to receive(:get).and_return(easy)
|
32
|
-
expect(Typhoeus::Pool).to receive(:release).with(easy)
|
33
|
-
request.url
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe ".new" do
|
38
|
-
it "stores base_url" do
|
39
|
-
expect(request.base_url).to eq(base_url)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "stores options" do
|
43
|
-
expect(request.options).to eq(options)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "stores original options" do
|
47
|
-
expect(request.original_options).to eq(options)
|
48
|
-
expect(request.original_options).to_not be(request.options)
|
49
|
-
end
|
50
|
-
|
51
|
-
it "sets defaults" do
|
52
|
-
expect(request.options[:headers]['User-Agent']).to be
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe "set_defaults" do
|
57
|
-
context "when header with user agent" do
|
58
|
-
let(:options) { {:headers => {'User-Agent' => "Custom"} } }
|
59
|
-
|
60
|
-
it "doesn't modify user agent" do
|
61
|
-
expect(request.options[:headers]['User-Agent']).to eq("Custom")
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context "when header without user agent" do
|
66
|
-
let(:options) { {:headers => {} } }
|
67
|
-
|
68
|
-
it "add user agent" do
|
69
|
-
agent = request.options[:headers]['User-Agent']
|
70
|
-
expect(agent).to eq(Typhoeus::USER_AGENT)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
context "when Config.user_agent set" do
|
75
|
-
before { Typhoeus.configure { |config| config.user_agent = "Default" } }
|
76
|
-
after { Typhoeus.configure { |config| config.user_agent = nil } }
|
77
|
-
|
78
|
-
context "with headers" do
|
79
|
-
let(:options) { {:headers => { "User-Agent" => "Fubar" } } }
|
80
|
-
|
81
|
-
it "uses the request options' user agent" do
|
82
|
-
expect(request.options[:headers]["User-Agent"]).to eq("Fubar")
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context "without headers" do
|
87
|
-
let(:options) { {:headers => {} } }
|
88
|
-
|
89
|
-
it "uses the global options' user agent" do
|
90
|
-
expect(request.options[:headers]["User-Agent"]).to eq("Default")
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context "when Config.verbose set" do
|
96
|
-
before { Typhoeus.configure { |config| config.verbose = true} }
|
97
|
-
after { Typhoeus.configure { |config| config.verbose = false} }
|
98
|
-
|
99
|
-
it "respects" do
|
100
|
-
expect(request.options[:verbose]).to be_truthy
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context "when Config.timeout set" do
|
105
|
-
before { Typhoeus.configure { |config| config.timeout = 10 } }
|
106
|
-
after { Typhoeus.configure { |config| config.timeout = nil } }
|
107
|
-
|
108
|
-
it "respects configuration" do
|
109
|
-
expect(request.options[:timeout]).to eq(10)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
context "when Config.connecttimeout set" do
|
114
|
-
before { Typhoeus.configure { |config| config.connecttimeout = 10 } }
|
115
|
-
after { Typhoeus.configure { |config| config.connecttimeout = nil } }
|
116
|
-
|
117
|
-
it "respects configuration" do
|
118
|
-
expect(request.options[:connecttimeout]).to eq(10)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
context "when maxredirs" do
|
123
|
-
context "when not set" do
|
124
|
-
it "defaults to 50" do
|
125
|
-
expect(request.options[:maxredirs]).to be(50)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
context "when set" do
|
130
|
-
let(:options) { {:maxredirs => 1} }
|
131
|
-
|
132
|
-
it "respects" do
|
133
|
-
expect(request.options[:maxredirs]).to be(1)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
context "when Config.proxy set" do
|
139
|
-
before { Typhoeus.configure { |config| config.proxy = "http://proxy.internal" } }
|
140
|
-
after { Typhoeus.configure { |config| config.proxy = nil } }
|
141
|
-
|
142
|
-
it "respects" do
|
143
|
-
expect(request.options[:proxy]).to eq("http://proxy.internal")
|
144
|
-
end
|
145
|
-
|
146
|
-
context "when option proxy set" do
|
147
|
-
let(:options) { {:proxy => nil} }
|
148
|
-
|
149
|
-
it "does not override" do
|
150
|
-
expect(request.options[:proxy]).to be_nil
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
describe "#eql?" do
|
157
|
-
context "when another class" do
|
158
|
-
let(:other) { "" }
|
159
|
-
|
160
|
-
it "returns false" do
|
161
|
-
expect(request).to_not eql other
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
context "when same class" do
|
166
|
-
let(:other) { Typhoeus::Request.new("base_url", options) }
|
167
|
-
|
168
|
-
context "when other base_url" do
|
169
|
-
it "returns false" do
|
170
|
-
expect(request).to_not eql other
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
context "when same base_url and other options" do
|
175
|
-
let(:other) { Typhoeus::Request.new(base_url, {}) }
|
176
|
-
|
177
|
-
it "returns false" do
|
178
|
-
expect(request).to_not eql other
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
|
183
|
-
context "when same base_url and options" do
|
184
|
-
context "when same order" do
|
185
|
-
let(:other) { Typhoeus::Request.new(base_url, options) }
|
186
|
-
|
187
|
-
it "returns true" do
|
188
|
-
expect(request).to eql other
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
context "when different order" do
|
193
|
-
let(:other_options) {
|
194
|
-
{:headers => { 'User-Agent' => "Fubar", 'Expect' => ""}, :verbose => true }
|
195
|
-
}
|
196
|
-
let(:other) { Typhoeus::Request.new(base_url, other_options)}
|
197
|
-
|
198
|
-
it "returns true" do
|
199
|
-
expect(request).to eql other
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
describe "#hash" do
|
207
|
-
context "when request.eql?(other)" do
|
208
|
-
context "when different order" do
|
209
|
-
let(:other_options) {
|
210
|
-
{:headers => { 'User-Agent' => "Fubar", 'Expect' => "" }, :verbose => true }
|
211
|
-
}
|
212
|
-
let(:other) { Typhoeus::Request.new(base_url, other_options)}
|
213
|
-
|
214
|
-
it "has same hashes" do
|
215
|
-
expect(request.hash).to eq(other.hash)
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
context "when same order" do
|
220
|
-
let(:other) { Typhoeus::Request.new(base_url, options) }
|
221
|
-
|
222
|
-
it "has same hashes" do
|
223
|
-
expect(request.hash).to eq(other.hash)
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
context "when hashes with different orders are contained in arrays" do
|
228
|
-
let(:request) { Typhoeus::Request.new(base_url, :params => [{:b => 2, :a => 1}]) }
|
229
|
-
let(:other) { Typhoeus::Request.new(base_url, :params => [{:a => 1, :b => 2}]) }
|
230
|
-
it "has different hashes" do
|
231
|
-
expect(request.hash).to eq(other.hash)
|
232
|
-
end
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
context "when not request.eql?(other)" do
|
237
|
-
let(:request) { Typhoeus::Request.new(base_url, :params => {:foo => 'bar'}) }
|
238
|
-
let(:other) { Typhoeus::Request.new(base_url, :params => {:foo => 'baz'}) }
|
239
|
-
|
240
|
-
it "has different hashes" do
|
241
|
-
expect(request.hash).to_not eq(other.hash)
|
242
|
-
end
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
describe "#encoded_body" do
|
247
|
-
let(:request) {
|
248
|
-
Typhoeus::Request.new("www.example.com",:body => {:a => 1})
|
249
|
-
}
|
250
|
-
|
251
|
-
it "returns encoded body" do
|
252
|
-
expect(request.encoded_body).to eq("a=1")
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
end
|