From 67159582cba6df215786c3557152a4d9d2faf1f8 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Fri, 27 May 2011 10:26:19 +0200 Subject: [PATCH] raise ArgumentError, not TypeError for an invalid etag strength --- lib/sinatra/base.rb | 4 ++-- test/helpers_test.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) 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