set with block and value raises ArgumentError

This commit is contained in:
Ryan Tomayko 2010-02-05 13:45:52 -08:00
parent 0915274b69
commit 30c2ef8396
2 changed files with 7 additions and 6 deletions

View File

@ -679,7 +679,8 @@ module Sinatra
# Sets an option to the given value. If the value is a proc, # Sets an option to the given value. If the value is a proc,
# the proc will be called every time the option is accessed. # 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 value = block if block
if value.kind_of?(Proc) if value.kind_of?(Proc)
metadef(option, &value) metadef(option, &value)

View File

@ -27,11 +27,11 @@ class SettingsTest < Test::Unit::TestCase
assert_equal 'baz', @base.foo assert_equal 'baz', @base.foo
end end
# TODO: should it raise an error instead? it 'raises an error with a value and a block' do
it 'ignores any other value if set using a block' do assert_raise ArgumentError do
@base.set(:foo, 'ignore'){ 'baz' } @base.set(:fiz, 'boom!'){ 'baz' }
assert @base.respond_to?(:foo) end
assert_equal 'baz', @base.foo assert !@base.respond_to?(:fiz)
end end
it "sets multiple settings with a Hash" do it "sets multiple settings with a Hash" do