goliath 1.0.4 → 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.

Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -4
  3. data/goliath.gemspec +11 -7
  4. data/lib/goliath/api.rb +1 -1
  5. data/lib/goliath/connection.rb +15 -11
  6. data/lib/goliath/constants.rb +1 -0
  7. data/lib/goliath/rack/default_response_format.rb +3 -9
  8. data/lib/goliath/rack/formatters/json.rb +1 -1
  9. data/lib/goliath/rack/jsonp.rb +7 -2
  10. data/lib/goliath/rack/params.rb +4 -3
  11. data/lib/goliath/rack/validator.rb +1 -1
  12. data/lib/goliath/request.rb +37 -20
  13. data/lib/goliath/response.rb +2 -0
  14. data/lib/goliath/runner.rb +4 -3
  15. data/lib/goliath/server.rb +17 -2
  16. data/lib/goliath/test_helper_sse.rb +76 -0
  17. data/lib/goliath/validation/error.rb +4 -1
  18. data/lib/goliath/version.rb +1 -1
  19. data/spec/integration/async_request_processing.rb +2 -2
  20. data/spec/integration/chunked_streaming_spec.rb +1 -1
  21. data/spec/integration/early_abort_spec.rb +6 -6
  22. data/spec/integration/echo_spec.rb +7 -7
  23. data/spec/integration/empty_body_spec.rb +2 -2
  24. data/spec/integration/event_stream_spec.rb +50 -0
  25. data/spec/integration/exception_handling_spec.rb +202 -0
  26. data/spec/integration/http_log_spec.rb +16 -16
  27. data/spec/integration/jsonp_spec.rb +61 -10
  28. data/spec/integration/keepalive_spec.rb +2 -2
  29. data/spec/integration/pipelining_spec.rb +3 -3
  30. data/spec/integration/reloader_spec.rb +3 -3
  31. data/spec/integration/template_spec.rb +7 -7
  32. data/spec/integration/test_helper_spec.rb +3 -3
  33. data/spec/integration/trace_spec.rb +2 -2
  34. data/spec/integration/valid_spec.rb +25 -5
  35. data/spec/integration/websocket_spec.rb +2 -2
  36. data/spec/spec_helper.rb +1 -3
  37. data/spec/unit/api_spec.rb +1 -1
  38. data/spec/unit/connection_spec.rb +8 -8
  39. data/spec/unit/console_spec.rb +3 -3
  40. data/spec/unit/env_spec.rb +9 -9
  41. data/spec/unit/headers_spec.rb +8 -8
  42. data/spec/unit/rack/default_mime_type_spec.rb +3 -3
  43. data/spec/unit/rack/formatters/json_spec.rb +35 -13
  44. data/spec/unit/rack/formatters/plist_spec.rb +8 -8
  45. data/spec/unit/rack/formatters/xml_spec.rb +18 -18
  46. data/spec/unit/rack/formatters/yaml_spec.rb +13 -13
  47. data/spec/unit/rack/heartbeat_spec.rb +15 -15
  48. data/spec/unit/rack/params_spec.rb +99 -62
  49. data/spec/unit/rack/render_spec.rb +14 -14
  50. data/spec/unit/rack/validation/boolean_value_spec.rb +6 -6
  51. data/spec/unit/rack/validation/default_params_spec.rb +13 -13
  52. data/spec/unit/rack/validation/numeric_range_spec.rb +17 -17
  53. data/spec/unit/rack/validation/param_spec.rb +75 -75
  54. data/spec/unit/rack/validation/request_method_spec.rb +9 -9
  55. data/spec/unit/rack/validation/required_param_spec.rb +39 -39
  56. data/spec/unit/rack/validation/required_value_spec.rb +19 -19
  57. data/spec/unit/request_spec.rb +18 -18
  58. data/spec/unit/response_spec.rb +6 -6
  59. data/spec/unit/runner_spec.rb +31 -31
  60. data/spec/unit/server_spec.rb +21 -21
  61. data/spec/unit/validation/standard_http_errors_spec.rb +6 -6
  62. metadata +149 -94
  63. data/examples/around.rb +0 -38
  64. data/examples/clone.rb +0 -26
  65. data/examples/router.rb +0 -15
  66. data/examples/test.rb +0 -31
  67. data/examples/upload.rb +0 -17
