mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
set with block and value raises ArgumentError
This commit is contained in:
parent
0915274b69
commit
30c2ef8396
2 changed files with 7 additions and 6 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue