raise ArgumentError, not TypeError for an invalid etag strength

This commit is contained in:
Konstantin Haase 2011-05-27 10:26:19 +02:00
parent 8d6a1b35bb
commit 67159582cb
2 changed files with 12 additions and 2 deletions

View File

@ -288,8 +288,8 @@ module Sinatra
# When the current request includes an 'If-None-Match' header with a
# matching etag, execution is immediately halted. If the request method is
# GET or HEAD, a '304 Not Modified' response is sent.
def etag(value, kind=:strong)
raise TypeError, ":strong or :weak expected" if ![:strong,:weak].include?(kind)
def etag(value, kind = :strong)
raise ArgumentError, ":strong or :weak expected" unless [:strong,:weak].include?(kind)
value = '"%s"' % value
value = 'W/' + value if kind == :weak
response['ETag'] = value

View File

@ -852,6 +852,16 @@ class HelpersTest < Test::Unit::TestCase
get '/'
assert_equal 'W/"FOO"', response['ETag']
end
it 'raises an ArgumentError for an invalid strength' do
mock_app do
get '/' do
etag 'FOO', :w00t
"that's weak, dude."
end
end
assert_raise(ArgumentError) { get '/' }
end
end
describe 'back' do