/
exceptions_test.rb
36 lines (28 loc) · 949 Bytes
/
exceptions_test.rb
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
require 'test_helper'
class ExceptionsTest < Minitest::Test
include Rack::Test::Methods
include Rack::GridFS::Test::Methods
context "Rack::GridFS Exceptions" do
setup do
def app
setup_middleware(:lookup => :path)
end
@text_file = load_artifact('test.txt', nil)
@html_file = load_artifact('test.html', nil)
end
teardown do
db.collection('fs.files').remove
end
should "return a 500 if an error occurs" do
Rack::GridFS::Endpoint.any_instance.stubs(:find_file).raises(Mongo::GridError)
get "/gridfs/anything"
assert_equal 500, last_response.status
end
should "retry on connection failure" do
gridfile = Mongo::GridFileSystem.new(db).open("test.txt", "r")
Rack::GridFS::Endpoint.any_instance.stubs(:find_file).raises(Mongo::ConnectionFailure).then.returns(gridfile)
get "/gridfs/test.txt"
assert last_response.ok?
end
end
end