@@ -7,7 +7,7 @@ describe Goliath::API do
7
7
 
8
8
  describe "middlewares" do
9
9
  it "doesn't change after multi calls" do
10
- 2.times { DummyApi.should have(2).middlewares }
10
+ 2.times { expect(DummyApi.middlewares.size).to eq(2) }
11
11
  end
12
12
  end
13
13
  end
@@ -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.should == 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.should == 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.should == 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.should == 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").should_not be_nil
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.should_receive(:<<)
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.should_receive(:close)
55
+ expect(current_mock).to receive(:close)
56
56
 
57
57
  @c.instance_variable_set("@current", current_mock)
58
- lambda { @c.receive_data("bad data") }.should_not raise_error
58
+ expect { @c.receive_data("bad data") }.not_to raise_error
59
59
  end
60
60
  end
61
61
 
@@ -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.should_receive(:send).with(:define_method, :goliath_server)
13
- IRB.should_receive(:start)
14
- @server.should_receive(:load_config)
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
@@ -7,49 +7,49 @@ describe Goliath::Env do
7
7
  end
8
8
 
9
9
  it 'responds to []=' do
10
- lambda { @env['test'] = 'blah' }.should_not raise_error
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
- lambda { @env['test'].should == 'blah' }.should_not raise_error
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.should == 'test'
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.should == 'test'
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).should be_true
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).should be_false
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).should be_true
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).should be_false
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?(:[]).should be_true
52
+ expect(@env.respond_to?(:[])).to be true
53
53
  end
54
54
  end
55
55
  end
@@ -8,46 +8,46 @@ describe Goliath::Headers do
8
8
 
9
9
  it 'outputs in the correct format' do
10
10
  @h['my_header'] = 'my_value'
11
- @h.to_s.should == "my_header: my_value\r\n"
11
+ expect(@h.to_s).to eq("my_header: my_value\r\n")
12
12
  end
13
13
 
14
14
  it 'suppresses duplicate keys' do
15
15
  @h['my_header'] = 'my_value1'
16
16
  @h['my_header'] = 'my_value2'
17
- @h.to_s.should == "my_header: my_value1\r\n"
17
+ expect(@h.to_s).to eq("my_header: my_value1\r\n")
18
18
  end
19
19
 
20
20
  it 'returns true if a key has been set' do
21
21
  @h['my_header'] = 'my_value'
22
- @h.has_key?('my_header').should be_true
22
+ expect(@h.has_key?('my_header')).to be true
23
23
  end
24
24
 
25
25
  it 'returns false if the key has not been set' do
26
- @h.has_key?('my_header').should be_false
26
+ expect(@h.has_key?('my_header')).to be false
27
27
  end
28
28
 
29
29
  it 'ignores nil values' do
30
30
  @h['my_header'] = nil
31
- @h.to_s.should == ''
31
+ expect(@h.to_s).to eq('')
32
32
  end
33
33
 
34
34
  it 'allows a value after setting nil' do
35
35
  @h['my_header'] = nil
36
36
  @h['my_header'] = 'my_value'
37
- @h.to_s.should == "my_header: my_value\r\n"
37
+ expect(@h.to_s).to eq("my_header: my_value\r\n")
38
38
  end
39
39
 
40
40
  it 'formats time as an http time' do
41
41
  time = Time.now
42
42
  @h['my_time'] = time
43
- @h.to_s.should == "my_time: #{time.httpdate}\r\n"
43
+ expect(@h.to_s).to eq("my_time: #{time.httpdate}\r\n")
44
44
  end
