http_monkey 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.md +35 -163
- data/http_monkey.gemspec +2 -1
- data/lib/http_monkey.rb +4 -12
- data/lib/http_monkey/client.rb +6 -2
- data/lib/http_monkey/client/environment.rb +6 -0
- data/lib/http_monkey/client/environment_builder.rb +4 -2
- data/lib/http_monkey/client/response.rb +12 -0
- data/lib/http_monkey/configuration.rb +6 -0
- data/lib/http_monkey/configuration/middlewares.rb +15 -2
- data/lib/http_monkey/entry_point.rb +1 -7
- data/lib/http_monkey/middlewares.rb +1 -0
- data/lib/http_monkey/{client → middlewares}/http_request.rb +5 -3
- data/lib/http_monkey/version.rb +1 -1
- data/test/http_monkey/client/environment_builder_test.rb +46 -0
- data/test/http_monkey/client/environment_test.rb +8 -0
- data/test/http_monkey/client/response_test.rb +26 -0
- data/test/http_monkey/client_test.rb +13 -5
- data/test/http_monkey/configuration_test.rb +15 -1
- data/test/integration/client_test.rb +18 -0
- data/test/integration/verbs_test.rb +1 -11
- data/test/test_helper.rb +11 -0
- metadata +36 -18
data/Readme.md
CHANGED
@@ -1,183 +1,55 @@
|
|
1
1
|
# HTTP Monkey [![Build Status](https://secure.travis-ci.org/rogerleite/http_monkey.png?branch=master)](https://travis-ci.org/rogerleite/http_monkey)
|
2
2
|
|
3
3
|
A fluent interface to do HTTP calls, free of fat dependencies and at same time, powered by middlewares rack.
|
4
|
+
* Light and powerful interface
|
5
|
+
* Flexibility
|
6
|
+
* Choose your HTTP adapter
|
7
|
+
* Middlewares (More power to the people!)
|
8
|
+
* Easy to contribute
|
4
9
|
|
5
|
-
|
10
|
+
Probably you want to see some code to continue ...
|
6
11
|
|
7
12
|
``` ruby
|
8
|
-
|
9
|
-
response = HttpMonkey.at("http://google.com").get
|
10
|
-
response = HttpMonkey.at("http://google.com").post(:q => "Http Monkey!")
|
11
|
-
puts response.body # More info about response at http://httpirb.com/#responses
|
13
|
+
agent = HttpMonkey.build
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
# you can set headers, cookies, auth, proxy timeout, SSL ... all web stuff.
|
16
|
+
# response = agent.at("http://someservice.com").
|
17
|
+
# with_header("Content-Type" => "application/json").
|
18
|
+
# basic_auth("user", "pass").
|
19
|
+
# get
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
+
response = agent.at("http://google.com").get
|
22
|
+
puts response.code # response.headers and response.body
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
# you can change settings on your client
|
25
|
+
agent.configure do
|
26
|
+
middlewares do
|
27
|
+
# Default HTTP Headers (to all requests)
|
28
|
+
use HttpMonkey::M::DefaultHeaders, {"Content-Type" => "application/json"}
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
req.
|
32
|
-
req.read_timeout = 15
|
33
|
-
end.get
|
34
|
-
|
35
|
-
# SSL
|
36
|
-
HttpMonkey.at("http://google.com").yield_request do |req|
|
37
|
-
req.auth.ssl.cert_key_file = "client_key.pem" # the private key file to use
|
38
|
-
req.auth.ssl.cert_key_password = "C3rtP@ssw0rd" # the key file's password
|
39
|
-
req.auth.ssl.cert_file = "client_cert.pem" # the certificate file to use
|
40
|
-
req.auth.ssl.ca_cert_file = "ca_cert.pem" # the ca certificate file to use
|
41
|
-
req.auth.ssl.verify_mode = :none # or one of [:peer, :fail_if_no_peer_cert, :client_once]
|
42
|
-
req.auth.ssl.ssl_version = :TLSv1 # or one of [:SSLv2, :SSLv3]
|
43
|
-
end.get
|
44
|
-
|
45
|
-
# HttpMonkey "built-in" middlewares
|
46
|
-
HttpMonkey.configure do
|
47
|
-
# Default HTTP Headers (to all requests)
|
48
|
-
middlewares.use HttpMonkey::M::DefaultHeaders, {"Content-Type" => "application/json"}
|
49
|
-
|
50
|
-
# Filter ALL requests (access to env and request objects)
|
51
|
-
middlewares.use HttpMonkey::M::RequestFilter do |env, request|
|
52
|
-
# HTTPI::Request, you can set proxy, timeouts, authentication etc.
|
53
|
-
# req.proxy = "http://proxy.com"
|
54
|
-
end
|
55
|
-
|
56
|
-
# Enable automatic follow redirect
|
57
|
-
middlewares.use HttpMonkey::M::FollowRedirect, :max_tries => 3
|
58
|
-
end
|
59
|
-
```
|
60
|
-
|
61
|
-
## Flexibility
|
62
|
-
|
63
|
-
You can configure the default or build your own client and define how it should behave.
|
64
|
-
|
65
|
-
You can also define net adapter, behaviours and middlewares by request.
|
66
|
-
|
67
|
-
``` ruby
|
68
|
-
# Changing default client
|
69
|
-
HttpMonkey.configure do
|
70
|
-
net_adapter :curb
|
71
|
-
behaviours.on(500) do |client, request, response|
|
72
|
-
raise "Server side error :X"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# Works with status code callbacks (here known as behaviours)
|
77
|
-
chimp = HttpMonkey.build do
|
78
|
-
behaviours do
|
79
|
-
# 2xx range
|
80
|
-
on(200..299) do |client, request, response|
|
81
|
-
response
|
82
|
-
end
|
83
|
-
# Redirects
|
84
|
-
on([301, 302]) do |client, request, response|
|
85
|
-
raise "Redirect error"
|
86
|
-
end
|
87
|
-
end
|
30
|
+
# Filter ALL requests (access to env and request objects)
|
31
|
+
middlewares.use HttpMonkey::M::RequestFilter do |env, request|
|
32
|
+
# HTTPI::Request, you can set proxy, timeouts, authentication etc.
|
33
|
+
# req.proxy = "http://proxy.com"
|
88
34
|
end
|
89
35
|
|
90
|
-
|
36
|
+
# Enable automatic follow redirect
|
37
|
+
middlewares.use HttpMonkey::M::FollowRedirect, :max_tries => 3
|
38
|
+
end
|
91
39
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
40
|
+
# or settings by request
|
41
|
+
response = agent.at("http://google.com").get do
|
42
|
+
net_adapter :curb # [:httpclient, :curb, :net_http, :em_http]
|
43
|
+
behaviours do
|
44
|
+
on([301, 302]) do |client, request, response|
|
45
|
+
raise "Redirect Error"
|
96
46
|
end
|
97
47
|
end
|
48
|
+
end
|
98
49
|
```
|
99
50
|
|
100
|
-
|
101
|
-
|
102
|
-
Thanks to [HTTPI](http://httpirb.com/), you can choose different HTTP clients:
|
103
|
-
|
104
|
-
* [HTTPClient](http://rubygems.org/gems/httpclient)
|
105
|
-
* [Curb](http://rubygems.org/gems/curb)
|
106
|
-
* [Net::HTTP](http://ruby-doc.org/stdlib/libdoc/net/http/rdoc)
|
107
|
-
|
108
|
-
*Important*: If you want to use anything other than Net::HTTP, you need to manually require the library or make sure it’s available in your load path.
|
109
|
-
|
110
|
-
``` ruby
|
111
|
-
# When you build your own client, you can define which Http client to use.
|
112
|
-
chimp = HttpMonkey.build do
|
113
|
-
# HTTP clients available [:httpclient, :curb, :net_http]
|
114
|
-
net_adapter :curb # default :net_http
|
115
|
-
# [...]
|
116
|
-
end
|
117
|
-
|
118
|
-
# You can also change you net_adapter by request
|
119
|
-
chimp.at("http://google.com").get do
|
120
|
-
# only on this request, use :httpclient
|
121
|
-
net_adapter :httpclient
|
122
|
-
# [...]
|
123
|
-
end
|
124
|
-
```
|
125
|
-
|
126
|
-
## More power to the people (for God sake!)
|
127
|
-
|
128
|
-
Easy to extend, using the power of Rack middleware interface.
|
129
|
-
|
130
|
-
``` ruby
|
131
|
-
|
132
|
-
class Logger
|
133
|
-
def initialize(app)
|
134
|
-
@app = app
|
135
|
-
end
|
136
|
-
def call(env)
|
137
|
-
puts "-> before #{env.inspect} #{Time.now.inspect}"
|
138
|
-
result = @app.call(env)
|
139
|
-
puts "-> after #{env.inspect} #{Time.now.inspect}"
|
140
|
-
result
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
# Add custom middlewares to default stack
|
145
|
-
HttpMonkey.configure do
|
146
|
-
middlewares do
|
147
|
-
use Logger
|
148
|
-
end
|
149
|
-
end
|
150
|
-
# Now all requests uses Logger
|
151
|
-
response = HttpMonkey.at("http://google.com").get
|
152
|
-
|
153
|
-
# or when you build your own client
|
154
|
-
chimp = HttpMonkey.build do
|
155
|
-
middlewares do
|
156
|
-
use Logger
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
# or by request
|
161
|
-
chimp.at("http://google.com").get do
|
162
|
-
middlewares.use Logger
|
163
|
-
# [...]
|
164
|
-
end
|
165
|
-
```
|
166
|
-
|
167
|
-
Some ideas to future:
|
168
|
-
|
169
|
-
* Cache? Finish [cachebag](https://github.com/abril/cachebag)
|
170
|
-
* Support Cookies with http_monkey-cookies (to do).
|
171
|
-
* Logger? Maybe a built-in middleware? Apache/Custom format.
|
172
|
-
* Cool ways to support asynchronous calls.
|
173
|
-
|
174
|
-
You can see my [presentation](http://www.slideshare.net/rogerleite14/http-monkey) in *pt-br* at Editora Abril.
|
175
|
-
|
176
|
-
## Easy to contribute
|
177
|
-
|
178
|
-
Suggestions, bugs and pull requests, here at [github.com/rogerleite/http_monkey](http://github.com/rogerleite/http_monkey).
|
179
|
-
`bundle install`, `rake test` and be happy!
|
51
|
+
If you liked what you saw, visit http://rogerleite.github.com/http_monkey/ for more information.
|
180
52
|
|
181
|
-
|
53
|
+
Suggestions, bugs and pull requests, use [GitHub Issues](http://github.com/rogerleite/http_monkey/issues).
|
182
54
|
|
183
55
|
HTTP Monkey is copyright 2012 Roger Leite and contributors. It is licensed under the MIT license. See the include LICENSE file for details.
|
data/http_monkey.gemspec
CHANGED
@@ -18,7 +18,8 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
20
|
gem.add_runtime_dependency "rack"
|
21
|
-
gem.add_runtime_dependency "httpi", "~>
|
21
|
+
gem.add_runtime_dependency "httpi", "~> 2.0.0"
|
22
|
+
gem.add_runtime_dependency "http_objects", "~> 0.0.4"
|
22
23
|
|
23
24
|
gem.add_development_dependency "rake"
|
24
25
|
gem.add_development_dependency "minitest", "~> 3"
|
data/lib/http_monkey.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "net/http"
|
2
2
|
require "rack"
|
3
3
|
require "httpi"
|
4
|
+
require "http_objects"
|
4
5
|
|
5
6
|
require "http_monkey/version"
|
6
7
|
require "http_monkey/entry_point"
|
@@ -8,11 +9,13 @@ require "http_monkey/configuration"
|
|
8
9
|
require "http_monkey/configuration/behaviours"
|
9
10
|
require "http_monkey/configuration/middlewares"
|
10
11
|
require "http_monkey/client"
|
11
|
-
require "http_monkey/client/http_request"
|
12
12
|
require "http_monkey/client/environment"
|
13
13
|
require "http_monkey/client/environment_builder"
|
14
|
+
require "http_monkey/client/response"
|
14
15
|
require "http_monkey/middlewares"
|
15
16
|
|
17
|
+
HTTPI.log = false
|
18
|
+
|
16
19
|
module HttpMonkey
|
17
20
|
|
18
21
|
def self.at(url)
|
@@ -42,14 +45,3 @@ module HttpMonkey
|
|
42
45
|
end
|
43
46
|
|
44
47
|
end
|
45
|
-
|
46
|
-
HTTPI.log = false
|
47
|
-
|
48
|
-
# This monkey patch is to avoid a bug from httpi (1.1.1) on ruby 1.8.7
|
49
|
-
# that raises "undefined method `use_ssl=' for Net::HTTP"
|
50
|
-
if RUBY_VERSION =~ /1\.8/
|
51
|
-
class Net::HTTPSession
|
52
|
-
def use_ssl=(flag)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
data/lib/http_monkey/client.rb
CHANGED
@@ -19,6 +19,10 @@ module HttpMonkey
|
|
19
19
|
@conf.net_adapter
|
20
20
|
end
|
21
21
|
|
22
|
+
def storage
|
23
|
+
@conf.storage
|
24
|
+
end
|
25
|
+
|
22
26
|
def configure(&block)
|
23
27
|
@conf.instance_eval(&block) if block_given?
|
24
28
|
self
|
@@ -26,9 +30,9 @@ module HttpMonkey
|
|
26
30
|
|
27
31
|
def http_request(method, request)
|
28
32
|
env = Client::EnvironmentBuilder.new(self, method, request).to_env
|
29
|
-
code, headers, body = @conf.middlewares.execute(
|
33
|
+
code, headers, body = @conf.middlewares.execute(Middlewares::HttpRequest, env)
|
30
34
|
body.close if body.respond_to?(:close) # close when is a Rack::BodyProxy
|
31
|
-
response =
|
35
|
+
response = Client::Response.new(code, headers, body)
|
32
36
|
|
33
37
|
if (behaviour = @conf.behaviours.find(response.code))
|
34
38
|
behaviour.call(self, request, response)
|
@@ -93,6 +93,12 @@ module HttpMonkey
|
|
93
93
|
(method.empty? ? nil : method.downcase.to_sym)
|
94
94
|
end
|
95
95
|
|
96
|
+
# Returns instance from HttpMonkey::Configuration#storage.
|
97
|
+
# Simple Hash instance by default.
|
98
|
+
def storage
|
99
|
+
self['http_monkey.storage']
|
100
|
+
end
|
101
|
+
|
96
102
|
end
|
97
103
|
|
98
104
|
end
|
@@ -23,7 +23,6 @@ module HttpMonkey
|
|
23
23
|
# Returns a instance of HttpMonkey::Client::Environment with
|
24
24
|
# rack like headers.
|
25
25
|
def to_env
|
26
|
-
uri = @request.url
|
27
26
|
rack_input = normalize_body(@request.body)
|
28
27
|
|
29
28
|
env = HttpMonkey::Client::Environment.new(DEFAULT_ENV)
|
@@ -37,12 +36,15 @@ module HttpMonkey
|
|
37
36
|
'CONTENT_LENGTH' => rack_input.length.to_s,
|
38
37
|
|
39
38
|
# custom info
|
40
|
-
'http_monkey.request' => [@method, @request, @client]
|
39
|
+
'http_monkey.request' => [@method, @request, @client],
|
40
|
+
'http_monkey.storage' => @client.storage
|
41
41
|
})
|
42
42
|
env.add_http_header(@request.headers)
|
43
43
|
env
|
44
44
|
end
|
45
45
|
|
46
|
+
protected
|
47
|
+
|
46
48
|
def normalize_body(body)
|
47
49
|
return "" if body.nil?
|
48
50
|
input = body.dup
|
@@ -8,6 +8,7 @@ module HttpMonkey
|
|
8
8
|
# behaviour default always return response
|
9
9
|
@behaviours.on_unknown { |client, req, response| response }
|
10
10
|
@middlewares = HttpMonkey::Configuration::Middlewares.new
|
11
|
+
@storage = Hash.new
|
11
12
|
end
|
12
13
|
|
13
14
|
def initialize_copy(source)
|
@@ -31,6 +32,11 @@ module HttpMonkey
|
|
31
32
|
@middlewares
|
32
33
|
end
|
33
34
|
|
35
|
+
def storage(store = nil)
|
36
|
+
@storage = store unless store.nil?
|
37
|
+
@storage
|
38
|
+
end
|
39
|
+
|
34
40
|
end
|
35
41
|
|
36
42
|
end
|
@@ -5,23 +5,36 @@ module HttpMonkey
|
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
@chain = []
|
8
|
+
@stack_middlewares = nil
|
8
9
|
end
|
9
10
|
|
10
11
|
def initialize_copy(source)
|
11
12
|
super
|
12
13
|
@chain = @chain.clone
|
14
|
+
@stack_middlewares = @stack_middlewares.clone if @stack_middlewares
|
13
15
|
end
|
14
16
|
|
15
17
|
def use(middleware, *args, &block)
|
16
18
|
@chain << lambda { |app| middleware.new(app, *args, &block) }
|
19
|
+
@stack_middlewares = nil
|
17
20
|
self
|
18
21
|
end
|
19
22
|
|
20
23
|
def execute(app, env)
|
21
|
-
|
24
|
+
stacked = stack_middlewares(app, @chain)
|
25
|
+
stacked.call(env)
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def stack_middlewares(app, chain)
|
31
|
+
@stack_middlewares ||= stack_middlewares!(app, chain)
|
32
|
+
end
|
33
|
+
|
34
|
+
def stack_middlewares!(app, chain)
|
35
|
+
chain.reverse.inject(app) do |app, middle|
|
22
36
|
middle.call(app)
|
23
37
|
end
|
24
|
-
stacked_middleware.call(env)
|
25
38
|
end
|
26
39
|
|
27
40
|
end
|
@@ -48,13 +48,7 @@ module HttpMonkey
|
|
48
48
|
include EntryPointFluentInterface
|
49
49
|
|
50
50
|
def get(query_param = nil, &block)
|
51
|
-
|
52
|
-
if query_param.kind_of?(Hash)
|
53
|
-
query_param = Rack::Utils.build_query(query_param)
|
54
|
-
end
|
55
|
-
query_param = query_param.to_s unless query_param.is_a?(String)
|
56
|
-
@request.url.query = query_param unless query_param.empty?
|
57
|
-
|
51
|
+
@request.query = query_param unless query_param.nil?
|
58
52
|
capture_client(&block).http_request(:get, @request)
|
59
53
|
end
|
60
54
|
|
@@ -3,6 +3,7 @@ module HttpMonkey
|
|
3
3
|
autoload :DefaultHeaders, "http_monkey/middlewares/default_headers"
|
4
4
|
autoload :RequestFilter, "http_monkey/middlewares/request_filter"
|
5
5
|
autoload :FollowRedirect, "http_monkey/middlewares/follow_redirect"
|
6
|
+
require "http_monkey/middlewares/http_request"
|
6
7
|
end
|
7
8
|
M = Middlewares
|
8
9
|
end
|
@@ -1,11 +1,13 @@
|
|
1
|
-
module HttpMonkey
|
1
|
+
module HttpMonkey::Middlewares
|
2
2
|
|
3
3
|
# Main App middleware
|
4
4
|
# Responsible to make HTTP request
|
5
|
-
class
|
5
|
+
class HttpRequest
|
6
6
|
|
7
7
|
def self.call(env)
|
8
|
-
|
8
|
+
unless env.is_a?(HttpMonkey::Client::Environment)
|
9
|
+
env = HttpMonkey::Client::Environment.new(env)
|
10
|
+
end
|
9
11
|
_, request, client = env['http_monkey.request']
|
10
12
|
|
11
13
|
method = env.request_method
|
data/lib/http_monkey/version.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
describe HttpMonkey::Client::EnvironmentBuilder do
|
4
|
+
|
5
|
+
let(:subject_class) { HttpMonkey::Client::EnvironmentBuilder }
|
6
|
+
let(:client) { HttpMonkey.build }
|
7
|
+
|
8
|
+
describe "#to_env" do
|
9
|
+
|
10
|
+
let(:fake_uri) { URI.parse("http://fake.com") }
|
11
|
+
let(:stub_request) do
|
12
|
+
stub("request",
|
13
|
+
:url => fake_uri,
|
14
|
+
:body => "body",
|
15
|
+
:headers => {"Content-Type" => "plain/text"})
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:env) { subject_class.new(client, :get, stub_request).to_env }
|
19
|
+
|
20
|
+
it "body as 'rack.input'" do
|
21
|
+
env['rack.input'].must_equal("body")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "builds env with uri" do
|
25
|
+
env.uri.host.must_equal("fake.com")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "sets request method" do
|
29
|
+
env['REQUEST_METHOD'].must_equal("GET")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "sets 'http_monkey.request'" do
|
33
|
+
env['http_monkey.request'].must_equal([:get, stub_request, client])
|
34
|
+
end
|
35
|
+
|
36
|
+
it "sets 'http_monkey.storage'" do
|
37
|
+
env['http_monkey.storage'].must_be_same_as(client.storage)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "adds http headers" do
|
41
|
+
env['HTTP_CONTENT_TYPE'].must_equal("plain/text")
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -125,4 +125,12 @@ describe HttpMonkey::Client::Environment do
|
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
+
describe "#storage" do
|
129
|
+
it "returns 'http_monkey.storage' key" do
|
130
|
+
stub_store = stub("storage")
|
131
|
+
env = subject.new('http_monkey.storage' => stub_store)
|
132
|
+
env.storage.must_be_same_as(stub_store)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
128
136
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
describe HttpMonkey::Client::Response do
|
4
|
+
|
5
|
+
let(:code) { 200 }
|
6
|
+
let(:headers) { Hash["Content-Type", "text/plain; charset=ISO-8859-4"] }
|
7
|
+
let(:body) { ["body test"] }
|
8
|
+
|
9
|
+
subject { HttpMonkey::Client::Response.new(code, headers, body) }
|
10
|
+
|
11
|
+
describe "#headers" do
|
12
|
+
it "must be instance of HttpObjects::HeadersHash" do
|
13
|
+
subject.headers.must_be_instance_of(HttpObjects::HeadersHash)
|
14
|
+
end
|
15
|
+
it "access values with style" do
|
16
|
+
subject.headers.content_type?.must_equal(true)
|
17
|
+
subject.headers.content_type!.must_equal("text/plain; charset=ISO-8859-4")
|
18
|
+
subject.headers.content_type.value.must_equal("text/plain")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "must be kind of HTTPI::Response" do
|
23
|
+
subject.must_be_kind_of(HTTPI::Response)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -10,18 +10,26 @@ describe HttpMonkey::Client do
|
|
10
10
|
subject.at("http://server.com").must_be_instance_of(HttpMonkey::EntryPoint)
|
11
11
|
end
|
12
12
|
|
13
|
-
describe "
|
13
|
+
describe "configuration attributes" do
|
14
14
|
it "#net_adapter" do
|
15
|
-
subject.
|
15
|
+
subject.must_respond_to(:net_adapter)
|
16
|
+
end
|
17
|
+
it "#storage" do
|
18
|
+
subject.must_respond_to(:storage)
|
16
19
|
end
|
17
20
|
end
|
18
21
|
|
19
22
|
describe "#configure" do
|
20
|
-
it "
|
23
|
+
it "returns self" do
|
24
|
+
subject.configure.must_be_same_as(subject)
|
25
|
+
end
|
26
|
+
it "yields Configuration instance" do
|
27
|
+
flag = "out block"
|
21
28
|
subject.configure do
|
22
|
-
|
29
|
+
self.must_be_instance_of(HttpMonkey::Configuration)
|
30
|
+
flag = "inner block"
|
23
31
|
end
|
24
|
-
|
32
|
+
flag.must_equal("inner block")
|
25
33
|
end
|
26
34
|
end
|
27
35
|
|
@@ -18,7 +18,7 @@ describe HttpMonkey::Configuration do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
describe "#net_adapter" do
|
21
|
-
it "returns
|
21
|
+
it "returns :net_http by default" do
|
22
22
|
subject.net_adapter.must_equal(:net_http)
|
23
23
|
end
|
24
24
|
it "sets value" do
|
@@ -61,4 +61,18 @@ describe HttpMonkey::Configuration do
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
describe "#storage" do
|
65
|
+
it "respond_to" do
|
66
|
+
subject.must_respond_to(:storage)
|
67
|
+
end
|
68
|
+
it "returns hash by default" do
|
69
|
+
subject.storage.must_be_instance_of(Hash)
|
70
|
+
end
|
71
|
+
it "allows to change" do
|
72
|
+
MyCustomStorage = Class.new(Hash)
|
73
|
+
subject.storage(MyCustomStorage.new)
|
74
|
+
subject.storage.must_be_instance_of(MyCustomStorage)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
64
78
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
describe "Integration Specs - Client" do
|
4
|
+
|
5
|
+
def self.before_suite
|
6
|
+
@@server = MinionServer.new(MirrorApp).start
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.after_suite
|
10
|
+
@@server.shutdown
|
11
|
+
end
|
12
|
+
|
13
|
+
it "response must be instance of Client::Response" do
|
14
|
+
response = HttpMonkey.at("http://localhost:4000").get
|
15
|
+
response.must_be_instance_of(HttpMonkey::Client::Response)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -1,19 +1,9 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
|
-
VerbsApp = Rack::Builder.new do
|
4
|
-
map "/" do
|
5
|
-
run lambda { |env|
|
6
|
-
env['rack.input'] = env['rack.input'].read if env['rack.input'].respond_to?(:read)
|
7
|
-
body = YAML.dump(env)
|
8
|
-
[200, {"Content-Type" => "text/plain", "Content-Length" => body.size.to_s}, [body]]
|
9
|
-
}
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
3
|
describe "Integration Specs - Verbs" do
|
14
4
|
|
15
5
|
def self.before_suite
|
16
|
-
@@server = MinionServer.new(
|
6
|
+
@@server = MinionServer.new(MirrorApp).start
|
17
7
|
end
|
18
8
|
|
19
9
|
def self.after_suite
|
data/test/test_helper.rb
CHANGED
@@ -13,3 +13,14 @@ MiniTest::Unit.runner.reporters << MiniTest::Reporters::SpecReporter.new
|
|
13
13
|
MiniTest::Unit.runner.reporters << HttpMonkey::Support::CaptainHook.new
|
14
14
|
|
15
15
|
require "minion_server"
|
16
|
+
|
17
|
+
# Default App to integration tests
|
18
|
+
MirrorApp = Rack::Builder.new do
|
19
|
+
map "/" do
|
20
|
+
run lambda { |env|
|
21
|
+
env['rack.input'] = env['rack.input'].read if env['rack.input'].respond_to?(:read)
|
22
|
+
body = YAML.dump(env)
|
23
|
+
[200, {"Content-Type" => "text/plain", "Content-Length" => body.size.to_s}, [body]]
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_monkey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
16
|
-
requirement: &
|
16
|
+
requirement: &70197101569580 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,21 +21,32 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70197101569580
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: httpi
|
27
|
-
requirement: &
|
27
|
+
requirement: &70197101569080 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: 2.0.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70197101569080
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: http_objects
|
38
|
+
requirement: &70197101568560 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.0.4
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70197101568560
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: rake
|
38
|
-
requirement: &
|
49
|
+
requirement: &70197101568160 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
@@ -43,10 +54,10 @@ dependencies:
|
|
43
54
|
version: '0'
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *70197101568160
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: minitest
|
49
|
-
requirement: &
|
60
|
+
requirement: &70197101567600 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ~>
|
@@ -54,10 +65,10 @@ dependencies:
|
|
54
65
|
version: '3'
|
55
66
|
type: :development
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *70197101567600
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: minitest-reporters
|
60
|
-
requirement: &
|
71
|
+
requirement: &70197101567040 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - ~>
|
@@ -65,10 +76,10 @@ dependencies:
|
|
65
76
|
version: 0.7.0
|
66
77
|
type: :development
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
79
|
+
version_requirements: *70197101567040
|
69
80
|
- !ruby/object:Gem::Dependency
|
70
81
|
name: mocha
|
71
|
-
requirement: &
|
82
|
+
requirement: &70197101566640 !ruby/object:Gem::Requirement
|
72
83
|
none: false
|
73
84
|
requirements:
|
74
85
|
- - ! '>='
|
@@ -76,10 +87,10 @@ dependencies:
|
|
76
87
|
version: '0'
|
77
88
|
type: :development
|
78
89
|
prerelease: false
|
79
|
-
version_requirements: *
|
90
|
+
version_requirements: *70197101566640
|
80
91
|
- !ruby/object:Gem::Dependency
|
81
92
|
name: minion_server
|
82
|
-
requirement: &
|
93
|
+
requirement: &70197101566140 !ruby/object:Gem::Requirement
|
83
94
|
none: false
|
84
95
|
requirements:
|
85
96
|
- - ! '>='
|
@@ -87,7 +98,7 @@ dependencies:
|
|
87
98
|
version: '0'
|
88
99
|
type: :development
|
89
100
|
prerelease: false
|
90
|
-
version_requirements: *
|
101
|
+
version_requirements: *70197101566140
|
91
102
|
description: A fluent interface to do HTTP calls, free of fat dependencies and at
|
92
103
|
same time, powered by middlewares rack.
|
93
104
|
email:
|
@@ -107,7 +118,7 @@ files:
|
|
107
118
|
- lib/http_monkey/client.rb
|
108
119
|
- lib/http_monkey/client/environment.rb
|
109
120
|
- lib/http_monkey/client/environment_builder.rb
|
110
|
-
- lib/http_monkey/client/
|
121
|
+
- lib/http_monkey/client/response.rb
|
111
122
|
- lib/http_monkey/configuration.rb
|
112
123
|
- lib/http_monkey/configuration/behaviours.rb
|
113
124
|
- lib/http_monkey/configuration/middlewares.rb
|
@@ -115,9 +126,12 @@ files:
|
|
115
126
|
- lib/http_monkey/middlewares.rb
|
116
127
|
- lib/http_monkey/middlewares/default_headers.rb
|
117
128
|
- lib/http_monkey/middlewares/follow_redirect.rb
|
129
|
+
- lib/http_monkey/middlewares/http_request.rb
|
118
130
|
- lib/http_monkey/middlewares/request_filter.rb
|
119
131
|
- lib/http_monkey/version.rb
|
132
|
+
- test/http_monkey/client/environment_builder_test.rb
|
120
133
|
- test/http_monkey/client/environment_test.rb
|
134
|
+
- test/http_monkey/client/response_test.rb
|
121
135
|
- test/http_monkey/client_test.rb
|
122
136
|
- test/http_monkey/configuration/behaviours_test.rb
|
123
137
|
- test/http_monkey/configuration/middlewares_test.rb
|
@@ -128,6 +142,7 @@ files:
|
|
128
142
|
- test/http_monkey/middlewares/follow_redirect_test.rb
|
129
143
|
- test/http_monkey/middlewares/request_filter_test.rb
|
130
144
|
- test/http_monkey/middlewares_test.rb
|
145
|
+
- test/integration/client_test.rb
|
131
146
|
- test/integration/follow_redirect_test.rb
|
132
147
|
- test/integration/verbs_test.rb
|
133
148
|
- test/support/captain_hook.rb
|
@@ -159,7 +174,9 @@ specification_version: 3
|
|
159
174
|
summary: A fluent interface to do HTTP calls, free of fat dependencies and at same
|
160
175
|
time, powered by middlewares rack.
|
161
176
|
test_files:
|
177
|
+
- test/http_monkey/client/environment_builder_test.rb
|
162
178
|
- test/http_monkey/client/environment_test.rb
|
179
|
+
- test/http_monkey/client/response_test.rb
|
163
180
|
- test/http_monkey/client_test.rb
|
164
181
|
- test/http_monkey/configuration/behaviours_test.rb
|
165
182
|
- test/http_monkey/configuration/middlewares_test.rb
|
@@ -170,6 +187,7 @@ test_files:
|
|
170
187
|
- test/http_monkey/middlewares/follow_redirect_test.rb
|
171
188
|
- test/http_monkey/middlewares/request_filter_test.rb
|
172
189
|
- test/http_monkey/middlewares_test.rb
|
190
|
+
- test/integration/client_test.rb
|
173
191
|
- test/integration/follow_redirect_test.rb
|
174
192
|
- test/integration/verbs_test.rb
|
175
193
|
- test/support/captain_hook.rb
|