mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-04 00:02:03 -04:00
raise ArgumentError if Faraday::Options.memoized is called w/o a block
This commit is contained in:
parent
5063ffe963
commit
342c2e4eb8
@ -172,6 +172,9 @@ module Faraday
|
||||
end
|
||||
|
||||
def self.memoized(key)
|
||||
if !block_given?
|
||||
raise ArgumentError, "#memoized must be called with a block"
|
||||
end
|
||||
memoized_attributes[key.to_sym] = Proc.new
|
||||
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
||||
def #{key}() self[:#{key}]; end
|
||||
|
@ -250,6 +250,20 @@ RSpec.describe Faraday::Options do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#memoized' do
|
||||
subject(:options_class) { Class.new(ParentOptions) }
|
||||
it 'requires block' do
|
||||
expect {
|
||||
options_class.memoized(:a)
|
||||
}.to raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it 'accepts block' do
|
||||
options_class.memoized(:a) { :foo }
|
||||
expect(options_class.new.a).to eql(:foo)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#fetch' do
|
||||
subject { SubOptions.new }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user