45
45
 
46
46
  %w(Set-Cookie Set-Cookie2 Warning WWW-Authenticate).each do |key|
47
47
  it "allows #{key} as to be duplicate" do
48
48
  @h[key] = 'value1'
49
49
  @h[key] = 'value2'
50
- @h.to_s.should == "#{key}: value1\r\n#{key}: value2\r\n"
50
+ expect(@h.to_s).to eq("#{key}: value1\r\n#{key}: value2\r\n")
51
51
  end
52
52
  end
53
53
  end
@@ -14,21 +14,21 @@ describe Goliath::Rack::DefaultMimeType do
14
14
  context 'accept header cleanup' do
15
15
  it 'handles a nil header' do
16
16
  env['HTTP_ACCEPT'] = nil
17
- lambda { dmt.call(env) }.should_not raise_error
17
+ expect { dmt.call(env) }.not_to raise_error
18
18
  end
19
19
 
20
20
  %w(gzip deflate compressed identity).each do |type|
21
21
  it "removes #{type} from the accept header" do
22
22
  env['HTTP_ACCEPT'] = "text/html, #{type}, text/javascript"
23
23
  dmt.call(env)
24
- env['HTTP_ACCEPT'].should == 'text/html, text/javascript'
24
+ expect(env['HTTP_ACCEPT']).to eq('text/html, text/javascript')
25
25
  end
26
26
  end
27
27
 
28
28
  it 'sets to */* if all entries removed' do
29
29
  env['HTTP_ACCEPT'] = 'identity'
30
30
  dmt.call(env)
31
- env['HTTP_ACCEPT'].should == '*/*'
31
+ expect(env['HTTP_ACCEPT']).to eq('*/*')
32
32
  end
33
33
  end
34
34
  end
@@ -3,7 +3,7 @@ require 'goliath/rack/formatters/json'
3
3
 
4
4
  describe Goliath::Rack::Formatters::JSON do
5
5
  it 'accepts an app' do
6
- lambda { Goliath::Rack::Formatters::JSON.new('my app') }.should_not raise_error
6
+ expect { Goliath::Rack::Formatters::JSON.new('my app') }.not_to raise_error
7
7
  end
8
8
 
9
9
  describe 'with a formatter' do
@@ -13,41 +13,63 @@ describe Goliath::Rack::Formatters::JSON do
13
13
  end
14
14
 
15
15
  it 'checks content type for application/json' do
16
- @js.json_response?({'Content-Type' => 'application/json'}).should be_true
16
+ expect(@js.json_response?({'Content-Type' => 'application/json'})).to be_truthy
17
+ end
18
+
19
+ it 'checks content type for application/vnd.api+json' do
20
+ expect(@js.json_response?({'Content-Type' => 'application/vnd.api+json'})).to be_truthy
21
+ end
22
+
23
+ it 'checks content type for application/javascript' do
24
+ expect(@js.json_response?({'Content-Type' => 'application/javascript'})).to be_truthy
17
25
  end
18
26
 
19
27
  it 'returns false for non-applicaton/json types' do
20
- @js.json_response?({'Content-Type' => 'application/xml'}).should be_false
28
+ expect(@js.json_response?({'Content-Type' => 'application/xml'})).to be_falsey
21
29
  end
22
30
 
23
31
  it 'calls the app with the provided environment' do
24
32
  env_mock = double('env').as_null_object
25
- @app.should_receive(:call).with(env_mock).and_return([200, {}, {"a" => 1}])
33
+ expect(@app).to receive(:call).with(env_mock).and_return([200, {}, {"a" => 1}])
26
34
  @js.call(env_mock)
27
35
  end
28
36
 
29
37
  it 'formats the body into json if content-type is json' do
