sham_rack 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ ## 02-Sep-2010 [mdub@dogbiscuit.org]
2
+
3
+ * Fixes to support Ruby-1.9.x.
4
+
1
5
  ## 08-Jul-2010 [jyurek@thoughtbot.com]
2
6
 
3
7
  * Add support for Mechanize.
@@ -4,6 +4,6 @@
4
4
  #
5
5
  module ShamRack; end
6
6
 
7
- require "sham_rack/core_ext/net/http"
7
+ require "sham_rack/net_http"
8
8
  require "sham_rack/registry"
9
9
  require "sham_rack/version"
@@ -1,7 +1,26 @@
1
- module ShamRack
1
+ require "net/http"
2
+ require "sham_rack/registry"
3
+
4
+ class << Net::HTTP
5
+
6
+ alias :new_without_sham_rack :new
7
+
8
+ def new(address, port = nil, *proxy_args)
9
+ port ||= Net::HTTP.default_port
10
+ rack_app = ShamRack.application_for(address, port)
11
+ http_object = new_without_sham_rack(address, port, *proxy_args)
12
+ if rack_app
13
+ http_object.extend(ShamRack::NetHttp::Extensions)
14
+ http_object.rack_app = rack_app
15
+ end
16
+ http_object
17
+ end
2
18
 
3
- module HTTP
19
+ end
4
20
 
21
+ module ShamRack
22
+ module NetHttp
23
+
5
24
  module Extensions
6
25
 
7
26
  attr_accessor :rack_app
@@ -49,8 +68,10 @@ module ShamRack
49
68
  def io_env(request, body)
50
69
  raise(ArgumentError, "both request.body and body argument were provided") if (request.body && body)
51
70
  body ||= request.body || ""
71
+ body = body.to_s
72
+ body = body.encode("ASCII-8BIT") if body.respond_to?(:encode)
52
73
  {
53
- "rack.input" => StringIO.new(body.to_s),
74
+ "rack.input" => StringIO.new(body),
54
75
  "rack.errors" => $stderr
55
76
  }
56
77
  end
@@ -83,7 +104,7 @@ module ShamRack
83
104
  headers.each do |k,v|
84
105
  response.add_field(k, v)
85
106
  end
86
- response.extend ShamRack::ResponseExtensions
107
+ response.extend ShamRack::NetHttp::ResponseExtensions
87
108
  return response
88
109
  end
89
110
 
@@ -95,14 +116,14 @@ module ShamRack
95
116
 
96
117
  end
97
118
 
98
- end
119
+ module ResponseExtensions
99
120
 
100
- module ResponseExtensions
121
+ def read_body(dest = nil)
122
+ yield @body if block_given?
123
+ dest << @body if dest
124
+ return @body
125
+ end
101
126
 
102
- def read_body(dest = nil)
103
- yield @body if block_given?
104
- dest << @body if dest
105
- return @body
106
127
  end
107
128
 
108
129
  end
@@ -32,7 +32,7 @@ module ShamRack
32
32
  unless request.query_string.to_s.empty?
33
33
  request_path += "?" + request.query_string
34
34
  end
35
- [status, {"Content-Type" => content_type}, content] if request_path == path
35
+ [status, {"Content-Type" => content_type}, [content]] if request_path == path
36
36
  end
37
37
  end
38
38
 
@@ -43,7 +43,7 @@ module ShamRack
43
43
  protected
44
44
 
45
45
  def default_response
46
- [404, {"Content-Type" => "text/plain"}, "Not found"]
46
+ [404, {"Content-Type" => "text/plain"}, ["Not found"]]
47
47
  end
48
48
 
49
49
  end
@@ -1,3 +1,3 @@
1
1
  module ShamRack
2
- VERSION = "1.3.1".freeze
2
+ VERSION = "1.3.2"
3
3
  end
@@ -43,11 +43,11 @@ describe ShamRack::StubWebService do
43
43
  before(:each) do
44
44
 
45
45
  @app.handle do |request|
46
- [200, {}, "response from first handler"] if request.get?
46
+ [200, {}, ["response from first handler"]] if request.get?
47
47
  end
48
48
 
