excon 0.9.0 → 0.9.1

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.

@@ -81,7 +81,11 @@ NOTE: Excon will use the environment variables "http_proxy" and "https_proxy" if
81
81
 
82
82
  You can stub out requests for testing purposes by enabling mock mode on a connection.
83
83
 
84
- Excon.mock = true
84
+ connection = Excon.new('http://example.com', :mock => true)
85
+
86
+ Or by enabling mock mode for a request.
87
+
88
+ connection.request(:method => :get, :path => 'example', :mock => true)
85
89
 
86
90
  Then you can add stubs, for instance:
87
91
 
@@ -90,6 +94,13 @@ Then you can add stubs, for instance:
90
94
 
91
95
  Omitted attributes are assumed to match, so this stub will match any get request and return an Excon::Response with a body of 'body' and status of 200. You can add whatever stubs you might like this way and they will be checked against in the order they were added, if none of them match then excon will raise an error to let you know.
92
96
 
97
+ Alternatively you can pass a block instead of response_attributes and it will be called with the request params. For example, you could create a stub that echoes the body given to it like this:
98
+
99
+ # Excon.stub(request_attributes, &response_block)
100
+ Excon.stub({:method => :put}) do |params|
101
+ {:body => params[:body], :status => 200}
102
+ end
103
+
93
104
  == HTTPS/SSL Issues
94
105
 
95
106
  By default excon will try to verify peer certificates when using SSL for HTTPS. Unfortunately on some operating systems the defaults will not work. This will likely manifest itself as something like "Excon::Errors::SocketError: SSL_connect returned=1 ..."
@@ -1,3 +1,8 @@
1
+ 0.9.1 12/15/11
2
+ ==============
3
+
4
+ * update mock usage to be at the connection/request level
5
+
1
6
  0.9.0 12/14/11
2
7
  ==============
3
8
 
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'excon'
16
- s.version = '0.9.0'
17
- s.date = '2011-12-14'
16
+ s.version = '0.9.1'
17
+ s.date = '2011-12-15'
18
18
  s.rubyforge_project = 'excon'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -53,12 +53,13 @@ Gem::Specification.new do |s|
53
53
  ## List your development dependencies here. Development dependencies are
54
54
  ## those that are only needed during development
55
55
  # s.add_development_dependency('DEVDEPNAME', [">= 1.1.0", "< 2.0.0"])
56
+ s.add_development_dependency('activesupport', '~>3.1.3')
57
+ s.add_development_dependency('delorean')
56
58
  s.add_development_dependency('open4')
57
59
  s.add_development_dependency('rake')
60
+ s.add_development_dependency('rdoc')
58
61
  s.add_development_dependency('shindo', '0.2.0')
59
62
  s.add_development_dependency('sinatra')
60
- s.add_development_dependency('activesupport', '~>3.1.3')
61
- s.add_development_dependency('delorean')
62
63
 
63
64
  ## Leave this section as-is. It will be automatically generated from the
64
65
  ## contents of your Git repository via the gemspec task. DO NOT REMOVE
@@ -26,11 +26,9 @@ module Excon
26
26
  # setup ssl defaults based on platform
27
27
  @ssl_verify_peer = RbConfig::CONFIG['host_os'] !~ /mswin|win32|dos|cygwin|mingw/i
28
28
 
29
- # default mocking to off
30
- @mock = false
31
-
32
29
  # Status of mocking
33
30
  def mock
31
+ puts("Excon#mock is deprecated, pass :mock to the initializer (#{caller.first})")
34
32
  @mock
35
33
  end
36
34
 
@@ -38,6 +36,7 @@ module Excon
38
36
  # false is the default and works as expected
39
37
  # true returns a value from stubs or raises
40
38
  def mock=(new_mock)
39
+ puts("Excon#mock= is deprecated, pass :mock to the initializer (#{caller.first})")
41
40
  @mock = new_mock
42
41
  end
43
42
 
@@ -23,7 +23,7 @@ module Excon
23
23
  :headers => {},
24
24
  :host => uri.host,
25
25
  :instrumentor_name => 'excon',
26
- :mock => Excon.mock,
26
+ :mock => Excon.instance_variable_get(:@mock),
27
27
  :path => uri.path,
28
28
  :port => uri.port.to_s,
29
29
  :query => uri.query,
@@ -1,6 +1,6 @@
1
1
  module Excon
2
2
  unless const_defined?(:VERSION)
