sham_rack 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ ## 5-Jun-2009 [mdub@dogbiscuit.org]
2
+
3
+ * Add support for Net::HTTP.get_response.
4
+ * Pass back headers provided by Rack app in the HTTPResponse.
5
+
1
6
  ## 3-Jun-2009 [mdub@dogbiscuit.org]
2
7
 
3
8
  * Introduced ShamRack#at to simplify registration of apps.
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 1
3
2
  :major: 1
4
3
  :minor: 1
4
+ :patch: 2
@@ -29,6 +29,22 @@ module ShamRack
29
29
  return response
30
30
  end
31
31
 
32
+ def request_get(path, initheader = nil, &block)
33
+ request Net::HTTP::Get.new(path, initheader), &block
34
+ end
35
+
36
+ def request_head(path, initheader = nil, &block)
37
+ request Net::HTTP::Head.new(path, initheader), &block
38
+ end
39
+
40
+ def request_post(path, data, initheader = nil, &block)
41
+ request Net::HTTP::Post.new(path, initheader), data, &block
42
+ end
43
+
44
+ def request_put(path, data, initheader = nil, &block)
45
+ request Net::HTTP::Put.new(path, initheader), data, &block
46
+ end
47
+
32
48
  private
33
49
 
34
50
  def default_env
@@ -84,6 +100,9 @@ module ShamRack
84
100
  response = Net::HTTPResponse.send(:response_class, code).new("Sham", code, message)
85
101
  response.instance_variable_set(:@body, assemble_body(body))
86
102
  response.instance_variable_set(:@read, true)
103
+ headers.each do |k,v|
104
+ response.add_field(k, v)
105
+ end
87
106
  response.extend ShamRack::ResponseExtensions
88
107
  return response
89
108
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{sham_rack}
5
- s.version = "1.1.1"
5
+ s.version = "1.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Mike Williams"]
9
- s.date = %q{2009-06-03}
9
+ s.date = %q{2009-06-05}
10
10
  s.description = %q{ShamRack plumbs Net::HTTP directly into Rack, for quick and easy HTTP testing.}
11
11
  s.email = %q{mdub@dogbiscuit.org}
12
12
  s.extra_rdoc_files = [
@@ -75,6 +75,11 @@ describe ShamRack do
75
75
  response.body.should == "Hello, world"
76
76
  end
77
77
 
78
+ it "can be accessed using Net::HTTP#get_response" do
79
+ response = Net::HTTP.get_response(URI.parse("http://www.test.xyz/"))
80
+ response.body.should == "Hello, world"
81
+ end
82
+
78
83
  it "can be accessed using open-uri" do
79
84
  response = open("http://www.test.xyz")
80
85
  response.status.should == ["200", "OK"]
@@ -89,6 +94,37 @@ describe ShamRack do
89
94
 
90
95
  end
91
96
 
97
+ describe "response" do
98
+
99
+ before(:each) do
100
+ ShamRack.at("www.test.xyz") do
101
+ [
102
+ "201 Created",
103
+ { "Content-Type" => "text/plain", "X-Foo" => "bar" },
104
+ "BODY"
105
+ ]
106
+ end
107
+ @response = Net::HTTP.get_response(URI.parse("http://www.test.xyz/"))
108
+ end
109
+
110
+ it "has status returned by app" do
111
+ @response.code.should == "201"
112
+ end
113
+
114
+ it "has body returned by app" do
115
+ @response.body.should == "BODY"
116
+ end
117
+
118
+ it "has Content-Type returned by app" do
119
+ @response.content_type.should == "text/plain"
120
+ end
121
+
122
+ it "has other headers returned by app" do
123
+ @response["x-foo"].should =="bar"
124
+ end
125
+
126
+ end
127
+
92
128
  describe "#at" do
93
129
 
94
130
  describe "with a block" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sham_rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Williams
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-03 00:00:00 +10:00
12
+ date: 2009-06-05 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies: []
15
15