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

@ -680,6 +680,7 @@ 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)
raise ArgumentError if block && value != self
value = block if block
if value.kind_of?(Proc)
metadef(option, &value)

View File

@ -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