3
- VERSION = '0.9.0'
3
+ VERSION = '0.9.1'
4
4
  end
5
5
 
6
6
  unless const_defined?(:CHUNK_SIZE)
@@ -1,5 +1,8 @@
1
1
  Shindo.tests('Excon request idempotencey') do
2
- Excon.mock = true
2
+
3
+ before do
4
+ @connection = Excon.new('http://127.0.0.1:9292', :mock => true)
5
+ end
3
6
 
4
7
  after do
5
8
  # flush any existing stubs after each test
@@ -17,8 +20,7 @@ Shindo.tests('Excon request idempotencey') do
17
20
  end
18
21
  }
19
22
 
20
- connection = Excon.new('http://127.0.0.1:9292')
21
- response = connection.request(:method => :get, :path => '/some-path')
23
+ response = @connection.request(:method => :get, :path => '/some-path')
22
24
  end
23
25
 
24
26
  tests("Idempotent request with socket erroring first 3 times").returns(200) do
@@ -32,8 +34,7 @@ Shindo.tests('Excon request idempotencey') do
32
34
  end
33
35
  }
34
36
 
35
- connection = Excon.new('http://127.0.0.1:9292')
36
- response = connection.request(:method => :get, :idempotent => true, :path => '/some-path')
37
+ response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path')
37
38
  response.status
38
39
  end
39
40
 
@@ -48,8 +49,7 @@ Shindo.tests('Excon request idempotencey') do
48
49
  end
49
50
  }
50
51
 
51
- connection = Excon.new('http://127.0.0.1:9292')
52
- response = connection.request(:method => :get, :idempotent => true, :path => '/some-path')
52
+ response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path')
53
53
  response.status
54
54
  end
55
55
 
@@ -64,8 +64,7 @@ Shindo.tests('Excon request idempotencey') do
64
64
  end
65
65
  }
66
66
 
67
- connection = Excon.new('http://127.0.0.1:9292', :retry_limit => 2)
68
- response = connection.request(:method => :get, :idempotent => true, :path => '/some-path')
67
+ response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :retry_limit => 2)
69
68
  response.status
70
69
  end
71
70
 
@@ -80,8 +79,7 @@ Shindo.tests('Excon request idempotencey') do
80
79
  end
81
80
  }
82
81
 
83
- connection = Excon.new('http://127.0.0.1:9292', :retry_limit => 2)
84
- response = connection.request(:method => :get, :idempotent => true, :path => '/some-path')
82
+ response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :retry_limit => 2)
85
83
  response.status
86
84
  end
87
85
 
@@ -96,8 +94,7 @@ Shindo.tests('Excon request idempotencey') do
96
94
  end
97
95
  }
98
96
 
99
- connection = Excon.new('http://127.0.0.1:9292', :retry_limit => 8)
100
- response = connection.request(:method => :get, :idempotent => true, :path => '/some-path')
97
+ response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :retry_limit => 8)
101
98
  response.status
102
99
  end
103
100
 
@@ -112,16 +109,12 @@ Shindo.tests('Excon request idempotencey') do
112
109
  end
113
110
  }
114
111
 
115
- connection = Excon.new('http://127.0.0.1:9292', :retry_limit => 8)
116
- response = connection.request(:method => :get, :idempotent => true, :path => '/some-path')
112
+ response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :retry_limit => 8)
117
113
  response.status
118
114
  end
119
115
 
120
116
  tests("Retry limit in constructor with socket erroring first 5 times").returns(200) do
121
117
  run_count = 0
122
-
123
- connection = Excon.new('http://127.0.0.1:9292', :retry_limit => 6)
124
-
125
118
  Excon.stub({:method => :get}) { |params|
126
119
  run_count += 1
127
120
  if run_count <= 5 # First 5 calls fail.
@@ -130,9 +123,9 @@ Shindo.tests('Excon request idempotencey') do
130
123
  {:body => params[:body], :headers => params[:headers], :status => 200}
131
124
  end
132
125
  }
133
- response = connection.request(:method => :get, :idempotent => true, :path => '/some-path')
126
+
127
+ response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :retry_limit => 6)
134
128
  response.status
135
129
  end
136
130
 
137
- Excon.mock = false
138
131
  end
@@ -13,9 +13,6 @@ class SimpleInstrumentor
13
13
  end
14
14
 
15
15
  Shindo.tests('Excon instrumentation') do
16
- before do
17
- Excon.mock = true
18
- end
19
16
 
