http 0.5.0.pre → 0.5.0.pre2

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

Potentially problematic release.


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

@@ -1,34 +1,34 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Http::Response do
3
+ describe HTTP::Response do
4
4
  describe "headers" do
5
- subject { Http::Response.new(200, "1.1", "Content-Type" => "text/plain") }
5
+ subject { HTTP::Response.new(200, "1.1", "Content-Type" => "text/plain") }
6
6
 
7
7
  it "exposes header fields for easy access" do
8
- subject["Content-Type"].should eq("text/plain")
8
+ expect(subject["Content-Type"]).to eq("text/plain")
9
9
  end
10
10
 
11
11
  it "provides a #headers accessor too" do
12
- subject.headers.should eq("Content-Type" => "text/plain")
12
+ expect(subject.headers).to eq("Content-Type" => "text/plain")
13
13
  end
14
14
  end
15
15
 
16
16
  describe "#parse_body" do
17
17
  context "on a registered MIME type" do
18
18
  let(:body) { ::JSON.dump("Hello" => "World") }
19
- subject { Http::Response.new(200, "1.1", {"Content-Type" => "application/json"}, body) }
19
+ subject { HTTP::Response.new(200, "1.1", {"Content-Type" => "application/json"}, body) }
20
20
 
21
21
  it "returns a parsed response body" do
22
- subject.parse_body.should eq ::JSON.parse(body)
22
+ expect(subject.parse_body).to eq ::JSON.parse(body)
23
23
  end
24
24
  end
25
25
 
26
26
  context "on an unregistered MIME type" do
27
27
  let(:body) { "Hello world" }
28
- subject { Http::Response.new(200, "1.1", {"Content-Type" => "text/plain"}, body) }
28
+ subject { HTTP::Response.new(200, "1.1", {"Content-Type" => "text/plain"}, body) }
29
29
 
30
30
  it "returns the raw body as a String" do
31
- subject.parse_body.should eq(body)
31
+ expect(subject.parse_body).to eq(body)
32
32
  end
33
33
  end
34
34
  end
@@ -37,20 +37,20 @@ describe Http::Response do
37
37
  context "on a registered MIME type" do
38
38
  let(:body) { ::JSON.dump("Hello" => "World") }
39
39
  let(:content_type) { "application/json" }
40
- subject { Http::Response.new(200, "1.1", {"Content-Type" => content_type}, body) }
40
+ subject { HTTP::Response.new(200, "1.1", {"Content-Type" => content_type}, body) }
41
41
 
42
42
  it "retuns a Rack-like array with a parsed response body" do
43
- subject.to_a.should eq([200, {"Content-Type" => content_type}, ::JSON.parse(body)])
43
+ expect(subject.to_a).to eq([200, {"Content-Type" => content_type}, ::JSON.parse(body)])
44
44
  end
45
45
  end
46
46
 
47
47
  context "on an unregistered MIME type" do
48
48
  let(:body) { "Hello world" }
49
49
  let(:content_type) { "text/plain" }
50
- subject { Http::Response.new(200, "1.1", {"Content-Type" => content_type}, body) }
50
+ subject { HTTP::Response.new(200, "1.1", {"Content-Type" => content_type}, body) }
51
51
 
52
52
  it "returns a Rack-like array" do
53
- subject.to_a.should eq([200, {"Content-Type" => content_type}, body])
53
+ expect(subject.to_a).to eq([200, {"Content-Type" => content_type}, body])
54
54
  end
55
55
  end
56
56
  end
data/spec/http_spec.rb CHANGED
@@ -1,79 +1,79 @@
1
1
  require 'spec_helper'
2
2
  require 'json'
3
3
 
4
- describe Http do
4
+ describe HTTP do
5
5
  let(:test_endpoint) { "http://127.0.0.1:#{ExampleService::PORT}/" }
6
6
  let(:proxy_endpoint) { "#{test_endpoint}proxy" }
7
7
 
8
8
  context "getting resources" do
9
9
  it "should be easy" do
10
- response = Http.get test_endpoint
11
- response.should match(/<!doctype html>/)
10
+ response = HTTP.get test_endpoint
11
+ expect(response).to match(/<!doctype html>/)
12
12
  end
13
13
 