30
- @app.should_receive(:call).and_return([200, {'Content-Type' => 'application/json'}, {:a => 1, :b => 2}])
38
+ expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'application/json'}, {:a => 1, :b => 2}])
39
+
40
+ status, header, body = @js.call({})
41
+ expect { expect(MultiJson.load(body.first)['a']).to eq(1) }.not_to raise_error
42
+ end
43
+
44
+ it 'formats the body into json if content-type is vnd.api+json' do
45
+ expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'application/vnd.api+json'}, {:a => 1, :b => 2}])
46
+
47
+ status, header, body = @js.call({})
48
+ expect { expect(MultiJson.load(body.first)['a']).to eq(1) }.not_to raise_error
49
+ end
50
+
51
+ it 'formats the body into json if content-type is javascript' do
52
+ expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'application/javascript'}, {:a => 1, :b => 2}])
31
53
 
32
54
  status, header, body = @js.call({})
33
- lambda { MultiJson.load(body.first)['a'].should == 1 }.should_not raise_error
55
+ expect { expect(MultiJson.load(body.first)['a']).to eq(1) }.not_to raise_error
34
56
  end
35
57
 
36
58
  it "doesn't format to json if the type is not application/json" do
37
- @app.should_receive(:call).and_return([200, {'Content-Type' => 'application/xml'}, {:a => 1, :b => 2}])
59
+ expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'application/xml'}, {:a => 1, :b => 2}])
38
60
 
39
- MultiJson.should_not_receive(:dump)
61
+ expect(MultiJson).not_to receive(:dump)
40
62
  status, header, body = @js.call({})
41
- body[:a].should == 1
63
+ expect(body[:a]).to eq(1)
42
64
  end
43
65
 
44
66
  it 'returns the status and headers' do
45
- @app.should_receive(:call).and_return([200, {'Content-Type' => 'application/xml'}, {:a => 1, :b => 2}])
67
+ expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'application/xml'}, {:a => 1, :b => 2}])
46
68
 
47
- MultiJson.should_not_receive(:dump)
69
+ expect(MultiJson).not_to receive(:dump)
48
70
  status, header, body = @js.call({})
49
- status.should == 200
50
- header.should == {'Content-Type' => 'application/xml'}
71
+ expect(status).to eq(200)
72
+ expect(header).to eq({'Content-Type' => 'application/xml'})
51
73
  end
52
74
  end
53
75
  end
@@ -17,7 +17,7 @@ describe Goliath::Rack::Formatters::PLIST do
17
17
  end
18
18
 
19
19
  it 'accepts an app' do
20
- lambda { Goliath::Rack::Formatters::PLIST.new('my app') }.should_not raise_error
20
+ expect { Goliath::Rack::Formatters::PLIST.new('my app') }.not_to raise_error
21
21
  end
22
22
 
23
23
  describe 'with a formatter' do
@@ -27,23 +27,23 @@ describe Goliath::Rack::Formatters::PLIST do
27
27
  end
28
28
 
29
29
  it 'formats the body into plist if content-type is plist' do
30
- @app.should_receive(:call).and_return([200, {'Content-Type' => 'application/x-plist'}, {:a => 1, :b => 2}])
30
+ expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'application/x-plist'}, {:a => 1, :b => 2}])
31
31
 
32
32
  status, header, body = @m.call({})
33
- body.should == ["plist: {:a=>1, :b=>2}"]
33
+ expect(body).to eq(["plist: {:a=>1, :b=>2}"])
34
34
  end
35
35
 
36
36
  it "doesn't format to plist if the type is not plist" do
37
- @app.should_receive(:call).and_return([200, {'Content-Type' => 'application/xml'}, {:a => 1, :b => 2}])
37
+ expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'application/xml'}, {:a => 1, :b => 2}])
38
38
  status, header, body = @m.call({})
39
- status.should == 200
40
- header.should == {'Content-Type' => 'application/xml'}
39
+ expect(status).to eq(200)
40
+ expect(header).to eq({'Content-Type' => 'application/xml'})
41
41
 
