fredo 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/fredo.gemspec +2 -2
- data/lib/fredo/ext/net_http.rb +19 -15
- data/spec/fredo_spec.rb +12 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.10
|
data/fredo.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{fredo}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.10"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["ilpoldo"]
|
12
|
-
s.date = %q{2010-05-
|
12
|
+
s.date = %q{2010-05-06}
|
13
13
|
s.description = %q{Mocks web services by plugging Net::Http straight into Rack}
|
14
14
|
s.email = %q{ilpoldo@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/fredo/ext/net_http.rb
CHANGED
@@ -50,27 +50,31 @@ module Net #:nodoc: all
|
|
50
50
|
protocol = use_ssl? ? "https" : "http"
|
51
51
|
full_path = "#{protocol}://#{self.address}:#{self.port}#{request.path}"
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
53
|
+
# It's for testing, we care about all the headers
|
54
|
+
request_headers = request.instance_variable_get :@header
|
55
|
+
request_headers = Hash[*request_headers.map {|k,v| [String(k).upcase.gsub(%r{[^_0-9A-Z]},"_"),v]}.flatten]
|
56
|
+
|
57
|
+
rack_env =request_headers.merge({'REQUEST_METHOD' => request.method,
|
58
|
+
'SCRIPT_NAME' => '',
|
59
|
+
'PATH_INFO' => uri.path,
|
60
|
+
'QUERY_STRING' => (uri.query || ''),
|
61
|
+
'SERVER_NAME' => self.address,
|
62
|
+
'SERVER_PORT' => self.port,
|
63
|
+
'rack.version' => [1,1],
|
64
|
+
'rack.url_scheme' => protocol,
|
65
|
+
'rack.input' => body,
|
66
|
+
'rack.errors' => $stderr,
|
67
|
+
'rack.multithread' => true,
|
68
|
+
'rack.multiprocess' => true,
|
69
|
+
'rack.run_once' => false})
|
66
70
|
|
67
71
|
# @socket = Net::HTTP.socket_type.new
|
68
72
|
# Perform the request
|
69
|
-
status,
|
73
|
+
status, headers, body = Fredo.call(rack_env)
|
70
74
|
|
71
75
|
response = Net::HTTPResponse.send(:response_class, "#{status}").new("1.0", "#{status}", body)
|
72
76
|
response.instance_variable_set(:@body, body)
|
73
|
-
|
77
|
+
headers.each { |name, value| response[name] = value }
|
74
78
|
response.instance_variable_set(:@read, true)
|
75
79
|
|
76
80
|
def response.read_body(*args, &block)
|
data/spec/fredo_spec.rb
CHANGED
@@ -126,8 +126,19 @@ describe Fredo do
|
|
126
126
|
end
|
127
127
|
|
128
128
|
http = Net::HTTP.new('www.gossip.com')
|
129
|
-
http.post('/', body, '
|
129
|
+
http.post('/', body, 'Content-Type' => 'text/plain').body.should eql(body)
|
130
130
|
end
|
131
131
|
|
132
132
|
end
|
133
|
+
|
134
|
+
context "headers" do
|
135
|
+
it "keeps request headers" do
|
136
|
+
Fredo.post 'http://www.headheavy.com' do
|
137
|
+
"I got #{request.env['CONTENT_TYPE']}"
|
138
|
+
end
|
139
|
+
|
140
|
+
http = Net::HTTP.new('www.headheavy.com')
|
141
|
+
http.post('/', '<foo></foo>', 'content-type' => 'application/xml').body.should eql('I got application/xml')
|
142
|
+
end
|
143
|
+
end
|
133
144
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 10
|
9
|
+
version: 0.1.10
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- ilpoldo
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-06 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|