diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index bd9a4a51..6c1f9421 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -679,7 +679,8 @@ module Sinatra # Sets an option to the given value. If the value is a proc, # the proc will be called every time the option is accessed. - def set(option, value=self, &block) + def set(option, value=self, &block) + raise ArgumentError if block && value != self value = block if block if value.kind_of?(Proc) metadef(option, &value) diff --git a/test/settings_test.rb b/test/settings_test.rb index 482fc614..bfb2bbd0 100644 --- a/test/settings_test.rb +++ b/test/settings_test.rb @@ -27,11 +27,11 @@ class SettingsTest < Test::Unit::TestCase assert_equal 'baz', @base.foo end - # TODO: should it raise an error instead? - it 'ignores any other value if set using a block' do - @base.set(:foo, 'ignore'){ 'baz' } - assert @base.respond_to?(:foo) - assert_equal 'baz', @base.foo + it 'raises an error with a value and a block' do + assert_raise ArgumentError do + @base.set(:fiz, 'boom!'){ 'baz' } + end + assert !@base.respond_to?(:fiz) end it "sets multiple settings with a Hash" do