20
17
  after do
21
18
  ActiveSupport::Notifications.unsubscribe("excon")
@@ -25,7 +22,6 @@ Shindo.tests('Excon instrumentation') do
25
22
  ActiveSupport::Notifications.unsubscribe("gug")
26
23
  Delorean.back_to_the_present
27
24
  Excon.stubs.clear
28
- Excon.mock = false
29
25
  end
30
26
 
31
27
  def subscribe(match)
@@ -36,8 +32,11 @@ Shindo.tests('Excon instrumentation') do
36
32
  end
37
33
 
38
34
  def make_request(idempotent = false, params = {})
39
- connection = Excon.new('http://127.0.0.1:9292',
40
- :instrumentor => ActiveSupport::Notifications)
35
+ connection = Excon.new(
36
+ 'http://127.0.0.1:9292',
37
+ :instrumentor => ActiveSupport::Notifications,
38
+ :mock => true
39
+ )
41
40
  if idempotent
42
41
  params[:idempotent] = :true
43
42
  end
@@ -139,8 +138,11 @@ Shindo.tests('Excon instrumentation') do
139
138
  tests('use our own instrumentor').returns(
140
139
  ['excon.request', 'excon.retry', 'excon.retry', 'excon.retry', 'excon.error']) do
141
140
  stub_failure
142
- connection = Excon.new('http://127.0.0.1:9292',
143
- :instrumentor => SimpleInstrumentor)
141
+ connection = Excon.new(
142
+ 'http://127.0.0.1:9292',
143
+ :instrumentor => SimpleInstrumentor,
144
+ :mock => true
145
+ )
144
146
  raises(Excon::Errors::SocketError) do
145
147
  connection.get(:idempotent => true)
146
148
  end
@@ -151,7 +153,7 @@ Shindo.tests('Excon instrumentation') do
151
153
  tests('does not generate events when not provided').returns(0) do
152
154
  subscribe(/excon/)
153
155
  stub_success
154
- connection = Excon.new('http://127.0.0.1:9292')
156
+ connection = Excon.new('http://127.0.0.1:9292', :mock => true)
155
157
  connection.get(:idempotent => true)
156
158
  @events.count
157
159
  end
@@ -160,8 +162,12 @@ Shindo.tests('Excon instrumentation') do
160
162
  ['gug.request', 'gug.retry', 'gug.retry','gug.retry', 'gug.error']) do
161
163
  subscribe(/gug/)
162
164
  stub_failure
163
- connection = Excon.new('http://127.0.0.1:9292',
164
- :instrumentor => ActiveSupport::Notifications, :instrumentor_name => 'gug')
165
+ connection = Excon.new(
166
+ 'http://127.0.0.1:9292',
167
+ :instrumentor => ActiveSupport::Notifications,
168
+ :instrumentor_name => 'gug',
169
+ :mock => true
170
+ )
165
171
  raises(Excon::Errors::SocketError) do
166
172
  connection.get(:idempotent => true)
167
173
  end
@@ -172,8 +178,12 @@ Shindo.tests('Excon instrumentation') do
172
178
  ['gug.request', 'gug.error']) do
173
179
  subscribe(/gug/)
174
180
  stub_failure
175
- connection = Excon.new('http://127.0.0.1:9292',
176
- :instrumentor => ActiveSupport::Notifications, :instrumentor_name => 'gug')
181
+ connection = Excon.new(
182
+ 'http://127.0.0.1:9292',
183
+ :instrumentor => ActiveSupport::Notifications,
184
+ :instrumentor_name => 'gug',
185
+ :mock => true
186
+ )
177
187
  raises(Excon::Errors::SocketError) do
178
188
  connection.get()
179
189
  end
@@ -182,9 +192,8 @@ Shindo.tests('Excon instrumentation') do
182
192
 
183
193
  with_rackup('basic.ru') do
184
194
  tests('works unmocked').returns('excon.request') do
185
- Excon.mock = false
186
195
  subscribe(/excon/)
187
- make_request
196
+ make_request(false, :mock => false)
188
197
  @events.first.name
189
198
  end
190
199
  end
@@ -1,8 +1,7 @@
1
1
  Shindo.tests('Excon stubs') do
2
- Excon.mock = true
3
2
 
4
3
  tests("missing stub").raises(Excon::Errors::StubNotFound) do
