typhoeus 1.4.0 → 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.
Files changed (59) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +47 -1
  3. data/README.md +10 -6
  4. data/lib/typhoeus/config.rb +16 -0
  5. data/lib/typhoeus/easy_factory.rb +26 -0
  6. data/lib/typhoeus/expectation.rb +4 -2
  7. data/lib/typhoeus/request/responseable.rb +1 -1
  8. data/lib/typhoeus/request.rb +2 -0
  9. data/lib/typhoeus/response/informations.rb +57 -0
  10. data/lib/typhoeus/version.rb +1 -1
  11. data/typhoeus.gemspec +14 -4
  12. metadata +18 -97
  13. data/.gitignore +0 -8
  14. data/.rspec +0 -4
  15. data/.travis.yml +0 -26
  16. data/Gemfile +0 -32
  17. data/Guardfile +0 -9
  18. data/Rakefile +0 -38
  19. data/perf/profile.rb +0 -14
  20. data/perf/vs_nethttp.rb +0 -64
  21. data/spec/rack/typhoeus/middleware/params_decoder/helper_spec.rb +0 -156
  22. data/spec/rack/typhoeus/middleware/params_decoder_spec.rb +0 -31
  23. data/spec/spec_helper.rb +0 -29
  24. data/spec/support/localhost_server.rb +0 -94
  25. data/spec/support/memory_cache.rb +0 -15
  26. data/spec/support/server.rb +0 -116
  27. data/spec/typhoeus/adapters/faraday_spec.rb +0 -339
  28. data/spec/typhoeus/cache/dalli_spec.rb +0 -41
  29. data/spec/typhoeus/cache/redis_spec.rb +0 -41
  30. data/spec/typhoeus/config_spec.rb +0 -15
  31. data/spec/typhoeus/easy_factory_spec.rb +0 -143
  32. data/spec/typhoeus/errors/no_stub_spec.rb +0 -13
  33. data/spec/typhoeus/expectation_spec.rb +0 -280
  34. data/spec/typhoeus/hydra/addable_spec.rb +0 -22
  35. data/spec/typhoeus/hydra/before_spec.rb +0 -98
  36. data/spec/typhoeus/hydra/block_connection_spec.rb +0 -18
  37. data/spec/typhoeus/hydra/cacheable_spec.rb +0 -88
  38. data/spec/typhoeus/hydra/memoizable_spec.rb +0 -53
  39. data/spec/typhoeus/hydra/queueable_spec.rb +0 -98
  40. data/spec/typhoeus/hydra/runnable_spec.rb +0 -137
  41. data/spec/typhoeus/hydra/stubbable_spec.rb +0 -48
  42. data/spec/typhoeus/hydra_spec.rb +0 -22
  43. data/spec/typhoeus/pool_spec.rb +0 -137
  44. data/spec/typhoeus/request/actions_spec.rb +0 -19
  45. data/spec/typhoeus/request/before_spec.rb +0 -93
  46. data/spec/typhoeus/request/block_connection_spec.rb +0 -75
  47. data/spec/typhoeus/request/cacheable_spec.rb +0 -94
  48. data/spec/typhoeus/request/callbacks_spec.rb +0 -91
  49. data/spec/typhoeus/request/marshal_spec.rb +0 -60
  50. data/spec/typhoeus/request/memoizable_spec.rb +0 -34
  51. data/spec/typhoeus/request/operations_spec.rb +0 -101
  52. data/spec/typhoeus/request/responseable_spec.rb +0 -13
  53. data/spec/typhoeus/request/stubbable_spec.rb +0 -45
  54. data/spec/typhoeus/request_spec.rb +0 -232
  55. data/spec/typhoeus/response/header_spec.rb +0 -147
  56. data/spec/typhoeus/response/informations_spec.rb +0 -283
  57. data/spec/typhoeus/response/status_spec.rb +0 -256
  58. data/spec/typhoeus/response_spec.rb +0 -100
  59. data/spec/typhoeus_spec.rb +0 -105
