httpadapter 0.2.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,236 +13,115 @@
13
13
  # limitations under the License.
14
14
 
15
15
  require 'spec_helper'
16
+ require 'spec/httpadapter/adapter_type_checking_spec'
16
17
 
17
18
  require 'httpadapter'
18
19
 
19
20
  class StubAdapter
20
- def to_ary
21
+ include HTTPAdapter
22
+
23
+ def convert_request_to_a(request_obj)
24
+ if request_obj == 42
25
+ raise TypeError, "This should never be fourty-two."
26
+ end
21
27
  return ['GET', '/', [], [""]]
22
28
  end
23
29
 
24
- def self.from_ary(array)
25
- return Object.new
30
+ def convert_request_from_a(request_ary)
31
+ if request_ary == 42
32
+ raise TypeError, "This should never be fourty-two."
33
+ end
34
+ return :stubbed_request
26
35
  end
27
36
 
28
- def self.transmit(request, connection=nil)
37
+ def convert_response_to_a(response_obj)
38
+ if response_obj == 42
39
+ raise TypeError, "This should never be fourty-two."
40
+ end
29
41
  return [200, [], ['']]
30
42
  end
31
- end
32
-
33
- class BogusAdapter
34
- def initialize(request)
35
- end
36
- end
37
-
38
- describe HTTPAdapter, 'when attempting to specialize a request' do
39
- it 'should raise an error for converting from an invalid tuple' do
40
- (lambda do
41
- HTTPAdapter.specialize_request(42, StubAdapter)
42
- end).should raise_error(TypeError)
43
- end
44
-
45
- it 'should raise an error for converting from an invalid tuple' do
46
- (lambda do
47
- HTTPAdapter.specialize_request([42], StubAdapter)
48
- end).should raise_error(TypeError)
49
- end
50
-
51
- it 'should raise an error for converting from an invalid tuple' do
52
- (lambda do
53
- HTTPAdapter.specialize_request(
54
- [42, 42, 42, 42], StubAdapter
55
- )
56
- end).should raise_error(TypeError)
57
- end
58
-
59
- it 'should raise an error for converting from an invalid tuple' do
60
- (lambda do
61
- HTTPAdapter.specialize_request(
62
- ['GET', 42, [], ['']], StubAdapter
63
- )
64
- end).should raise_error(TypeError)
65
- end
66
-
67
- it 'should raise an error for converting from an invalid tuple' do
68
- (lambda do
69
- HTTPAdapter.specialize_request(
70
- ['GET', '/', 42, ['']], StubAdapter
71
- )
72
- end).should raise_error(TypeError)
73
- end
74
-
75
- it 'should raise an error for converting from an invalid tuple' do
76
- (lambda do
77
- HTTPAdapter.specialize_request(
78
- ['GET', '/', [42], ['']], StubAdapter
79
- )
80
- end).should raise_error(TypeError)
81
- end
82
-
83
- it 'should raise an error for converting from an invalid tuple' do
84
- (lambda do
85
- HTTPAdapter.specialize_request(
86
- ['GET', '/', [[42, 'value']], ['']], StubAdapter
87
- )
88
- end).should raise_error(TypeError)
89
- end
90
-
91
- it 'should raise an error for converting from an invalid tuple' do
92
- (lambda do
93
- HTTPAdapter.specialize_request(
94
- ['GET', '/', [['X', 42]], ['']], StubAdapter
95
- )
96
- end).should raise_error(TypeError)
97
- end
98
-
99
- it 'should raise an error for converting from an invalid tuple' do
100
- (lambda do
101
- HTTPAdapter.specialize_request(
102
- ['GET', '/', [], 42], StubAdapter
103
- )
104
- end).should raise_error(TypeError)
105
- end
106
43
 
107
- it 'should raise an error for converting from an invalid tuple' do
108
- (lambda do
109
- HTTPAdapter.specialize_request(
110
- ['GET', '/', [], ''], StubAdapter
111
- )
112
- end).should raise_error(TypeError)
44
+ def convert_response_from_a(response_ary)
45
+ if response_ary == 42
46
+ raise TypeError, "This should never be fourty-two."
47
+ end
48
+ return :stubbed_response
113
49
  end
114
50
 
115
- it 'should raise an error for converting from an invalid adapter' do
116
- (lambda do
117
- HTTPAdapter.specialize_request(
118
- ['GET', '/', [], ['']], Object
119
- )
120
- end).should raise_error(TypeError)
51
+ def fetch_resource(request_ary, connection=nil)
52
+ if request_ary == 42 || connection == 42
53
+ raise TypeError, "This should never be fourty-two."
54
+ end
55
+ return [200, [], ['']]
121
56
  end