5
- connection = Excon.new('http://127.0.0.1:9292')
4
+ connection = Excon.new('http://127.0.0.1:9292', :mock => true)
6
5
  response = connection.request(:method => :get, :path => '/content-length/100')
7
6
  end
8
7
 
@@ -18,7 +17,7 @@ Shindo.tests('Excon stubs') do
18
17
 
19
18
  Excon.stub({:method => :get}, {:body => 'body', :status => 200})
20
19
 
21
- connection = Excon.new('http://127.0.0.1:9292')
20
+ connection = Excon.new('http://127.0.0.1:9292', :mock => true)
22
21
  response = connection.request(:method => :get, :path => '/content-length/100')
23
22
 
24
23
  tests('response.body').returns('body') do
@@ -41,7 +40,7 @@ Shindo.tests('Excon stubs') do
41
40
  body
42
41
  end
43
42
 
44
- Excon.stubs.pop
43
+ Excon.stubs.clear
45
44
 
46
45
  end
47
46
 
@@ -49,7 +48,7 @@ Shindo.tests('Excon stubs') do
49
48
 
50
49
  Excon.stub({:body => 'body', :method => :get}) {|params| {:body => params[:body], :headers => params[:headers], :status => 200}}
51
50
 
52
- connection = Excon.new('http://127.0.0.1:9292')
51
+ connection = Excon.new('http://127.0.0.1:9292', :mock => true)
53
52
  response = connection.request(:body => 'body', :method => :get, :path => '/content-length/100')
54
53
 
55
54
  tests('response.body').returns('body') do
@@ -72,17 +71,19 @@ Shindo.tests('Excon stubs') do
72
71
  body
73
72
  end
74
73
 
75
- Excon.stubs.pop
74
+ Excon.stubs.clear
76
75
 
77
76
  end
78
77
 
79
78
  tests("mismatched stub").raises(Excon::Errors::StubNotFound) do
80
79
  Excon.stub({:method => :post}, {:body => 'body'})
81
- Excon.get('http://127.0.0.1:9292/')
80
+ Excon.get('http://127.0.0.1:9292/', :mock => true)
82
81
  end
83
82
 
83
+ Excon.stubs.clear
84
+
84
85
  tests("stub({}, {:body => 'x' * (Excon::CHUNK_SIZE + 1)})") do
85
- connection = Excon.new('http://127.0.0.1:9292')
86
+ connection = Excon.new('http://127.0.0.1:9292', :mock => true)
86
87
  Excon.stub({}, {:body => 'x' * (Excon::CHUNK_SIZE + 1)})
87
88
 
88
89
  test("with block") do
@@ -95,7 +96,6 @@ Shindo.tests('Excon stubs') do
95
96
  end
96
97
 
97
98
  Excon.stubs.clear
98
- Excon.mock = false
99
99
 
100
100
  tests('mock = false') do
101
101
  with_rackup('basic.ru') do
metadata CHANGED
@@ -1,91 +1,129 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: excon
3
- version: !ruby/object:Gem::Version
4
- version: 0.9.0
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 9
8
+ - 1
9
+ segments_generated: true
10
+ version: 0.9.1
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - dpiddy (Dan Peterson)
9
14
  - geemus (Wesley Beary)
10
15
  - nextmat (Matt Sanders)
11
16
  autorequire:
12
17
  bindir: bin
13
18
  cert_chain: []
14
- date: 2011-12-14 00:00:00.000000000Z
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: open4
18
- requirement: &70338621231260 !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
21
- - - ! '>='
22
- - !ruby/object:Gem::Version
23
- version: '0'
19
+
20
+ date: 2011-12-15 00:00:00 -06:00
21
+ default_executable:
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 3
30
+ - 1
31
+ - 3
32
+ segments_generated: true
33
+ version: 3.1.3
34
+ requirement: *id001
35
+ name: activesupport
36
+ prerelease: false
24
37
  type: :development
38
+ - !ruby/object:Gem::Dependency
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 0
45
+ segments_generated: true
46
+ version: "0"
47
+ requirement: *id002
48
+ name: delorean
25
49
  prerelease: false
26
- version_requirements: *70338621231260
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: &70338621230800 !ruby/object:Gem::Requirement
30
- none: false
31
- requirements:
32
- - - ! '>='
33
- - !ruby/object:Gem::Version
34
- version: '0'
35
50
  type: :development
51
+ - !ruby/object:Gem::Dependency
52
+ version_requirements: &id003 !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 0
58
+ segments_generated: true
59
+ version: "0"
60
+ requirement: *id003
61
+ name: open4
36
62
  prerelease: false