42
- body[:a].should == 1
42
+ expect(body[:a]).to eq(1)
43
43
  end
44
44
 
45
45
  it 'returns the status and headers' do
46
- @app.should_receive(:call).and_return([200, {'Content-Type' => 'application/xml'}, {:a => 1, :b => 2}])
46
+ expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'application/xml'}, {:a => 1, :b => 2}])
47
47
 
48
48
  status, header, body = @m.call({})
49
49
  end
@@ -4,7 +4,7 @@ require 'nokogiri'
4
4
 
5
5
  describe Goliath::Rack::Formatters::XML do
6
6
  it 'accepts an app' do
7
- lambda { Goliath::Rack::Formatters::XML.new('my app') }.should_not raise_error
7
+ expect { Goliath::Rack::Formatters::XML.new('my app') }.not_to raise_error
8
8
  end
9
9
 
10
10
  describe 'with a formatter' do
@@ -14,52 +14,52 @@ describe Goliath::Rack::Formatters::XML do
14
14
  end
15
15
 
16
16
  it 'checks content type for application/xml' do
17
- @xml.xml_response?({'Content-Type' => 'application/xml'}).should be_true
17
+ expect(@xml.xml_response?({'Content-Type' => 'application/xml'})).to be_truthy
18
18
  end
19
19
 
20
20
  it 'returns false for non-applicaton/xml types' do
21
- @xml.xml_response?({'Content-Type' => 'application/json'}).should be_false
21
+ expect(@xml.xml_response?({'Content-Type' => 'application/json'})).to be_falsey
22
22
  end
23
23
 
24
24
  it 'calls the app with the provided environment' do
25
25
  env_mock = double('env').as_null_object
26
- @app.should_receive(:call).with(env_mock).and_return([200, {}, {"a" => 1}])
26
+ expect(@app).to receive(:call).with(env_mock).and_return([200, {}, {"a" => 1}])
27
27
  @xml.call(env_mock)
28
28
  end
29
29
 
30
30
  it 'formats the body into xml if content-type is xml' do
31
- @app.should_receive(:call).and_return([200, {'Content-Type' => 'application/xml'}, {:a => 1, :b => 2}])
31
+ expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'application/xml'}, {:a => 1, :b => 2}])
32
32
 
33
33
  status, header, body = @xml.call({})
34
- lambda { Nokogiri.parse(body.first).search('a').inner_text.should == '1' }.should_not raise_error
34
+ expect { expect(Nokogiri.parse(body.first).search('a').inner_text).to eq('1') }.not_to raise_error
35
35
  end
36
36
 
37
37
  it 'generates arrays correctly' do
38
- @app.should_receive(:call).and_return([200, {'Content-Type' => 'application/xml'}, [1, 2]])
38
+ expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'application/xml'}, [1, 2]])
39
39
 
40
40
  status, header, body = @xml.call({})
41
- lambda {
41
+ expect {
42
42
  doc = Nokogiri.parse(body.first)
43
- doc.search('item').first.inner_text.should == '1'
44
- doc.search('item').last.inner_text.should == '2'
45
- }.should_not raise_error
43
+ expect(doc.search('item').first.inner_text).to eq('1')
44
+ expect(doc.search('item').last.inner_text).to eq('2')
45
+ }.not_to raise_error
46
46
  end
47
47
 
48
48
  it "doesn't format to xml if the type is not application/xml" do
49
- @app.should_receive(:call).and_return([200, {'Content-Type' => 'application/json'}, {:a => 1, :b => 2}])
49
+ expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'application/json'}, {:a => 1, :b => 2}])
50
50
 
51
- @xml.should_not_receive(:to_xml)
51
+ expect(@xml).not_to receive(:to_xml)
52
52
  status, header, body = @xml.call({})
53
- body[:a].should == 1
53
+ expect(body[:a]).to eq(1)
54
54
  end