@@ -1,100 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Typhoeus::Response do
4
- let(:response) { Typhoeus::Response.new(options) }
5
- let(:options) { {} }
6
-
7
- describe ".new" do
8
- context "when options" do
9
- context "when return_code" do
10
- let(:options) { {:return_code => 2} }
11
-
12
- it "stores" do
13
- expect(response.options[:return_code]).to be(2)
14
- end
15
- end
16
-
17
- context "when headers" do
18
- let(:options) { {:headers => {'A' => 'B'}} }
19
-
20
- it "stores unmodified" do
21
- expect(response.options[:headers]).to be(options[:headers])
22
- end
23
-
24
- it "sets @headers to a Typhoeus::Response::Header" do
25
- expect(response.instance_variable_get(:@headers)).to be_a(Typhoeus::Response::Header)
26
- end
27
-
28
- it "has key" do
29
- expect(response.headers['A']).to eq('B')
30
- end
31
- end
32
- end
33
- end
34
-
35
- describe "#mock" do
36
- context "when @mock" do
37
- before { response.mock = true }
38
-
39
- it "returns @mock" do
40
- expect(response.mock).to be_truthy
41
- end
42
- end
43
-
44
- context "when options[:mock]" do
45
- let(:options) { {:mock => true} }
46
-
47
- it "returns options[:mock]" do
48
- expect(response.mock).to be_truthy
49
- end
50
- end
51
-
52
- context "when @mock and options[:mock]" do
53
- let(:options) { {:mock => 1} }
54
- before { response.mock = 2 }
55
-
56
- it "returns @mock" do
57
- expect(response.mock).to be(2)
58
- end
59
- end
60
- end
61
-
62
- describe "#handled_response" do
63
- let(:handled_response) { Typhoeus::Response.new }
64
-
65
- context "when @handled_response" do
66
- before { response.handled_response = handled_response }
67
-
68
- it "returns @handled_response" do
69
- expect(response.handled_response).to be(handled_response)
70
- end
71
- end
72
-
73
- context "when @handled_response is nil" do
74
- before { response.handled_response = nil }
75
-
76
- it "returns response" do
77
- expect(response.handled_response).to be(response)
78
- end
79
- end
80
- end
81
-
82
- describe "#cached" do
83
- context "when @cached" do
84
- before { response.cached = true }
85
-
86
- it "returns cached status" do
87
- expect(response.cached?).to be_truthy
88
- end
89
- end
90
-
91
- context "when @cached is nil" do
92
- before { response.cached = nil }
93
-
94
- it "returns false" do
95
- expect(response.cached?).to be_falsey
96
- end
97
- end
98
-
99
- end
100
- end
@@ -1,105 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Typhoeus do
4
- before(:each) do
5
- Typhoeus.configure { |config| config.verbose = false; config.block_connection = false }
6
- end
7
-
8
- describe ".configure" do
9
- it "yields config" do
10
- Typhoeus.configure do |config|
11
- expect(config).to be_a(Typhoeus::Config)
12
- end
13
- end
14
-
15
- it "sets values config" do
16
- Typhoeus::Config.verbose = true
17
- expect(Typhoeus::Config.verbose).to be_truthy
18
- end
19
- end
20
-
21
- describe ".stub" do
22
- let(:base_url) { "www.example.com" }
23
-
24
- shared_examples "lazy response construction" do
25
- it "calls the block to construct a response when a request matches the stub" do
26
- expected_response = Typhoeus::Response.new
27
- Typhoeus.stub(base_url) do |request|
28
- expected_response
29
- end
30
-
31
- response = Typhoeus.get(base_url)
32
-
33
- expect(response).to be(expected_response)
34
- end
35
- end
36
-
37
- context "when no similar expectation exists" do
38
- include_examples "lazy response construction"
39
-
40
- it "returns expectation" do
41
- expect(Typhoeus.stub(base_url)).to be_a(Typhoeus::Expectation)
42
- end
43
-
44
- it "adds expectation" do
45
- Typhoeus.stub(:get, "")
46
- expect(Typhoeus::Expectation.all.size).to eq(1)
47
- end
48
- end
49
-
50
- context "when similar expectation exists" do
51
- include_examples "lazy response construction"
52
-
53
- let(:expectation) { Typhoeus::Expectation.new(base_url) }
54
- before { Typhoeus::Expectation.all << expectation }
55
-
56
- it "returns expectation" do
57
- expect(Typhoeus.stub(base_url)).to be_a(Typhoeus::Expectation)
58
- end
59
-
60
- it "doesn't add expectation" do
61
- Typhoeus.stub(base_url)
62
- expect(Typhoeus::Expectation.all.size).to eq(1)
63
- end
64
- end
65
- end
66
-
67
- describe ".before" do
68
- it "adds callback" do
69
- Typhoeus.before { true }
70
- expect(Typhoeus.before.size).to eq(1)
71
- end
72
- end
73
-
74
- describe ".with_connection" do
75
- it "executes block with block connection is false" do
76
- Typhoeus.with_connection { expect(Typhoeus::Config.block_connection).to be(false) }
77
- end
78
-
79
- it "sets block connection back to previous value" do
80
- Typhoeus::Config.block_connection = true
81
- Typhoeus.with_connection {}
82
- expect(Typhoeus::Config.block_connection).to be(true)
83
- end
84
-
85
- it "returns result of block" do
86
- expect(Typhoeus.with_connection { "123" }).to eq("123")
87
- end
88
- end
89
-
90
- [:get, :post, :put, :delete, :head, :patch, :options].each do |name|
91
- describe ".#{name}" do
92
- let(:response) { Typhoeus::Request.method(name).call("http://localhost:3001") }
93
-
94
- it "returns ok" do
95
- expect(response.return_code).to eq(:ok)
96
- end
97
-
98
- unless name == :head
99
- it "makes #{name.to_s.upcase} requests" do
100
- expect(response.response_body).to include("\"REQUEST_METHOD\":\"#{name.to_s.upcase}\"")
101
- end
102
- end
103
- end
104
- end
105
- end