37
- version_requirements: *70338621230800
38
- - !ruby/object:Gem::Dependency
39
- name: shindo
40
- requirement: &70338621230300 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - =
44
- - !ruby/object:Gem::Version
45
- version: 0.2.0
46
63
  type: :development
64
+ - !ruby/object:Gem::Dependency
65
+ version_requirements: &id004 !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ segments_generated: true
72
+ version: "0"
73
+ requirement: *id004
74
+ name: rake
47
75
  prerelease: false
48
- version_requirements: *70338621230300
49
- - !ruby/object:Gem::Dependency
50
- name: sinatra
51
- requirement: &70338621229880 !ruby/object:Gem::Requirement
52
- none: false
53
- requirements:
54
- - - ! '>='
55
- - !ruby/object:Gem::Version
56
- version: '0'
57
76
  type: :development
77
+ - !ruby/object:Gem::Dependency
78
+ version_requirements: &id005 !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ segments:
83
+ - 0
84
+ segments_generated: true
85
+ version: "0"
86
+ requirement: *id005
87
+ name: rdoc
58
88
  prerelease: false
59
- version_requirements: *70338621229880
60
- - !ruby/object:Gem::Dependency
61
- name: activesupport
62
- requirement: &70338621220620 !ruby/object:Gem::Requirement
63
- none: false
64
- requirements:
65
- - - ~>
66
- - !ruby/object:Gem::Version
67
- version: 3.1.3
68
89
  type: :development
90
+ - !ruby/object:Gem::Dependency
91
+ version_requirements: &id006 !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "="
94
+ - !ruby/object:Gem::Version
95
+ segments:
96
+ - 0
97
+ - 2
98
+ - 0
99
+ segments_generated: true
100
+ version: 0.2.0
101
+ requirement: *id006
102
+ name: shindo
69
103
  prerelease: false
70
- version_requirements: *70338621220620
71
- - !ruby/object:Gem::Dependency
72
- name: delorean
73
- requirement: &70338621220200 !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
76
- - - ! '>='
77
- - !ruby/object:Gem::Version
78
- version: '0'
79
104
  type: :development
105
+ - !ruby/object:Gem::Dependency
106
+ version_requirements: &id007 !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ segments:
111
+ - 0
112
+ segments_generated: true
113
+ version: "0"
114
+ requirement: *id007
115
+ name: sinatra
80
116
  prerelease: false
81
- version_requirements: *70338621220200
117
+ type: :development
82
118
  description: EXtended http(s) CONnections
83
119
  email: geemus@gmail.com
84
120
  executables: []
121
+
85
122
  extensions: []
86
- extra_rdoc_files:
123
+
124
+ extra_rdoc_files:
87
125
  - README.rdoc
88
- files:
126
+ files:
89
127
  - Gemfile
90
128
  - README.rdoc
91
129
  - Rakefile
@@ -134,29 +172,37 @@ files:
134
172
  - tests/stub_tests.rb
135
173
  - tests/test_helper.rb
136
174
  - tests/thread_safety_tests.rb
175
+ has_rdoc: true
137
176
  homepage: https://github.com/geemus/excon
138
177
  licenses: []
178
+
139
179
  post_install_message:
140
- rdoc_options:
180
+ rdoc_options:
141
181
  - --charset=UTF-8
142
- require_paths:
182
+ require_paths:
143
183
  - lib
144
- required_ruby_version: !ruby/object:Gem::Requirement
145
- none: false
146
- requirements:
147
- - - ! '>='
148
- - !ruby/object:Gem::Version
149
- version: '0'
150
- required_rubygems_version: !ruby/object:Gem::Requirement
151
- none: false
152
- requirements:
153
- - - ! '>='
154
- - !ruby/object:Gem::Version
155
- version: '0'
184
+ required_ruby_version: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ segments:
189
+ - 0
190
+ segments_generated: true
191
+ version: "0"
192
+ required_rubygems_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ segments:
197
+ - 0
198
+ segments_generated: true
199
+ version: "0"
156
200
  requirements: []
201
+
157
202
  rubyforge_project: excon
158
- rubygems_version: 1.8.10
203
+ rubygems_version: 1.3.6
159
204
  signing_key:
160
205
  specification_version: 2
161
206
  summary: speed, persistence, http(s)
162
207
  test_files: []
208
+