excon 0.30.0 → 0.31.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of excon might be problematic. Click here for more details.

@@ -3,19 +3,22 @@ Shindo.tests('Excon Decompress Middleware') do
3
3
 
4
4
  with_server('good') do
5
5
 
6
- connection = Excon.new(
7
- 'http://127.0.0.1:9292/echo/content-encoded',
8
- :method => :post,
9
- :body => 'hello world',
10
- :middlewares => Excon.defaults[:middlewares] + [Excon::Middleware::Decompress]
11
- )
6
+ before do
7
+ @connection ||= Excon.new(
8
+ 'http://127.0.0.1:9292/echo/content-encoded',
9
+ :method => :post,
10
+ :body => 'hello world',
11
+ :middlewares => Excon.defaults[:middlewares] + [Excon::Middleware::Decompress]
12
+ )
13
+ end
12
14
 
13
15
  tests('gzip') do
14
- resp = connection.request(
15
- :headers => { 'Accept-Encoding' => 'gzip, deflate;q=0' }
16
- )
16
+ resp = nil
17
17
 
18
18
  tests('response body decompressed').returns('hello world') do
19
+ resp = @connection.request(
20
+ :headers => { 'Accept-Encoding' => 'gzip, deflate;q=0' }
21
+ )
19
22
  resp[:body]
20
23
  end
21
24
 
@@ -29,11 +32,12 @@ Shindo.tests('Excon Decompress Middleware') do
29
32
  end
30
33
 
31
34
  tests('deflate') do
32
- resp = connection.request(
33
- :headers => { 'Accept-Encoding' => 'gzip;q=0, deflate' }
34
- )
35
+ resp = nil
35
36
 
36
37
  tests('response body decompressed').returns('hello world') do
38
+ resp = @connection.request(
39
+ :headers => { 'Accept-Encoding' => 'gzip;q=0, deflate' }
40
+ )
37
41
  resp[:body]
38
42
  end
39
43
 
@@ -47,12 +51,13 @@ Shindo.tests('Excon Decompress Middleware') do
47
51
  end
48
52
 
49
53
  tests('with pre-encoding') do
50
- resp = connection.request(
51
- :headers => { 'Accept-Encoding' => 'gzip, deflate;q=0',
52
- 'Content-Encoding-Pre' => 'other' }
53
- )
54
+ resp = nil
54
55
 
55
56
  tests('server sent content-encoding').returns('other, gzip') do
57
+ resp = @connection.request(
58
+ :headers => { 'Accept-Encoding' => 'gzip, deflate;q=0',
59
+ 'Content-Encoding-Pre' => 'other' }
60
+ )
56
61
  resp[:headers]['Content-Encoding-Sent']
57
62
  end
58
63
 
@@ -67,12 +72,13 @@ Shindo.tests('Excon Decompress Middleware') do
67
72
  end
68
73
 
69
74
  tests('with post-encoding') do
70
- resp = connection.request(
71
- :headers => { 'Accept-Encoding' => 'gzip, deflate;q=0',
72
- 'Content-Encoding-Post' => 'other' }
73
- )
75
+ resp = nil
74
76
 
75
77
  tests('server sent content-encoding').returns('gzip, other') do
78
+ resp = @connection.request(
79
+ :headers => { 'Accept-Encoding' => 'gzip, deflate;q=0',
80
+ 'Content-Encoding-Post' => 'other' }
81
+ )
76
82
  resp[:headers]['Content-Encoding-Sent']
77
83
  end
78
84
 
@@ -87,15 +93,16 @@ Shindo.tests('Excon Decompress Middleware') do
87
93
  end
88
94
 
89
95
  tests('with a :response_block') do
96
+ captures = nil
90
97
  resp = nil
91
- captures = capture_response_block do |block|
92
- resp = connection.request(
93
- :headers => { 'Accept-Encoding' => 'gzip'},
94
- :response_block => block
95
- )
96
- end
97
98
 
98
99
  tests('server sent content-encoding').returns('gzip') do
100
+ captures = capture_response_block do |block|
101
+ resp = @connection.request(
102
+ :headers => { 'Accept-Encoding' => 'gzip'},
103
+ :response_block => block
104
+ )
105
+ end
99
106
  resp[:headers]['Content-Encoding-Sent']
100
107
  end
101
108
 
@@ -125,7 +132,7 @@ Shindo.tests('Excon Decompress Middleware') do
125
132
 
126
133
  tests('with a :response_block').returns(nil) do
127
134
  captures = capture_response_block do |block|