14
14
  it "should be easy to get a response object" do
15
- response = Http.get(test_endpoint).response
16
- response.should be_a Http::Response
15
+ response = HTTP.get(test_endpoint).response
16
+ expect(response).to be_a HTTP::Response
17
17
  end
18
18
 
19
19
  context "with_response" do
20
20
  it 'allows specifying :object' do
21
- res = Http.with_response(:object).get test_endpoint
22
- res.should be_a(Http::Response)
21
+ res = HTTP.with_response(:object).get test_endpoint
22
+ expect(res).to be_a(HTTP::Response)
23
23
  end
24
24
  end
25
25
 
26
26
  context "with query string parameters" do
27
27
 
28
28
  it "should be easy" do
29
- response = Http.get "#{test_endpoint}params" , :params => {:foo => 'bar'}
30
- response.should match(/Params!/)
29
+ response = HTTP.get "#{test_endpoint}params" , :params => {:foo => 'bar'}
30
+ expect(response).to match(/Params!/)
31
31
  end
32
32
  end
33
33
 
34
34
  context "with headers" do
35
35
  it "should be easy" do
36
- response = Http.accept(:json).get test_endpoint
37
- response['json'].should be_true
36
+ response = HTTP.accept(:json).get test_endpoint
37
+ expect(response['json']).to be_true
38
38
  end
39
39
  end
40
40
 
41
41
  context "with callbacks" do
42
42
  it "fires a request callback" do
43
- pending 'Http::Request is not yet implemented'
43
+ pending 'HTTP::Request is not yet implemented'
44
44
 
45
45
  request = nil
46
- Http.on(:request) {|r| request = r}.get test_endpoint
47
- request.should be_a Http::Request
46
+ HTTP.on(:request) {|r| request = r}.get test_endpoint
47
+ expect(request).to be_a HTTP::Request
48
48
  end
49
49
 
50
50
  it "fires a response callback" do
51
51
  response = nil
52
- Http.on(:response) {|r| response = r}.get test_endpoint
53
- response.should be_a Http::Response
52
+ HTTP.on(:response) {|r| response = r}.get test_endpoint
53
+ expect(response).to be_a HTTP::Response
54
54
  end
55
55
  end
56
56
 
57
57
  it "should not mess with the returned status" do
58
- client = Http.with_response(:object)
58
+ client = HTTP.with_response(:object)
59
59
  res = client.get test_endpoint
60
- res.status.should == 200
60
+ expect(res.status).to eq(200)
61
61
  res = client.get "#{test_endpoint}not-found"
62
- res.status.should == 404
62
+ expect(res.status).to eq(404)
63
63
  end
64
64
  end
65
65
 
66
66
  context "with http proxy address and port" do
67
67
  it "should proxy the request" do
68
- response = Http.via("127.0.0.1", 8080).get proxy_endpoint
69
- response.should match(/Proxy!/)
68
+ response = HTTP.via("127.0.0.1", 8080).get proxy_endpoint
69
+ expect(response).to match(/Proxy!/)
70
70
  end
71
71
  end
72
72
 
73
73
  context "with http proxy address, port username and password" do
74
74
  it "should proxy the request" do
75
- response = Http.via("127.0.0.1", 8081, "username", "password").get proxy_endpoint
76
- response.should match(/Proxy!/)
75
+ response = HTTP.via("127.0.0.1", 8081, "username", "password").get proxy_endpoint
76
+ expect(response).to match(/Proxy!/)
77
77
  end
78
78
  end
79
79
 
@@ -81,55 +81,55 @@ describe Http do
81
81
  it "should proxy the request" do
82
82
  pending "fixing proxy support"
83
83
 
84
- response = Http.via("127.0.0.1", 8081, "user", "pass").get proxy_endpoint
85
- response.should match(/Proxy Authentication Required/)
84
+ response = HTTP.via("127.0.0.1", 8081, "user", "pass").get proxy_endpoint
85
+ expect(response).to match(/Proxy Authentication Required/)
86
86
  end
87
87
  end
88
88
 
89
89
  context "without proxy port" do
90
90
  it "should raise an argument error" do
91
- expect { Http.via("127.0.0.1") }.to raise_error ArgumentError
91
+ expect { HTTP.via("127.0.0.1") }.to raise_error ArgumentError
92
92
  end