49
49
  @app.handle do |request|
50
- [200, {}, "response from second handler"] if request.path_info == "/stuff"
50
+ [200, {}, ["response from second handler"]] if request.path_info == "/stuff"
51
51
  end
52
52
 
53
53
  end
@@ -107,7 +107,7 @@ describe ShamRack do
107
107
  [
108
108
  "201 Created",
109
109
  { "Content-Type" => "text/plain", "X-Foo" => "bar" },
110
- "BODY"
110
+ ["BODY"]
111
111
  ]
112
112
  end
113
113
  @response = Net::HTTP.get_response(URI.parse("http://www.test.xyz/"))
@@ -138,7 +138,7 @@ describe ShamRack do
138
138
  it "mounts associated block as an app" do
139
139
 
140
140
  ShamRack.at("simple.xyz") do |env|
141
- ["200 OK", { "Content-type" => "text/plain" }, "Easy, huh?"]
141
+ ["200 OK", { "Content-type" => "text/plain" }, ["Easy, huh?"]]
142
142
  end
143
143
 
144
144
  open("http://simple.xyz").read.should == "Easy, huh?"
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sham_rack
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 31
4
5
  prerelease: false
5
6
  segments:
6
7
  - 1
7
8
  - 3
8
- - 1
9
- version: 1.3.1
9
+ - 2
10
+ version: 1.3.2
10
11
  platform: ruby
11
12
  authors:
12
13
  - Mike Williams
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-07-12 00:00:00 +10:00
18
+ date: 2010-09-02 00:00:00 +10:00
18
19
  default_executable:
19
20
  dependencies: []
20
21
 
@@ -27,14 +28,19 @@ extensions: []
27
28
  extra_rdoc_files: []
28
29
 
29
30
  files:
30
- - lib/sham_rack/core_ext/net/http.rb
31
- - lib/sham_rack/http.rb
31
+ - lib/sham_rack/net_http.rb
32
32
  - lib/sham_rack/registry.rb
33
33
  - lib/sham_rack/stub_web_service.rb
34
34
  - lib/sham_rack/version.rb
35
35
  - lib/sham_rack.rb
36
36
  - README.markdown
37
37
  - CHANGES.markdown
38
+ - spec/sham_rack/stub_web_service_spec.rb
39
+ - spec/sham_rack_spec.rb
40
+ - spec/spec_helper.rb
41
+ - Rakefile
42
+ - benchmark/benchmark.rb
43
+ - benchmark/hello_app.rb
38
44
  has_rdoc: true
39
45
  homepage: http://github.com/mdub/sham_rack
40
46
  licenses: []
@@ -45,23 +51,27 @@ rdoc_options: []
45
51
  require_paths:
46
52
  - lib
47
53
  required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
48
55
  requirements:
49
56
  - - ">="
50
57
  - !ruby/object:Gem::Version
58
+ hash: 3
51
59
  segments:
52
60
  - 0
53
61
  version: "0"
54
62
  required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
55
64
  requirements:
56
65
  - - ">="
57
66
  - !ruby/object:Gem::Version
67
+ hash: 3
58
68
  segments:
59
69
  - 0
60
70
  version: "0"
61
71
  requirements: []
62
72
 
63
73
  rubyforge_project: shamrack
64
- rubygems_version: 1.3.6
74
+ rubygems_version: 1.3.7
65
75
  signing_key:
66
76
  specification_version: 3
67
77
  summary: Net::HTTP-to-Rack plumbing
@@ -1,20 +0,0 @@
1
- require "net/http"
2
- require "sham_rack/registry"
3
- require "sham_rack/http"
4
-
5
- class << Net::HTTP
6
-
7
- alias :new_without_sham_rack :new
8
-
9
- def new(address, port = nil, *proxy_args)
10
- port ||= Net::HTTP.default_port
11
- rack_app = ShamRack.application_for(address, port)
12
- http_object = new_without_sham_rack(address, port, *proxy_args)
13
- if rack_app
14
- http_object.extend(ShamRack::HTTP::Extensions)
15
- http_object.rack_app = rack_app
16
- end
17
- http_object
18
- end
19
-
20
- end