122
57
  end
123
58
 
124
- describe HTTPAdapter, 'when attempting to adapt a request' do
125
- it 'should raise an error for converting from an invalid adapter' do
126
- (lambda do
127
- HTTPAdapter.adapt_request(
128
- Object.new, BogusAdapter
129
- )
130
- end).should raise_error(TypeError)
131
- end
59
+ class BogusAdapter
60
+ include HTTPAdapter
132
61
  end
133
62
 
134
- describe HTTPAdapter, 'when attempting to specialize a response' do
135
- it 'should raise an error for converting from an invalid tuple' do
136
- (lambda do
137
- HTTPAdapter.specialize_response(42, StubAdapter)
138
- end).should raise_error(TypeError)
139
- end
140
-
141
- it 'should raise an error for converting from an invalid tuple' do
142
- (lambda do
143
- HTTPAdapter.specialize_response([42], StubAdapter)
144
- end).should raise_error(TypeError)
145
- end
146
-
147
- it 'should raise an error for converting from an invalid tuple' do
148
- (lambda do
149
- HTTPAdapter.specialize_response(
150
- [42, 42, 42], StubAdapter
151
- )
152
- end).should raise_error(TypeError)
63
+ describe StubAdapter, 'a stubbed adapter class that does nothing' do
64
+ before do
65
+ @adapter = StubAdapter.new
66
+ @request = ['GET', '/', [], ['']]
67
+ @response = [200, [], ['']]
153
68
  end
154
69
 
155
- it 'should raise an error for converting from an invalid tuple' do
156
- (lambda do
157
- HTTPAdapter.specialize_response(
158
- [Object.new, [], ['']], StubAdapter
159
- )
160
- end).should raise_error(TypeError)
161
- end
70
+ it_should_behave_like 'adapter type-checking example'
162
71
 
163
- it 'should raise an error for converting from an invalid tuple' do
164
- (lambda do
165
- HTTPAdapter.specialize_response(
166
- ['', 42, ['']], StubAdapter
167
- )
168
- end).should raise_error(TypeError)
72
+ it 'should convert to a stubbed request object' do
73
+ @adapter.specialize_request(@request).should == :stubbed_request
169
74
  end
170
75
 
171
- it 'should raise an error for converting from an invalid tuple' do
172
- (lambda do
173
- HTTPAdapter.specialize_response(
174
- [200, [42], ['']], StubAdapter
175
- )
176
- end).should raise_error(TypeError)
76
+ it 'should convert to a stubbed response object' do
77
+ @adapter.specialize_response(@response).should == :stubbed_response
177
78
  end
178
79
 
179
- it 'should raise an error for converting from an invalid tuple' do
180
- (lambda do
181
- HTTPAdapter.specialize_response(
182
- [200, [[42, 'value']], ['']], StubAdapter
183
- )
184
- end).should raise_error(TypeError)
80
+ it 'should convert to a stubbed request array' do
81
+ @adapter.adapt_request(Object.new).should == @request
185
82
  end
186
83
 
187
- it 'should raise an error for converting from an invalid tuple' do
188
- (lambda do
189
- HTTPAdapter.specialize_response(
190
- [200, [['X', 42]], ['']], StubAdapter
191
- )
192
- end).should raise_error(TypeError)
84
+ it 'should convert to a stubbed response array' do
85
+ @adapter.adapt_response(Object.new).should == @response
193
86
  end
87
+ end
194
88
 
195
- it 'should raise an error for converting from an invalid tuple' do
196
- (lambda do
197
- HTTPAdapter.specialize_response(
198
- [200, [], 42], StubAdapter
199
- )
200
- end).should raise_error(TypeError)
89
+ describe BogusAdapter, 'an empty class that does nothing' do
90
+ before do
91
+ @adapter = BogusAdapter.new
92
+ @request = ['GET', '/', [], ['']]
93
+ @response = [200, [], ['']]
201
94
  end
202
95
 
203
- it 'should raise an error for converting from an invalid tuple' do
204
- (lambda do
205
- HTTPAdapter.specialize_response(
206
- [200, [], ''], StubAdapter
207
- )
208
- end).should raise_error(TypeError)
209
- end
96
+ it_should_behave_like 'adapter type-checking example'
210
97
 
211
- it 'should raise an error for converting from an invalid adapter' do
98
+ it 'should raise an error when attempting to adapt a request' do
212
99
  (lambda do
213
- HTTPAdapter.specialize_response(
214
- [200, [], ['']], Object
215
- )
100
+ @adapter.adapt_request(Object.new)
216
101
  end).should raise_error(TypeError)
