forked from postrank-labs/goliath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest_spec.rb
More file actions
78 lines (60 loc) · 1.95 KB
/
Copy pathrequest_spec.rb
File metadata and controls
78 lines (60 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require 'spec_helper'
describe Goliath::Request do
before(:each) do
app = mock('app').as_null_object
env = Goliath::Env.new
@r = Goliath::Request.new(app, nil, env)
end
describe 'initialization' do
it 'initializes env defaults' do
env = Goliath::Env.new
env['INIT'] = 'init'
r = Goliath::Request.new(nil, nil, env)
r.env['INIT'].should == 'init'
end
it 'initializes an async callback' do
@r.env['async.callback'].should_not be_nil
end
it 'initializes request' do
@r.instance_variable_get("@state").should == :processing
end
end
describe 'process' do
it 'executes the application' do
app_mock = mock('app').as_null_object
env_mock = mock('app').as_null_object
request = Goliath::Request.new(app_mock, nil, env_mock)
app_mock.should_receive(:call).with(request.env)
request.should_receive(:post_process)
request.process
end
end
describe 'finished?' do
it "returns false if the request parsing has not yet finished" do
@r.finished?.should be_false
end
it 'returns true if we have finished request parsing' do
@r.should_receive(:post_process).and_return(nil)
@r.process
@r.finished?.should be_true
end
end
describe 'parse_headers' do
it 'sets content_type correctly' do
parser = mock('parser').as_null_object
@r.parse_header({'Content-Type' => 'text/plain'}, parser)
@r.env['CONTENT_TYPE'].should == 'text/plain'
end
it 'sets content_length correctly' do
parser = mock('parser').as_null_object
@r.parse_header({'Content-Length' => 42}, parser)
@r.env['CONTENT_LENGTH'].should == 42
end
it 'sets server_name and server_port correctly' do
parser = mock('parser').as_null_object
@r.parse_header({'Host' => 'myhost.com:3000'}, parser)
@r.env['SERVER_NAME'].should == 'myhost.com'
@r.env['SERVER_PORT'].should == '3000'
end
end
end