goliath 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of goliath might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/goliath.gemspec +1 -0
- data/lib/goliath/connection.rb +15 -11
- data/lib/goliath/constants.rb +1 -0
- data/lib/goliath/rack/default_response_format.rb +3 -9
- data/lib/goliath/rack/formatters/json.rb +1 -1
- data/lib/goliath/rack/params.rb +1 -1
- data/lib/goliath/request.rb +35 -18
- data/lib/goliath/response.rb +2 -0
- data/lib/goliath/version.rb +1 -1
- data/spec/integration/async_request_processing.rb +2 -2
- data/spec/integration/chunked_streaming_spec.rb +1 -1
- data/spec/integration/early_abort_spec.rb +5 -5
- data/spec/integration/echo_spec.rb +7 -7
- data/spec/integration/empty_body_spec.rb +2 -2
- data/spec/integration/event_stream_spec.rb +3 -3
- data/spec/integration/exception_handling_spec.rb +16 -16
- data/spec/integration/http_log_spec.rb +16 -16
- data/spec/integration/jsonp_spec.rb +6 -6
- data/spec/integration/keepalive_spec.rb +2 -2
- data/spec/integration/pipelining_spec.rb +3 -3
- data/spec/integration/reloader_spec.rb +3 -3
- data/spec/integration/template_spec.rb +7 -7
- data/spec/integration/test_helper_spec.rb +3 -3
- data/spec/integration/trace_spec.rb +2 -2
- data/spec/integration/valid_spec.rb +8 -8
- data/spec/integration/websocket_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -3
- data/spec/unit/api_spec.rb +1 -1
- data/spec/unit/connection_spec.rb +8 -8
- data/spec/unit/console_spec.rb +3 -3
- data/spec/unit/env_spec.rb +9 -9
- data/spec/unit/headers_spec.rb +8 -8
- data/spec/unit/rack/default_mime_type_spec.rb +3 -3
- data/spec/unit/rack/formatters/json_spec.rb +35 -13
- data/spec/unit/rack/formatters/plist_spec.rb +8 -8
- data/spec/unit/rack/formatters/xml_spec.rb +18 -18
- data/spec/unit/rack/formatters/yaml_spec.rb +13 -13
- data/spec/unit/rack/heartbeat_spec.rb +15 -15
- data/spec/unit/rack/params_spec.rb +62 -60
- data/spec/unit/rack/render_spec.rb +14 -14
- data/spec/unit/rack/validation/boolean_value_spec.rb +6 -6
- data/spec/unit/rack/validation/default_params_spec.rb +13 -13
- data/spec/unit/rack/validation/numeric_range_spec.rb +17 -17
- data/spec/unit/rack/validation/param_spec.rb +75 -75
- data/spec/unit/rack/validation/request_method_spec.rb +9 -9
- data/spec/unit/rack/validation/required_param_spec.rb +28 -28
- data/spec/unit/rack/validation/required_value_spec.rb +19 -19
- data/spec/unit/request_spec.rb +18 -18
- data/spec/unit/response_spec.rb +6 -6
- data/spec/unit/runner_spec.rb +31 -31
- data/spec/unit/server_spec.rb +21 -21
- data/spec/unit/validation/standard_http_errors_spec.rb +6 -6
- metadata +16 -2
@@ -42,7 +42,7 @@ describe HttpLog do
|
|
42
42
|
mock_mongo(api)
|
43
43
|
|
44
44
|
get_request({}, err) do |c|
|
45
|
-
c.response_header.status.
|
45
|
+
expect(c.response_header.status).to eq(200)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -53,9 +53,9 @@ describe HttpLog do
|
|
53
53
|
mock_mongo(api)
|
54
54
|
|
55
55
|
get_request({}, err) do |c|
|
56
|
-
c.response_header.status.
|
57
|
-
c.response_header['SPECIAL'].
|
58
|
-
c.response.
|
56
|
+
expect(c.response_header.status).to eq(200)
|
57
|
+
expect(c.response_header['SPECIAL']).to eq('Header')
|
58
|
+
expect(c.response).to eq('Hello from Responder')
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -63,8 +63,8 @@ describe HttpLog do
|
|
63
63
|
context 'HTTP header handling' do
|
64
64
|
it 'transforms back properly' do
|
65
65
|
hl = HttpLog.new
|
66
|
-
hl.to_http_header("SPECIAL").
|
67
|
-
hl.to_http_header("CONTENT_TYPE").
|
66
|
+
expect(hl.to_http_header("SPECIAL")).to eq('Special')
|
67
|
+
expect(hl.to_http_header("CONTENT_TYPE")).to eq('Content-Type')
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -75,8 +75,8 @@ describe HttpLog do
|
|
75
75
|
mock_mongo(api)
|
76
76
|
|
77
77
|
get_request({:query => {:first => :foo, :second => :bar, :third => :baz}}, err) do |c|
|
78
|
-
c.response_header.status.
|
79
|
-
c.response_header["PARAMS"].
|
78
|
+
expect(c.response_header.status).to eq(200)
|
79
|
+
expect(c.response_header["PARAMS"]).to eq("first: foo|second: bar|third: baz")
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
@@ -89,8 +89,8 @@ describe HttpLog do
|
|
89
89
|
mock_mongo(api)
|
90
90
|
|
91
91
|
get_request({:path => '/my/request/path'}, err) do |c|
|
92
|
-
c.response_header.status.
|
93
|
-
c.response_header['PATH'].
|
92
|
+
expect(c.response_header.status).to eq(200)
|
93
|
+
expect(c.response_header['PATH']).to eq('/my/request/path')
|
94
94
|
end
|
95
95
|
end
|
96
96
|
end
|
@@ -103,8 +103,8 @@ describe HttpLog do
|
|
103
103
|
mock_mongo(api)
|
104
104
|
|
105
105
|
get_request({:head => {:first => :foo, :second => :bar}}, err) do |c|
|
106
|
-
c.response_header.status.
|
107
|
-
c.response_header["HEADERS"].
|
106
|
+
expect(c.response_header.status).to eq(200)
|
107
|
+
expect(c.response_header["HEADERS"]).to match(/First: foo\|Second: bar/)
|
108
108
|
end
|
109
109
|
end
|
110
110
|
end
|
@@ -117,8 +117,8 @@ describe HttpLog do
|
|
117
117
|
mock_mongo(api)
|
118
118
|
|
119
119
|
get_request({}, err) do |c|
|
120
|
-
c.response_header.status.
|
121
|
-
c.response_header["METHOD"].
|
120
|
+
expect(c.response_header.status).to eq(200)
|
121
|
+
expect(c.response_header["METHOD"]).to eq("GET")
|
122
122
|
end
|
123
123
|
end
|
124
124
|
end
|
@@ -129,8 +129,8 @@ describe HttpLog do
|
|
129
129
|
mock_mongo(api)
|
130
130
|
|
131
131
|
post_request({}, err) do |c|
|
132
|
-
c.response_header.status.
|
133
|
-
c.response_header["METHOD"].
|
132
|
+
expect(c.response_header.status).to eq(200)
|
133
|
+
expect(c.response_header["METHOD"]).to eq("POST")
|
134
134
|
end
|
135
135
|
end
|
136
136
|
end
|
@@ -30,7 +30,7 @@ describe 'JSONP' do
|
|
30
30
|
it 'does not alter the content type' do
|
31
31
|
with_api(JSON_API) do
|
32
32
|
get_request({ query: query }, err) do |c|
|
33
|
-
c.response_header['CONTENT_TYPE'].
|
33
|
+
expect(c.response_header['CONTENT_TYPE']).to match(%r{^application/json})
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -38,7 +38,7 @@ describe 'JSONP' do
|
|
38
38
|
it 'does not alter the content length' do
|
39
39
|
with_api(JSON_API) do
|
40
40
|
get_request({ query: query }, err) do |c|
|
41
|
-
c.response_header['CONTENT_LENGTH'].to_i.
|
41
|
+
expect(c.response_header['CONTENT_LENGTH'].to_i).to eq(2)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -46,7 +46,7 @@ describe 'JSONP' do
|
|
46
46
|
it 'does not wrap the response with anything' do
|
47
47
|
with_api(JSON_API) do
|
48
48
|
get_request({ query: query }, err) do |c|
|
49
|
-
c.response.
|
49
|
+
expect(c.response).to eq('OK')
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -58,7 +58,7 @@ describe 'JSONP' do
|
|
58
58
|
it 'adjusts the content type' do
|
59
59
|
with_api(JSON_API) do
|
60
60
|
get_request({ query: query }, err) do |c|
|
61
|
-
c.response_header['CONTENT_TYPE'].
|
61
|
+
expect(c.response_header['CONTENT_TYPE']).to match(%r{^application/javascript})
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
@@ -66,7 +66,7 @@ describe 'JSONP' do
|
|
66
66
|
it 'adjusts the content length' do
|
67
67
|
with_api(JSON_API) do
|
68
68
|
get_request({ query: query }, err) do |c|
|
69
|
-
c.response_header['CONTENT_LENGTH'].to_i.
|
69
|
+
expect(c.response_header['CONTENT_LENGTH'].to_i).to eq(8)
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
@@ -74,7 +74,7 @@ describe 'JSONP' do
|
|
74
74
|
it 'wraps response with callback' do
|
75
75
|
with_api(JSON_API) do
|
76
76
|
get_request({ query: query }, err) do |c|
|
77
|
-
c.response.
|
77
|
+
expect(c.response).to match(/^test\(.*\)$/)
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
@@ -10,13 +10,13 @@ describe 'HTTP Keep-Alive support' do
|
|
10
10
|
r1.errback { fail }
|
11
11
|
r1.callback do |c|
|
12
12
|
b = MultiJson.load(c.response)
|
13
|
-
b['response'].
|
13
|
+
expect(b['response']).to eq('test')
|
14
14
|
|
15
15
|
r2 = conn.get(:query => {:echo => 'test2'})
|
16
16
|
r2.errback { fail }
|
17
17
|
r2.callback do |c|
|
18
18
|
b = MultiJson.load(c.response)
|
19
|
-
b['response'].
|
19
|
+
expect(b['response']).to eq('test2')
|
20
20
|
|
21
21
|
stop
|
22
22
|
end
|
@@ -24,15 +24,15 @@ describe 'HTTP Pipelining support' do
|
|
24
24
|
r1.errback { fail }
|
25
25
|
r1.callback do |c|
|
26
26
|
res << c.response
|
27
|
-
c.response.
|
27
|
+
expect(c.response).to match('0.3')
|
28
28
|
end
|
29
29
|
|
30
30
|
r2.errback { fail }
|
31
31
|
r2.callback do |c|
|
32
32
|
res << c.response
|
33
33
|
|
34
|
-
res.
|
35
|
-
(Time.now.to_f - start).
|
34
|
+
expect(res).to eq(['0.3', '0.2'])
|
35
|
+
expect(Time.now.to_f - start).to be_within(0.1).of(0.3)
|
36
36
|
|
37
37
|
stop
|
38
38
|
end
|
@@ -29,15 +29,15 @@ describe "Reloader" do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'adds reloader in dev mode' do
|
32
|
-
count(ReloaderDev).
|
32
|
+
expect(count(ReloaderDev)).to eq(1)
|
33
33
|
end
|
34
34
|
|
35
35
|
it "doesn't add if it's already there in dev mode" do
|
36
|
-
count(ReloaderAlreadyLoaded).
|
36
|
+
expect(count(ReloaderAlreadyLoaded)).to eq(1)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "doesn't add in prod mode" do
|
40
40
|
Goliath.env = :production
|
41
|
-
count(ReloaderProd).
|
41
|
+
expect(count(ReloaderProd)).to eq(0)
|
42
42
|
end
|
43
43
|
end
|
@@ -11,7 +11,7 @@ describe Template do
|
|
11
11
|
it 'renders haml template with default haml layout' do
|
12
12
|
with_api(Template, api_options) do
|
13
13
|
get_request(:path => '/') do |c|
|
14
|
-
c.response.
|
14
|
+
expect(c.response).to match(%r{<li><a href="/joke">Tell me a joke</a></li>})
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -19,7 +19,7 @@ describe Template do
|
|
19
19
|
it 'renders haml template from string with default haml layout' do
|
20
20
|
with_api(Template, api_options) do
|
21
21
|
get_request(:path => '/haml_str') do |c|
|
22
|
-
c.response.
|
22
|
+
expect(c.response).to match(%r{<h1>Header</h1>})
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -27,7 +27,7 @@ describe Template do
|
|
27
27
|
it 'renders a markdown template with default haml layout' do
|
28
28
|
with_api(Template, api_options) do
|
29
29
|
get_request(:path => '/joke') do |c|
|
30
|
-
c.response.
|
30
|
+
expect(c.response).to match(%r{<code>Arr, I dunno matey -- but it is driving me nuts!\s*</code>}m)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -35,7 +35,7 @@ describe Template do
|
|
35
35
|
it 'lets me specify an alternate layout engine' do
|
36
36
|
with_api(Template, api_options) do
|
37
37
|
get_request(:path => '/erb_me') do |c|
|
38
|
-
c.response.
|
38
|
+
expect(c.response).to match(%r{I AM ERB</h1>}m)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -43,7 +43,7 @@ describe Template do
|
|
43
43
|
it 'accepts local variables' do
|
44
44
|
with_api(Template, api_options) do
|
45
45
|
get_request(:path => '/erb_me') do |c|
|
46
|
-
c.response.
|
46
|
+
expect(c.response).to match(%r{<title>HERE IS A JOKE</title>}m)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -52,8 +52,8 @@ describe Template do
|
|
52
52
|
it 'raises an explanatory 500 error' do
|
53
53
|
with_api(Template, api_options) do
|
54
54
|
get_request(:path => '/oops') do |c|
|
55
|
-
c.response.
|
56
|
-
c.response_header.status.
|
55
|
+
expect(c.response).to match(%r{^\[:error, "Template no_such_template not found in .*examples/views for haml"\]$})
|
56
|
+
expect(c.response_header.status).to eq(500)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
@@ -11,20 +11,20 @@ describe "with_api" do
|
|
11
11
|
with_api(DummyServer, :log_file => "test.log") do |api|
|
12
12
|
get_request({},err)
|
13
13
|
end
|
14
|
-
File.exist?("test.log").
|
14
|
+
expect(File.exist?("test.log")).to be_truthy
|
15
15
|
File.unlink("test.log")
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should log on console if requested" do
|
19
19
|
with_api(DummyServer, {:log_stdout => true }) do |api|
|
20
|
-
api.logger.outputters.select {|o| o.is_a? Log4r::StdoutOutputter}.
|
20
|
+
expect(api.logger.outputters.select {|o| o.is_a? Log4r::StdoutOutputter}).not_to be_empty
|
21
21
|
EM.stop
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should be verbose if asked" do
|
26
26
|
with_api(DummyServer, {:verbose => true, :log_stdout => true }) do |api|
|
27
|
-
api.logger.level.
|
27
|
+
expect(api.logger.level).to eq(Log4r::DEBUG)
|
28
28
|
EM.stop
|
29
29
|
end
|
30
30
|
|
@@ -8,7 +8,7 @@ describe Goliath::Rack::Tracer do
|
|
8
8
|
it 'injects a trace param on a 200 (via async callback)' do
|
9
9
|
with_api(Echo) do
|
10
10
|
get_request({:query => {:echo => 'test'}}, err) do |c|
|
11
|
-
c.response_header['X_POSTRANK'].
|
11
|
+
expect(c.response_header['X_POSTRANK']).to match(/trace\.start: [\d\.]+, total: [\d\.]+/)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -16,7 +16,7 @@ describe Goliath::Rack::Tracer do
|
|
16
16
|
it 'injects a trace param on a 400 (direct callback)' do
|
17
17
|
with_api(Echo) do
|
18
18
|
get_request({}, err) do |c|
|
19
|
-
c.response_header['X_POSTRANK'].
|
19
|
+
expect(c.response_header['X_POSTRANK']).to match(/trace\.start: [\d\.]+, total: [\d\.]+/)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -38,7 +38,7 @@ describe ValidSingleParam do
|
|
38
38
|
it 'returns OK with param' do
|
39
39
|
with_api(ValidSingleParam) do
|
40
40
|
get_request({:query => {:test => 'test'}}, err) do |c|
|
41
|
-
c.response.
|
41
|
+
expect(c.response).to eq('OK')
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -46,7 +46,7 @@ describe ValidSingleParam do
|
|
46
46
|
it 'returns error without param' do
|
47
47
|
with_api(ValidSingleParam) do
|
48
48
|
get_request({}, err) do |c|
|
49
|
-
c.response.
|
49
|
+
expect(c.response).to eq('[:error, "test identifier missing"]')
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -64,9 +64,9 @@ describe ValidationErrorInEndpoint do
|
|
64
64
|
it 'handles Goliath::Validation::Error correctly' do
|
65
65
|
with_api(ValidationErrorInEndpoint) do
|
66
66
|
get_request({}, err) do |c|
|
67
|
-
c.response.
|
68
|
-
c.response_header.status.
|
69
|
-
c.response_header["Foo"].
|
67
|
+
expect(c.response).to eq('[:error, "You Must Chill"]')
|
68
|
+
expect(c.response_header.status).to eq(420)
|
69
|
+
expect(c.response_header["Foo"]).to eq('Bar')
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
@@ -84,9 +84,9 @@ describe ValidationErrorWhileParsing do
|
|
84
84
|
it 'handles Goliath::Validation::Error correctly' do
|
85
85
|
with_api(ValidationErrorInEndpoint) do
|
86
86
|
get_request({}, err) do |c|
|
87
|
-
c.response.
|
88
|
-
c.response_header.status.
|
89
|
-
c.response_header["Foo"].
|
87
|
+
expect(c.response).to eq('[:error, "You Must Chill"]')
|
88
|
+
expect(c.response_header.status).to eq(420)
|
89
|
+
expect(c.response_header["Foo"]).to eq('Bar')
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
@@ -26,7 +26,7 @@ describe "WebSocket" do
|
|
26
26
|
|
27
27
|
it "should accept connection" do
|
28
28
|
with_api(WebSocketEndPoint, {:verbose => true, :log_stdout => true}) do |server|
|
29
|
-
WebSocketEndPoint.
|
29
|
+
expect_any_instance_of(WebSocketEndPoint).to receive(:on_open)
|
30
30
|
ws_client_connect('/ws')
|
31
31
|
end
|
32
32
|
end
|
@@ -35,7 +35,7 @@ describe "WebSocket" do
|
|
35
35
|
with_api(WebSocketEndPoint, {:verbose => true, :log_stdout => true}) do |server|
|
36
36
|
ws_client_connect('/ws') do |client|
|
37
37
|
client.send "hello"
|
38
|
-
client.receive.data.
|
38
|
+
expect(client.receive.data).to eq("hello")
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/unit/api_spec.rb
CHANGED
@@ -9,39 +9,39 @@ describe Goliath::Connection do
|
|
9
9
|
it 'accepts an app' do
|
10
10
|
app = double('app')
|
11
11
|
@c.app = app
|
12
|
-
@c.app.
|
12
|
+
expect(@c.app).to eq(app)
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'accepts a logger' do
|
16
16
|
logger = double('logger')
|
17
17
|
@c.logger = logger
|
18
|
-
@c.logger.
|
18
|
+
expect(@c.logger).to eq(logger)
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'accepts a status object' do
|
22
22
|
status = double('status')
|
23
23
|
@c.status = status
|
24
|
-
@c.status.
|
24
|
+
expect(@c.status).to eq(status)
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'accepts config' do
|
28
28
|
config = double('config')
|
29
29
|
@c.config = config
|
30
|
-
@c.config.
|
30
|
+
expect(@c.config).to eq(config)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
describe 'post_init' do
|
35
35
|
it 'sets up the parser' do
|
36
36
|
@c.post_init
|
37
|
-
@c.instance_variable_get("@parser").
|
37
|
+
expect(@c.instance_variable_get("@parser")).not_to be_nil
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
describe 'receive_data' do
|
42
42
|
it 'passes data to the http parser' do
|
43
43
|
request_mock = double("parser").as_null_object
|
44
|
-
request_mock.
|
44
|
+
expect(request_mock).to receive(:<<)
|
45
45
|
|
46
46
|
current_mock = double("current").as_null_object
|
47
47
|
|
@@ -52,10 +52,10 @@ describe Goliath::Connection do
|
|
52
52
|
|
53
53
|
it "closes the connection when a parse error is received" do
|
54
54
|
current_mock = double("current").as_null_object
|
55
|
-
current_mock.
|
55
|
+
expect(current_mock).to receive(:close)
|
56
56
|
|
57
57
|
@c.instance_variable_set("@current", current_mock)
|
58
|
-
|
58
|
+
expect { @c.receive_data("bad data") }.not_to raise_error
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
data/spec/unit/console_spec.rb
CHANGED
@@ -9,9 +9,9 @@ describe Goliath::Console do
|
|
9
9
|
|
10
10
|
describe 'run!' do
|
11
11
|
it "starts a irb session" do
|
12
|
-
Object.
|
13
|
-
IRB.
|
14
|
-
@server.
|
12
|
+
expect(Object).to receive(:send).with(:define_method, :goliath_server)
|
13
|
+
expect(IRB).to receive(:start)
|
14
|
+
expect(@server).to receive(:load_config)
|
15
15
|
Goliath::Console.run!(@server)
|
16
16
|
end
|
17
17
|
end
|
data/spec/unit/env_spec.rb
CHANGED
@@ -7,49 +7,49 @@ describe Goliath::Env do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'responds to []=' do
|
10
|
-
|
10
|
+
expect { @env['test'] = 'blah' }.not_to raise_error
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'responds to []' do
|
14
14
|
@env['test'] = 'blah'
|
15
|
-
|
15
|
+
expect { expect(@env['test']).to eq('blah') }.not_to raise_error
|
16
16
|
end
|
17
17
|
|
18
18
|
context '#method_missing' do
|
19
19
|
it 'allows access to items as methods' do
|
20
20
|
@env['db'] = 'test'
|
21
|
-
@env.db.
|
21
|
+
expect(@env.db).to eq('test')
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'allows access to config items as methods' do
|
25
25
|
@env['config'] = {}
|
26
26
|
@env['config']['db'] = 'test'
|
27
|
-
@env.db.
|
27
|
+
expect(@env.db).to eq('test')
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
context '#respond_to?' do
|
32
32
|
it 'returns true for items in the hash' do
|
33
33
|
@env['test'] = 'true'
|
34
|
-
@env.respond_to?(:test).
|
34
|
+
expect(@env.respond_to?(:test)).to be true
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'returns false for items not in hash' do
|
38
|
-
@env.respond_to?(:test).
|
38
|
+
expect(@env.respond_to?(:test)).to be false
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'returns true for items in the config hash' do
|
42
42
|
@env['config'] = {'test' => true}
|
43
|
-
@env.respond_to?(:test).
|
43
|
+
expect(@env.respond_to?(:test)).to be true
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'returns false for items not in the config hash' do
|
47
47
|
@env['config'] = {}
|
48
|
-
@env.respond_to?(:test).
|
48
|
+
expect(@env.respond_to?(:test)).to be false
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'delegates if not found' do
|
52
|
-
@env.respond_to?(:[]).
|
52
|
+
expect(@env.respond_to?(:[])).to be true
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|