217
102
  end
218
- end
219
103
 
220
- describe HTTPAdapter, 'when attempting to adapt a response' do
221
- it 'should raise an error for converting from an invalid adapter' do
104
+ it 'should raise an error when attempting to specialize a request' do
222
105
  (lambda do
223
- HTTPAdapter.adapt_response(
224
- Object.new, BogusAdapter
225
- )
106
+ @adapter.specialize_request(@request)
226
107
  end).should raise_error(TypeError)
227
108
  end
228
- end
229
109
 
230
- describe HTTPAdapter, 'when attempting to transmit a request' do
231
- it 'should raise an error for invalid request objects' do
110
+ it 'should raise an error when attempting to adapt a response' do
232
111
  (lambda do
233
- HTTPAdapter.transmit(42, StubAdapter)
112
+ @adapter.adapt_response(Object.new)
234
113
  end).should raise_error(TypeError)
235
114
  end
236
115
 
237
- it 'should raise an error for invalid adapter objects' do
116
+ it 'should raise an error when attempting to specialize a response' do
238
117
  (lambda do
239
- HTTPAdapter.transmit(['GET', '/', [], ['']], BogusAdapter)
118
+ @adapter.specialize_response(@response)
240
119
  end).should raise_error(TypeError)
241
120
  end
242
121
 
243
- it 'should raise an error for invalid connection objects' do
122
+ it 'should raise an error when attempting to transmit a request' do
244
123
  (lambda do
245
- HTTPAdapter.transmit(['GET', '/', [], ['']], StubAdapter, 42)
124
+ @adapter.transmit(@request)
246
125
  end).should raise_error(TypeError)
247
126
  end
248
127
  end
data/tasks/gem.rake CHANGED
@@ -19,8 +19,8 @@ namespace :gem do
19
19
  s.files = PKG_FILES.to_a
20
20
 
21
21
  s.has_rdoc = true
22
- s.extra_rdoc_files = %w( README )
23
- s.rdoc_options.concat ["--main", "README"]
22
+ s.extra_rdoc_files = %w( README.md )
23
+ s.rdoc_options.concat ["--main", "README.md"]
24
24
 
25
25
  s.add_runtime_dependency("addressable", "~> 2.2.0")
26
26
 
data/tasks/rdoc.rake CHANGED
@@ -8,7 +8,7 @@ namespace :doc do
8
8
  rdoc.options << "--line-numbers" << "--inline-source" <<
9
9
  "--accessor" << "cattr_accessor=object" << "--charset" << "utf-8"
10
10
  rdoc.template = "#{ENV["template"]}.rb" if ENV["template"]
11
- rdoc.rdoc_files.include("README", "CHANGELOG", "LICENSE")
11
+ rdoc.rdoc_files.include("README.md", "CHANGELOG", "LICENSE")
12
12
  rdoc.rdoc_files.include("lib/**/*.rb")
13
13
  end
14
14
 
data/tasks/spec.rake CHANGED
@@ -15,10 +15,13 @@ namespace :spec do
15
15
  t.rcov = false
16
16
  end
17
17
  t.rcov_opts = [
18
+ '--exclude', 'lib\\/compat',
18
19
  '--exclude', 'spec',
20
+ '--exclude', '\\.rvm\\/gems',
19
21
  '--exclude', '1\\.8\\/gems',
20
22
  '--exclude', '1\\.9\\/gems',
21
- '--exclude', 'addressable\\/idna\\.rb', # unicode tables too big
23
+ '--exclude', '\\.rvm',
24
+ '--exclude', '\\/Library\\/Ruby'
22
25
  ]
23
26
  end
24
27
 
data/tasks/yard.rake CHANGED
@@ -10,7 +10,7 @@ begin
10
10
  yardoc.name = 'yard'
11
11
  yardoc.options = ['--verbose']
12
12
  yardoc.files = [
13
- 'lib/**/*.rb', 'ext/**/*.c', 'README', 'CHANGELOG', 'LICENSE'
13
+ 'lib/**/*.rb', 'ext/**/*.c', 'README.md', 'CHANGELOG', 'LICENSE'
14
14
  ]
15
15
  end
16
16
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httpadapter
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
5
- prerelease: false
4
+ hash: 23
5
+ prerelease:
6
6
  segments:
7
- - 0
8
- - 2
9
7
  - 1
