Skip to content

Commit

Permalink
set with block and value raises ArgumentError
Browse files Browse the repository at this point in the history
  • Loading branch information
rtomayko committed Feb 5, 2010
1 parent 0915274 commit 30c2ef8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,8 @@ def middleware

# 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)
Expand Down
10 changes: 5 additions & 5 deletions test/settings_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 30c2ef8

Please sign in to comment.