93
93
  end
94
94
 
95
95
  context "posting to resources" do
96
96
  it "should be easy to post forms" do
97
- response = Http.post "#{test_endpoint}form", :form => {:example => 'testing-form'}
98
- response.should == "passed :)"
97
+ response = HTTP.post "#{test_endpoint}form", :form => {:example => 'testing-form'}
98
+ expect(response).to eq("passed :)")
99
99
  end
100
100
  end
101
101
 
102
102
  context "posting with an explicit body" do
103
103
  it "should be easy to post" do
104
- response = Http.post "#{test_endpoint}body", :body => "testing-body"
105
- response.should == "passed :)"
104
+ response = HTTP.post "#{test_endpoint}body", :body => "testing-body"
105
+ expect(response).to eq("passed :)")
106
106
  end
107
107
  end
108
108
 
109
109
  context "with redirects" do
110
110
  it "should be easy for 301" do
111
- response = Http.with_follow(true).get("#{test_endpoint}redirect-301")
112
- response.should match(/<!doctype html>/)
111
+ response = HTTP.with_follow(true).get("#{test_endpoint}redirect-301")
112
+ expect(response).to match(/<!doctype html>/)
113
113
  end
114
114
 
115
115
  it "should be easy for 302" do
116
- response = Http.with_follow(true).get("#{test_endpoint}redirect-302")
117
- response.should match(/<!doctype html>/)
116
+ response = HTTP.with_follow(true).get("#{test_endpoint}redirect-302")
117
+ expect(response).to match(/<!doctype html>/)
118
118
  end
119
119
 
120
120
  end
121
121
 
122
122
  context "head requests" do
123
123
  it "should be easy" do
124
- response = Http.head test_endpoint
125
- response.status.should == 200
126
- response['content-type'].should match(/html/)
124
+ response = HTTP.head test_endpoint
125
+ expect(response.status).to eq(200)
126
+ expect(response['content-type']).to match(/html/)
127
127
  end
128
128
  end
129
129
 
130
130
  it "should be chainable" do
131
- response = Http.accept(:json).on(:response){|r| seen = r}.get(test_endpoint)
132
- response['json'].should be_true
131
+ response = HTTP.accept(:json).on(:response){|r| r}.get(test_endpoint)
132
+ expect(response['json']).to be_true
133
133
  end
134
134
 
135
135
  end
data/spec/spec_helper.rb CHANGED
@@ -3,3 +3,9 @@ require 'support/example_server'
3
3
  require 'support/proxy_server'
4
4
  require 'coveralls'
5
5
  Coveralls.wear!
6
+
7
+ RSpec.configure do |config|
8
+ config.expect_with :rspec do |c|
9
+ c.syntax = :expect
10
+ end
11
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.pre
4
+ version: 0.5.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Arcieri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-06 00:00:00.000000000 Z
11
+ date: 2013-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http_parser.rb
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - '>='
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '2.11'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '2.11'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: json
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -89,7 +89,7 @@ files:
89
89
  - lib/http.rb
90
90
  - lib/http/chainable.rb
91
91
  - lib/http/client.rb
92
- - lib/http/compat/curb.rb
92
+ - lib/http/header.rb
93
93
  - lib/http/mime_type.rb
94
94
  - lib/http/mime_types/json.rb
95
95
  - lib/http/options.rb
@@ -99,7 +99,6 @@ files:
99
99
  - lib/http/response_parser.rb
100
100
  - lib/http/uri_backport.rb
101
101
  - lib/http/version.rb
102
- - spec/http/compat/curb_spec.rb
103
102
  - spec/http/options/body_spec.rb
104
103
  - spec/http/options/callbacks_spec.rb
105
104
  - spec/http/options/form_spec.rb
@@ -109,6 +108,7 @@ files:
109
108
  - spec/http/options/proxy_spec.rb
110
109
  - spec/http/options/response_spec.rb
111
110
  - spec/http/options_spec.rb
111
+ - spec/http/request_spec.rb
112
112
  - spec/http/request_stream_spec.rb
113
113
  - spec/http/response_spec.rb
114
114
  - spec/http_spec.rb