128
- resp = Excon.post(
135
+ Excon.post(
129
136
  'http://127.0.0.1:9292/echo/request',
130
137
  :body => 'hello world',
131
138
  :response_block => block,
@@ -1,4 +1,5 @@
1
1
  require 'active_support/notifications'
2
+ require 'securerandom'
2
3
 
3
4
  class SimpleInstrumentor
4
5
  class << self
@@ -166,12 +167,12 @@ Shindo.tests('Excon instrumentation') do
166
167
  original_stderr = $stderr
167
168
  $stderr = @captured_stderr = StringIO.new
168
169
  stub_failure
169
- @connection = Excon.new(
170
- 'http://user:pass@127.0.0.1:9292',
171
- :instrumentor => Excon::StandardInstrumentor,
172
- :mock => true
173
- )
174
170
  raises(Excon::Errors::SocketError) do
171
+ @connection = Excon.new(
172
+ 'http://user:pass@127.0.0.1:9292',
173
+ :instrumentor => Excon::StandardInstrumentor,
174
+ :mock => true
175
+ )
175
176
  @connection.get(:idempotent => true)
176
177
  end
177
178
  ensure
@@ -196,12 +197,12 @@ Shindo.tests('Excon instrumentation') do
196
197
  original_stderr = $stderr
197
198
  $stderr = @captured_stderr = StringIO.new
198
199
  stub_failure
199
- @connection = Excon.new(
200
- 'http://user:pass@127.0.0.1:9292',
201
- :instrumentor => Excon::StandardInstrumentor,
202
- :mock => true
203
- )
204
200
  raises(Excon::Errors::SocketError) do
201
+ @connection = Excon.new(
202
+ 'http://user:pass@127.0.0.1:9292',
203
+ :instrumentor => Excon::StandardInstrumentor,
204
+ :mock => true
205
+ )
205
206
  @connection.get(:idempotent => true)
206
207
  end
207
208
  ensure
@@ -15,13 +15,15 @@ Shindo.tests('Excon stubs') do
15
15
  end
16
16
 
17
17
  tests("stub({:method => :get}, {:body => 'body', :status => 200})") do
18
+ connection = nil
19
+ response = nil
18
20
 
19
- Excon.stub({:method => :get}, {:body => 'body', :status => 200})
21
+ tests('response.body').returns('body') do
22
+ Excon.stub({:method => :get}, {:body => 'body', :status => 200})
20
23
 
21
- connection = Excon.new('http://127.0.0.1:9292', :mock => true)
22
- response = connection.request(:method => :get, :path => '/content-length/100')
24
+ connection = Excon.new('http://127.0.0.1:9292', :mock => true)
25
+ response = connection.request(:method => :get, :path => '/content-length/100')
23
26
 
24
- tests('response.body').returns('body') do
25
27
  response.body
26
28
  end
27
29
 
@@ -47,18 +49,20 @@ Shindo.tests('Excon stubs') do
47
49
  end
48
50
 
49
51
  tests("stub({:path => %r{/tests/(\S+)}}, {:body => $1, :status => 200})") do
52
+ connection = nil
53
+ response = nil
50
54
 
51
- Excon.stub({:path => %r{/tests/(\S+)}}) do |params|
52
- {
53
- :body => params[:captures][:path].first,
54
- :status => 200
55
- }
56
- end
55
+ tests('response.body').returns('test') do
56
+ Excon.stub({:path => %r{/tests/(\S+)}}) do |params|
57
+ {
58
+ :body => params[:captures][:path].first,
59
+ :status => 200
60
+ }
61
+ end
57
62
 
58
- connection = Excon.new('http://127.0.0.1:9292', :mock => true)
59
- response = connection.request(:method => :get, :path => '/tests/test')
63
+ connection = Excon.new('http://127.0.0.1:9292', :mock => true)
64
+ response = connection.request(:method => :get, :path => '/tests/test')
60
65
 
61
- tests('response.body').returns('test') do
62
66
  response.body
63
67
  end
64
68
 
@@ -75,13 +79,15 @@ Shindo.tests('Excon stubs') do
75
79
  end
76
80
 
77
81
  tests("stub({:body => 'body', :method => :get}) {|params| {:body => params[:body], :headers => params[:headers], :status => 200}}") do
82
+ connection = nil
83
+ response = nil
78
84
 
79
- Excon.stub({:body => 'body', :method => :get}) {|params| {:body => params[:body], :headers => params[:headers], :status => 200}}
85
+ tests('response.body').returns('body') do
86
+ Excon.stub({:body => 'body', :method => :get}) {|params| {:body => params[:body], :headers => params[:headers], :status => 200}}
80
87
 
81
- connection = Excon.new('http://127.0.0.1:9292', :mock => true)
82
- response = connection.request(:body => 'body', :method => :get, :path => '/content-length/100')
88
+ connection = Excon.new('http://127.0.0.1:9292', :mock => true)
89
+ response = connection.request(:body => 'body', :method => :get, :path => '/content-length/100')
83
90
 
84
- tests('response.body').returns('body') do
85
91
  response.body
86
92
  end
87
93
 
@@ -108,17 +114,17 @@ Shindo.tests('Excon stubs') do
108
114
 
109
115
  tests("stub({:body => File.open(...), :method => :get}, { :status => 200 })") do
110
116
 
111
- file_path = File.join(File.dirname(__FILE__), '..', 'data', 'xs')
117
+ tests('response.status').returns(200) do
118
+ file_path = File.join(File.dirname(__FILE__), '..', 'data', 'xs')
112
119
 
113
- Excon.stub(
114
- { :body => File.read(file_path), :method => :get },
115
- { :status => 200 }
116
- )
120
+ Excon.stub(
121
+ { :body => File.read(file_path), :method => :get },
122
+ { :status => 200 }
123
+ )
117
124
 
118
- connection = Excon.new('http://127.0.0.1:9292', :mock => true)
119
- response = connection.request(:body => File.open(file_path), :method => :get, :path => '/')
125
+ connection = Excon.new('http://127.0.0.1:9292', :mock => true)
126
+ response = connection.request(:body => File.open(file_path), :method => :get, :path => '/')
120
127
 
121
- tests('response.status') do
122
128
  response.status
123
129
  end
124
130
 
@@ -134,10 +140,10 @@ Shindo.tests('Excon stubs') do
134
140
  Excon.stubs.clear
135
141
 
136
142
  tests("stub({}, {:body => 'x' * (Excon::DEFAULT_CHUNK_SIZE + 1)})") do
137
- connection = Excon.new('http://127.0.0.1:9292', :mock => true)
138
- Excon.stub({}, {:body => 'x' * (Excon::DEFAULT_CHUNK_SIZE + 1)})
139
-
140
143
  test("with response_block") do
144
+ connection = Excon.new('http://127.0.0.1:9292', :mock => true)
145
+ Excon.stub({}, {:body => 'x' * (Excon::DEFAULT_CHUNK_SIZE + 1)})
146
+
141
147
  chunks = []
142
148
  response_block = lambda do |chunk, remaining_bytes, total_bytes|
143
149
  chunks << chunk
@@ -150,33 +156,33 @@ Shindo.tests('Excon stubs') do
150
156
  Excon.stubs.clear
151
157
 
152
158
  tests("stub({:url => 'https://user:pass@foo.bar.com:9999/baz?quux=true'}, {:status => 200})") do
153
- Excon.stub({:url => 'https://user:pass@foo.bar.com:9999/baz?quux=true'}, {:status => 200})
154
-
155
- tests("get(:expects => 200)") do
159
+ test("get(:expects => 200)") do
160
+ Excon.stub({:url => 'https://user:pass@foo.bar.com:9999/baz?quux=true'}, {:status => 200})
156
161
  Excon.new("https://user:pass@foo.bar.com:9999/baz?quux=true", :mock => true).get(:expects => 200)
162
+ true
157
163
  end
158
164
  end
159
165
 
160
166
  Excon.stubs.clear
161
167
 
162
168
  tests("stub({}, {:status => 404, :body => 'Not Found'}") do
163
-
164
- connection = Excon.new('http://127.0.0.1:9292', :mock => true)
165
- Excon.stub({}, {:status => 404, :body => 'Not Found'})
169
+ connection = nil
166
170
 
167
171
  tests("request(:expects => 200, :method => :get, :path => '/')").raises(Excon::Errors::NotFound) do
172
+ connection = Excon.new('http://127.0.0.1:9292', :mock => true)
173
+ Excon.stub({}, {:status => 404, :body => 'Not Found'})
174
+
168
175
  connection.request(:expects => 200, :method => :get, :path => '/')
169
176
  end
170
177
 
171
- tests("Expects exception should contain response object") do
178
+ tests("Expects exception should contain response object").returns(Excon::Response) do
172
179
  begin
173
180
  connection.request(:expects => 200, :method => :get, :path => '/')
174
181
  rescue Excon::Errors::NotFound => e
175
- returns(Excon::Response) { e.response.class }
182
+ e.response.class
176
183
  end
177
184
  end
178
185
 
179
-
180
186
  test("request(:expects => 200, :method => :get, :path => '/') with block does not invoke the block since it raises an error") do
181
187
  block_called = false
182
188
  begin
@@ -194,10 +200,10 @@ Shindo.tests('Excon stubs') do
194
200
  end
195
201
 
196
202
  tests("stub_for({})") do
197
- connection = Excon.new('http://127.0.0.1:9292', :mock => true)
198
- Excon.stub({}, {})
199
-
200
203
  tests("stub_for({})").returns([{}, {}]) do
204
+ Excon.new('http://127.0.0.1:9292', :mock => true)
205
+ Excon.stub({}, {})
206
+
201
207
  Excon.stub_for({})
202
208
  end
203
209
 
@@ -205,10 +211,12 @@ Shindo.tests('Excon stubs') do
205
211
  end
206
212
 
207
213
  tests("unstub({})") do
208
- connection = Excon.new('http://127.0.0.1:9292', :mock => true)
209
- Excon.stub({}, {})
214
+ connection = nil
210
215
 
211
216
  tests("unstub({})").returns([{}, {}]) do
217
+ connection = Excon.new('http://127.0.0.1:9292', :mock => true)
218
+ Excon.stub({}, {})
219
+
212
220
  Excon.unstub({})
213
221
  end
214
222
 
@@ -219,11 +227,5 @@ Shindo.tests('Excon stubs') do
219
227
  Excon.stubs.clear
220
228
  end
221
229
 
222
- tests('mock = false') do
223
- with_rackup('basic.ru') do
224
- basic_tests
225
- end
226
- end
227
-
228
230
  env_restore
229
231
  end
@@ -1,31 +1,30 @@
1
1
  Shindo.tests('Excon redirector support') do
2
2
  env_init
3
3
 
4
- connection = Excon.new(
5
- 'http://127.0.0.1:9292',
6
- :middlewares => Excon.defaults[:middlewares] + [Excon::Middleware::RedirectFollower],
7
- :mock => true
8
- )
9
-
10
- Excon.stub(
11
- { :path => '/old' },
12
- {
13
- :headers => { 'Location' => 'http://127.0.0.1:9292/new' },
14
- :body => 'old',
15
- :status => 301
16
- }
17
- )
18
-
19
- Excon.stub(
20
- { :path => '/new' },
21
- {
22
- :body => 'new',
23
- :status => 200
24
- }
25
- )
26
-
27
4
  tests("request(:method => :get, :path => '/old').body").returns('new') do
28
- connection.request(:method => :get, :path => '/old').body
5
+ Excon.stub(
6
+ { :path => '/old' },
7
+ {
8
+ :headers => { 'Location' => 'http://127.0.0.1:9292/new' },
9
+ :body => 'old',
10
+ :status => 301
11
+ }
12
+ )
13
+
14
+ Excon.stub(
15
+ { :path => '/new' },
16
+ {
17
+ :body => 'new',
18
+ :status => 200
19
+ }
20
+ )
21
+
22
+ Excon.get(
23
+ 'http://127.0.0.1:9292',
24
+ :path => '/old',
25
+ :middlewares => Excon.defaults[:middlewares] + [Excon::Middleware::RedirectFollower],
26
+ :mock => true
27
+ ).body
29
28
  end
30
29
 
31
30
  env_restore
@@ -33,33 +32,32 @@ end
33
32
 
34
33
  Shindo.tests('Excon redirect support for relative Location headers') do
35
34
  env_init
36
-
37
- connection = Excon.new(
38
- 'http://127.0.0.1:9292',
39
- :middlewares => Excon.defaults[:middlewares] + [Excon::Middleware::RedirectFollower],
40
- :mock => true
41
- )
42
-
43
- Excon.stub(
44
- { :path => '/old' },
45
- {
46
- :headers => { 'Location' => '/new' },
47
- :body => 'old',
48
- :status => 301
49
- }
50
- )
51
-
52
- Excon.stub(
53
- { :path => '/new' },
54
- {
55
- :body => 'new',
56
- :status => 200
57
- }
58
- )
59
35
 
60
36
  tests("request(:method => :get, :path => '/old').body").returns('new') do
61
- connection.request(:method => :get, :path => '/old').body
37
+ Excon.stub(
38
+ { :path => '/old' },
39
+ {
40
+ :headers => { 'Location' => '/new' },
41
+ :body => 'old',
42
+ :status => 301
43
+ }
44
+ )
45
+
46
+ Excon.stub(
47
+ { :path => '/new' },
48
+ {
49
+ :body => 'new',
50
+ :status => 200
51
+ }
52
+ )
53
+
54
+ Excon.get(
55
+ 'http://127.0.0.1:9292',
56
+ :path => '/old',
57
+ :middlewares => Excon.defaults[:middlewares] + [Excon::Middleware::RedirectFollower],
58
+ :mock => true
59
+ ).body
62
60
  end
63
-
61
+
64
62
  env_restore
65
63
  end