hobbit 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/hobbit/response.rb +15 -3
- data/lib/hobbit/version.rb +1 -1
- data/spec/response_spec.rb +7 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ad21a4064eb73894490f6439b24759e4e205152
|
4
|
+
data.tar.gz: a39b6f89449f3f610b8ea689a9be411640491834
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0d3165b578580625915845cc1c681c03edfcc6a9ab8aae7a8ef9cc009152fc533592be8479741f628ba65970562e9210cb771bd1c313fae13f309b7f29f7b17
|
7
|
+
data.tar.gz: f0ae8fb5175333c1bb06484141e0609cb34c0340315cef48c95fb79227529284cf657d15eabe49ce4b23d9cb63055791f70f6f4ba1754a42e0e0058f9d598228
|
data/CHANGELOG.md
CHANGED
data/lib/hobbit/response.rb
CHANGED
@@ -7,11 +7,20 @@ module Hobbit
|
|
7
7
|
def_delegators :headers, :[], :[]=
|
8
8
|
|
9
9
|
def initialize(body = [], status = 200, headers = { 'Content-Type' => 'text/html; charset=utf-8' })
|
10
|
-
@body, @headers, @status =
|
10
|
+
@body, @headers, @status = [], headers, status
|
11
|
+
@length = 0
|
12
|
+
|
13
|
+
if body.respond_to? :to_str
|
14
|
+
write body.to_str
|
15
|
+
elsif body.respond_to? :each
|
16
|
+
body.each { |i| write i.to_s }
|
17
|
+
else
|
18
|
+
raise TypeError, 'body must #respond_to? :to_str or :each'
|
19
|
+
end
|
11
20
|
end
|
12
21
|
|
13
22
|
def finish
|
14
|
-
headers['Content-Length'] =
|
23
|
+
headers['Content-Length'] = @length.to_s
|
15
24
|
[status, headers, body]
|
16
25
|
end
|
17
26
|
|
@@ -21,7 +30,10 @@ module Hobbit
|
|
21
30
|
end
|
22
31
|
|
23
32
|
def write(string)
|
24
|
-
|
33
|
+
s = string.to_s
|
34
|
+
@length += s.bytesize
|
35
|
+
|
36
|
+
body << s
|
25
37
|
end
|
26
38
|
end
|
27
39
|
end
|
data/lib/hobbit/version.rb
CHANGED
data/spec/response_spec.rb
CHANGED
@@ -11,12 +11,16 @@ describe Hobbit::Response do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'must set the body, status and headers with arguments given' do
|
14
|
-
status, headers, body = 200, { 'Content-Type' => 'application/json' }, ['{"name":"Hobbit"}']
|
14
|
+
status, headers, body = 200, { 'Content-Type' => 'application/json' }, ['{"name": "Hobbit"}']
|
15
15
|
response = Hobbit::Response.new body, status, headers
|
16
16
|
response.status.must_equal status
|
17
17
|
response.headers.must_equal headers
|
18
18
|
response.body.must_equal body
|
19
19
|
end
|
20
|
+
|
21
|
+
it 'must raise a TypeError if body does not respond to :to_str or :each' do
|
22
|
+
proc { Hobbit::Response.new 1 }.must_raise TypeError
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
26
|
describe '#[]' do
|
@@ -48,7 +52,7 @@ describe Hobbit::Response do
|
|
48
52
|
describe '#finish' do
|
49
53
|
let(:status) { 200 }
|
50
54
|
let(:headers) { { 'Content-Type' => 'application/json' } }
|
51
|
-
let(:body) { ['{"name":"Hobbit"}'] }
|
55
|
+
let(:body) { ['{"name": "Hobbit"}'] }
|
52
56
|
|
53
57
|
it 'must return a 3 elements array with status, headers and body' do
|
54
58
|
response = Hobbit::Response.new body, status, headers
|
@@ -59,7 +63,7 @@ describe Hobbit::Response do
|
|
59
63
|
response = Hobbit::Response.new body, status, headers
|
60
64
|
s, h, b = response.finish
|
61
65
|
h.must_include 'Content-Length'
|
62
|
-
h['Content-Length'].must_equal '
|
66
|
+
h['Content-Length'].must_equal '18'
|
63
67
|
end
|
64
68
|
|
65
69
|
it 'must calculate the Content-Length of the body, even if the body is empty' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hobbit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patricio Mac Adden
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|