diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index dab8af84..29038eaf 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -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 diff --git a/test/helpers_test.rb b/test/helpers_test.rb index 8fa583da..667e4fa9 100644 --- a/test/helpers_test.rb +++ b/test/helpers_test.rb @@ -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