55
55
 
56
56
  it 'returns the status and headers' do
57
- @app.should_receive(:call).and_return([200, {'Content-Type' => 'application/json'}, {:a => 1, :b => 2}])
57
+ expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'application/json'}, {:a => 1, :b => 2}])
58
58
 
59
- @xml.should_not_receive(:to_xml)
59
+ expect(@xml).not_to receive(:to_xml)
60
60
  status, header, body = @xml.call({})
61
- status.should == 200
62
- header.should == {'Content-Type' => 'application/json'}
61
+ expect(status).to eq(200)
62
+ expect(header).to eq({'Content-Type' => 'application/json'})
63
63
  end
64
64
  end
65
65
  end
@@ -3,7 +3,7 @@ require 'goliath/rack/formatters/yaml'
3
3
 
4
4
  describe Goliath::Rack::Formatters::YAML do
5
5
  it 'accepts an app' do
6
- lambda { Goliath::Rack::Formatters::YAML.new('my app') }.should_not raise_error
6
+ expect { Goliath::Rack::Formatters::YAML.new('my app') }.not_to raise_error
7
7
  end
8
8
 
9
9
  describe 'with a formatter' do
@@ -13,41 +13,41 @@ describe Goliath::Rack::Formatters::YAML do
13
13
  end
14
14
 
15
15
  it 'checks content type for text/yaml' do
16
- @ym.yaml_response?({'Content-Type' => 'text/yaml'}).should be_true
16
+ expect(@ym.yaml_response?({'Content-Type' => 'text/yaml'})).to be_truthy
17
17
  end
18
18
 
19
19
  it 'returns false for non-applicaton/yaml types' do
20
- @ym.yaml_response?({'Content-Type' => 'application/xml'}).should be_false
20
+ expect(@ym.yaml_response?({'Content-Type' => 'application/xml'})).to be_falsey
21
21
  end
22
22
 
23
23
  it 'calls the app with the provided environment' do
24
24
  env_mock = double('env').as_null_object
25
- @app.should_receive(:call).with(env_mock).and_return([200, {}, {"a" => 1}])
25
+ expect(@app).to receive(:call).with(env_mock).and_return([200, {}, {"a" => 1}])
26
26
  @ym.call(env_mock)
27
27
  end
28
28
 
29
29
  it 'formats the body into yaml if content-type is yaml' do
30
- @app.should_receive(:call).and_return([200, {'Content-Type' => 'text/yaml'}, {:a => 1, :b => 2}])
30
+ expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'text/yaml'}, {:a => 1, :b => 2}])
31
31
 
32
32
  status, header, body = @ym.call({})
33
- lambda { YAML.load(body.first)[:a].should == 1 }.should_not raise_error
33
+ expect { expect(YAML.load(body.first)[:a]).to eq(1) }.not_to raise_error
34
34
  end
35
35
 
36
36
  it "doesn't format to yaml if the type is not text/yaml" do
37
- @app.should_receive(:call).and_return([200, {'Content-Type' => 'application/xml'}, {:a => 1, :b => 2}])
37
+ expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'application/xml'}, {:a => 1, :b => 2}])
38
38
 
39
- YAML.should_not_receive(:encode)
39
+ expect(YAML).not_to receive(:encode)
40
40
  status, header, body = @ym.call({})
41
- body[:a].should == 1
41
+ expect(body[:a]).to eq(1)
42
42
  end
43
43
 
44
44
  it 'returns the status and headers' do
45
- @app.should_receive(:call).and_return([200, {'Content-Type' => 'application/xml'}, {:a => 1, :b => 2}])
45
+ expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'application/xml'}, {:a => 1, :b => 2}])
46
46
 
47
- YAML.should_not_receive(:encode)
47
+ expect(YAML).not_to receive(:encode)
48
48
  status, header, body = @ym.call({})
