goliath 1.0.5 → 1.0.7

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 (57) hide show
  1. checksums.yaml +5 -5
  2. data/examples/rasterize/rasterize.rb +1 -1
  3. data/goliath.gemspec +1 -0
  4. data/lib/goliath/connection.rb +16 -12
  5. data/lib/goliath/constants.rb +1 -0
  6. data/lib/goliath/rack/default_response_format.rb +3 -9
  7. data/lib/goliath/rack/formatters/json.rb +1 -1
  8. data/lib/goliath/rack/params.rb +1 -1
  9. data/lib/goliath/rack/templates.rb +1 -1
  10. data/lib/goliath/request.rb +35 -18
  11. data/lib/goliath/response.rb +3 -1
  12. data/lib/goliath/server.rb +1 -1
  13. data/lib/goliath/version.rb +1 -1
  14. data/spec/integration/async_request_processing.rb +2 -2
  15. data/spec/integration/chunked_streaming_spec.rb +1 -1
  16. data/spec/integration/early_abort_spec.rb +5 -5
  17. data/spec/integration/echo_spec.rb +7 -7
  18. data/spec/integration/empty_body_spec.rb +2 -2
  19. data/spec/integration/event_stream_spec.rb +3 -3
  20. data/spec/integration/exception_handling_spec.rb +16 -16
  21. data/spec/integration/http_log_spec.rb +16 -16
  22. data/spec/integration/jsonp_spec.rb +6 -6
  23. data/spec/integration/keepalive_spec.rb +2 -2
  24. data/spec/integration/pipelining_spec.rb +3 -3
  25. data/spec/integration/reloader_spec.rb +3 -3
  26. data/spec/integration/template_spec.rb +7 -7
  27. data/spec/integration/test_helper_spec.rb +3 -3
  28. data/spec/integration/trace_spec.rb +2 -2
  29. data/spec/integration/valid_spec.rb +8 -8
  30. data/spec/integration/websocket_spec.rb +2 -2
  31. data/spec/spec_helper.rb +1 -3
  32. data/spec/unit/api_spec.rb +1 -1
  33. data/spec/unit/connection_spec.rb +8 -8
  34. data/spec/unit/console_spec.rb +3 -3
  35. data/spec/unit/env_spec.rb +9 -9
  36. data/spec/unit/headers_spec.rb +8 -8
  37. data/spec/unit/rack/default_mime_type_spec.rb +3 -3
  38. data/spec/unit/rack/formatters/json_spec.rb +35 -13
  39. data/spec/unit/rack/formatters/plist_spec.rb +8 -8
  40. data/spec/unit/rack/formatters/xml_spec.rb +18 -18
  41. data/spec/unit/rack/formatters/yaml_spec.rb +13 -13
  42. data/spec/unit/rack/heartbeat_spec.rb +15 -15
  43. data/spec/unit/rack/params_spec.rb +62 -60
  44. data/spec/unit/rack/render_spec.rb +14 -14
  45. data/spec/unit/rack/validation/boolean_value_spec.rb +6 -6
  46. data/spec/unit/rack/validation/default_params_spec.rb +13 -13
  47. data/spec/unit/rack/validation/numeric_range_spec.rb +17 -17
  48. data/spec/unit/rack/validation/param_spec.rb +75 -75
  49. data/spec/unit/rack/validation/request_method_spec.rb +9 -9
  50. data/spec/unit/rack/validation/required_param_spec.rb +28 -28
  51. data/spec/unit/rack/validation/required_value_spec.rb +19 -19
  52. data/spec/unit/request_spec.rb +18 -18
  53. data/spec/unit/response_spec.rb +6 -6
  54. data/spec/unit/runner_spec.rb +31 -31
  55. data/spec/unit/server_spec.rb +21 -21
  56. data/spec/unit/validation/standard_http_errors_spec.rb +6 -6
  57. metadata +20 -7
@@ -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'].should == 'test'
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'].should == 'test2'
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.should match('0.3')
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.should == ['0.3', '0.2']
35
- (Time.now.to_f - start).should be_within(0.1).of(0.3)
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).should == 1
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).should == 1
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).should == 0
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.should =~ %r{<li><a href="/joke">Tell me a joke</a></li>}
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.should =~ %r{<h1>Header</h1>}
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.should =~ %r{<code>Arr, I dunno matey -- but it is driving me nuts!\s*</code>}m
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.should =~ %r{I AM ERB</h1>}m
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.should =~ %r{<title>HERE IS A JOKE</title>}m
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.should =~ %r{^\[:error, "Template no_such_template not found in .*examples/views for haml"\]$}
56
- c.response_header.status.should == 500
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").should be_truthy
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}.should_not be_empty
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.should == Log4r::DEBUG
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'].should =~ /trace\.start: [\d\.]+, total: [\d\.]+/
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'].should =~ /trace\.start: [\d\.]+, total: [\d\.]+/
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.should == 'OK'
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.should == '[:error, "test identifier missing"]'
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.should == '[:error, "You Must Chill"]'
68
- c.response_header.status.should == 420
69
- c.response_header["Foo"].should == 'Bar'
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.should == '[:error, "You Must Chill"]'
88
- c.response_header.status.should == 420
89
- c.response_header["Foo"].should == 'Bar'
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.any_instance.should_receive(:on_open)
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.should == "hello"
38
+ expect(client.receive.data).to eq("hello")
39
39
  end
40
40
  end
41
41
  end
data/spec/spec_helper.rb CHANGED
@@ -8,7 +8,5 @@ require 'goliath/test_helper'
8
8
  Goliath.env = :test
9
9
 
10
10
  RSpec.configure do |c|
11
- c.include Goliath::TestHelper, :example_group => {
12
- :file_path => /spec\/integration/
13
- }
11
+ c.include Goliath::TestHelper, :file_path => /spec\/integration/
14
12
  end
@@ -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.middlewares.size.should eq(2) }
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_truthy
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_falsey
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