10
- version: 0.2.1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bob Aman
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-04 00:00:00 -08:00
18
+ date: 2011-03-11 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -139,7 +139,7 @@ executables: []
139
139
  extensions: []
140
140
 
141
141
  extra_rdoc_files:
142
- - README
142
+ - README.md
143
143
  files:
144
144
  - lib/httpadapter/adapters/mock.rb
145
145
  - lib/httpadapter/adapters/net_http.rb
@@ -148,14 +148,11 @@ files:
148
148
  - lib/httpadapter/connection.rb
149
149
  - lib/httpadapter/version.rb
150
150
  - lib/httpadapter.rb
151
- - spec/httpadapter/adapters/net_http_request_spec.rb
152
- - spec/httpadapter/adapters/net_http_response_spec.rb
153
- - spec/httpadapter/adapters/net_http_transmission_spec.rb
154
- - spec/httpadapter/adapters/rack_request_spec.rb
155
- - spec/httpadapter/adapters/rack_response_spec.rb
156
- - spec/httpadapter/adapters/typhoeus_request_spec.rb
157
- - spec/httpadapter/adapters/typhoeus_response_spec.rb
158
- - spec/httpadapter/adapters/typhoeus_transmission_spec.rb
151
+ - spec/httpadapter/adapter_type_checking_spec.rb
152
+ - spec/httpadapter/adapters/mock_adapter_spec.rb
153
+ - spec/httpadapter/adapters/net_http_spec.rb
154
+ - spec/httpadapter/adapters/rack_spec.rb
155
+ - spec/httpadapter/adapters/typhoeus_spec.rb
159
156
  - spec/httpadapter/connection_spec.rb
160
157
  - spec/httpadapter_spec.rb
161
158
  - spec/spec.opts
@@ -172,7 +169,7 @@ files:
172
169
  - CHANGELOG
173
170
  - LICENSE
174
171
  - Rakefile
175
- - README
172
+ - README.md
176
173
  has_rdoc: true
177
174
  homepage: http://httpadapter.rubyforge.org/
178
175
  licenses: []
@@ -180,7 +177,7 @@ licenses: []
180
177
  post_install_message:
181
178
  rdoc_options:
182
179
  - --main
183
- - README
180
+ - README.md
184
181
  require_paths:
185
182
  - lib
186
183
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -204,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
201
  requirements: []
205
202
 
206
203
  rubyforge_project: httpadapter
207
- rubygems_version: 1.3.7
204
+ rubygems_version: 1.4.1
208
205
  signing_key:
209
206
  specification_version: 3
210
207
  summary: Package Summary
data/README DELETED
@@ -1,49 +0,0 @@
1
- == HTTPAdapter
2
-
3
- Homepage:: httpadapter.rubyforge.org[http://httpadapter.rubyforge.org/]
4
- Author:: Bob Aman (mailto:bob@sporkmonger.com)
5
- Copyright:: Copyright © 2010 Google Inc.
6
- License:: Apache 2.0
7
-
8
- == Description
9
-
10
- A library for translating HTTP request and response objects for various clients into a common representation.
11
-
12
- == Reference
13
-
14
- - {HTTPAdapter}
15
-
16
- == Adapters
17
-
18
- - {HTTPAdapter::NetHTTPRequestAdapter}
19
- - {HTTPAdapter::NetHTTPResponseAdapter}
20
- - {HTTPAdapter::RackRequestAdapter}
21
- - {HTTPAdapter::RackResponseAdapter}
22
- - {HTTPAdapter::TyphoeusRequestAdapter}
23
- - {HTTPAdapter::TyphoeusResponseAdapter}
24
-
25
- == Example Usage
26
-
27
- response = Net::HTTP.start('www.google.com', 80) { |http| http.get('/') }
28
- # => #<Net::HTTPOK 200 OK readbody=true>
29
- result = HTTPAdapter.adapt_response(
30
- response, HTTPAdapter::NetHTTPResponseAdapter
31
- )
32
- # => [
33
- # 200,
34
- # [
35
- # ["Expires", "-1"],
36
- # ["Content-Type", "text/html; charset=ISO-8859-1"],
37
- # ["X-Xss-Protection", "1; mode=block"],
38
- # ["Server", "gws"],
39
- # ["Date", "Thu, 26 Aug 2010 22:13:03 GMT"],
40
- # ["Set-Cookie", "<snip>"],
41
- # ["Cache-Control", "private, max-age=0"],
42
- # ["Transfer-Encoding", "chunked"]
43
- # ],
44
- # ["<snip>"]
45
- # ]
46
-
47
- == Install
48
-
49
- * sudo gem install httpadapter