49
- status.should == 200
50
- header.should == {'Content-Type' => 'application/xml'}
49
+ expect(status).to eq(200)
50
+ expect(header).to eq({'Content-Type' => 'application/xml'})
51
51
  end
52
52
  end
53
53
  end
@@ -4,7 +4,7 @@ require 'goliath/env'
4
4
 
5
5
  describe Goliath::Rack::Heartbeat do
6
6
  it 'accepts an app' do
7
- lambda { Goliath::Rack::Heartbeat.new('my app') }.should_not raise_error
7
+ expect { Goliath::Rack::Heartbeat.new('my app') }.not_to raise_error
8
8
  end
9
9
 
10
10
  describe 'with the middleware' do
@@ -16,54 +16,54 @@ describe Goliath::Rack::Heartbeat do
16
16
  end
17
17
 
18
18
  it 'allows /status as a path prefix' do
19
- @app.should_receive(:call)
19
+ expect(@app).to receive(:call)
20
20
  @env['PATH_INFO'] = '/status_endpoint'
21
21
  @hb.call(@env)
22
22
  end
23
23
 
24
24
  it "doesn't call the app when request /status" do
25
- @app.should_not_receive(:call)
25
+ expect(@app).not_to receive(:call)
26
26
  @env['PATH_INFO'] = '/status'
27
27
  @hb.call(@env)
28
28
  end
29
29
 
30
30
  it 'returns the status, headers and body from the app on non-/status' do
31
31
  @env['PATH_INFO'] = '/v1'
32
- @app.should_receive(:call).and_return([200, {'a' => 'b'}, {'c' => 'd'}])
32
+ expect(@app).to receive(:call).and_return([200, {'a' => 'b'}, {'c' => 'd'}])
33
33
  status, headers, body = @hb.call(@env)
34
- status.should == 200
35
- headers.should == {'a' => 'b'}
36
- body.should == {'c' => 'd'}
34
+ expect(status).to eq(200)
35
+ expect(headers).to eq({'a' => 'b'})
36
+ expect(body).to eq({'c' => 'd'})
37
37
  end
38
38
 
39
39
  it 'returns the correct status, headers and body on /status' do
40
40
  @env['PATH_INFO'] = '/status'
41
41
  status, headers, body = @hb.call(@env)
42
- status.should == 200
43
- headers.should == {}
44
- body.should == 'OK'
42
+ expect(status).to eq(200)
43
+ expect(headers).to eq({})
44
+ expect(body).to eq('OK')
45
45
  end
46
46
 
47
47
  it 'allows path and response to be set using options' do
48
48
  @hb = Goliath::Rack::Heartbeat.new(@app, :path => '/isup', :response => [204, {}, nil])
49
49
  @env['PATH_INFO'] = '/isup'
50
50
  status, headers, body = @hb.call(@env)
51
- status.should == 204
52
- headers.should == {}
53
- body.should == nil
51
+ expect(status).to eq(204)
52
+ expect(headers).to eq({})
53
+ expect(body).to eq(nil)
54
54
  end
55
55
 
56
56
  it 'does not log the request by default' do
57
57
  @env['PATH_INFO'] = '/status'
58
58
  @hb.call(@env)
59
- @env[Goliath::Constants::RACK_LOGGER].should == Log4r::Logger.root
59
+ expect(@env[Goliath::Constants::RACK_LOGGER]).to eq(Log4r::Logger.root)
60
60
  end
61
61
 
62
62
  it 'logs the request only if asked' do
63
63
  @env['PATH_INFO'] = '/status'
64
64
  @hb = Goliath::Rack::Heartbeat.new(@app, :log => true)
65
65
  @hb.call(@env)
66
- @env[Goliath::Constants::RACK_LOGGER].should_not == Log4r::Logger.root
66
+ expect(@env[Goliath::Constants::RACK_LOGGER]).not_to eq(Log4r::Logger.root)
67
67
  end
68
68
  end
69
69
  end