@@ -139,7 +139,6 @@ signing_key:
139
139
  specification_version: 4
140
140
  summary: HTTP should be easy
141
141
  test_files:
142
- - spec/http/compat/curb_spec.rb
143
142
  - spec/http/options/body_spec.rb
144
143
  - spec/http/options/callbacks_spec.rb
145
144
  - spec/http/options/form_spec.rb
@@ -149,6 +148,7 @@ test_files:
149
148
  - spec/http/options/proxy_spec.rb
150
149
  - spec/http/options/response_spec.rb
151
150
  - spec/http/options_spec.rb
151
+ - spec/http/request_spec.rb
152
152
  - spec/http/request_stream_spec.rb
153
153
  - spec/http/response_spec.rb
154
154
  - spec/http_spec.rb
@@ -1,87 +0,0 @@
1
- require 'http'
2
-
3
- # Compatibility with the Curb gem
4
- module Curl
5
- module Err
6
- class CurlError < RuntimeError; end
7
- class ConnectionFailedError < CurlError; end
8
- class HostResolutionError < CurlError; end
9
- end
10
-
11
- class Easy
12
- attr_accessor :headers, :encoding
13
- attr_reader :response_code, :body_str
14
-
15
- def self.http_post(url, request_body = nil)
16
- Easy.new(url).tap { |e| e.http_post(request_body) }
17
- end
18
-
19
- def self.http_get(url, request_body = nil)
20
- Easy.new(url).tap { |e| e.http_get(request_body) }
21
- end
22
-
23
- def initialize(url = nil, method = nil, request_body = nil, headers = {})
24
- @url = url
25
- @method = method
26
- @request_body = request_body
27
- @headers = headers
28
- @response_code = @body_str = nil
29
- end
30
-
31
- def perform
32
- client = Http::Client.new
33
- options = {:response => :object, :headers => @headers}
34
- response = client.request @method, @url, options
35
- @response_code, @body_str = response.code, response.body
36
- true
37
- rescue SocketError => ex
38
- if ex.message['getaddrinfo'] || ex.message['ame or service not known']
39
- raise Err::HostResolutionError, ex.message
40
- else
41
- raise Err::ConnectionFailedError, ex.message
42
- end
43
- end
44
-
45
- def http_get(request_body = nil)
46
- @method, @request_body = :get, request_body
47
- perform
48
- end
49
-
50
- def http_put(request_body = nil)
51
- @method, @request_body = :put, request_body
52
- perform
53
- end
54
-
55
- def http_post(request_body = nil)
56
- @method, @request_body = :post, request_body
57
- perform
58
- end
59
-
60
- def http_delete
61
- @method = :delete
62
- perform
63
- end
64
- end
65
-
66
- class Multi
67
- def initialize
68
- @clients = []
69
- @done = false
70
- end
71
-
72
- def add(client)
73
- @clients << client
74
- end
75
-
76
-
77
- def perform
78
- return if @done
79
-
80
- @clients.map do |client|
81
- Thread.new { client.perform }
82
- end.each(&:join)
83
-
84
- @done = true
85
- end
86
- end
87
- end
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'http/compat/curb'
4
-
5
- describe Curl do
6
- let(:test_endpoint) { "http://127.0.0.1:#{ExampleService::PORT}/" }
7
-
8
- describe Curl::Easy do
9
- it "gets resources" do
10
- response = Curl::Easy.http_get test_endpoint
11
- response.body_str.should match(/<!doctype html>/)
12
- end
13
-
14
- context :errors do
15
- it "raises Curl::Err::HostResolutionError if asked to connect to a nonexistent domain" do
16
- expect {
17
- Curl::Easy.http_get "http://totallynonexistentdomain.com"
18
- }.to raise_exception(Curl::Err::HostResolutionError)
19
- end
20
- end
21
- end
22
-
23
- describe Curl::Multi do
24
- it "gets resources" do
25
- requests = [test_endpoint]
26
- responses = []
27
-
28
- multi = Curl::Multi.new
29
-
30
- requests.each do |url|
31
- response = Curl::Easy.new url, :get
32
- multi.add response
33
- responses << response
34
- end
35
-
36
- multi.perform
37
- responses.first.body_str.should match(/<!doctype html>/)
38
- end
39
- end
40
- end