Skip to content

Commit

Permalink
Deprecate Twitter::Base#[]
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Apr 6, 2014
1 parent 8552636 commit 2ab6c0d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/twitter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def initialize(attrs = {})
#
# @param method [String, Symbol] Message to send to the object
def [](method)
warn "#{Kernel.caller.first}: [DEPRECATION] #[#{method.inspect}] is deprecated. Use ##{method} to fetch the value."
send(method.to_sym)
rescue NoMethodError
nil
Expand Down
20 changes: 16 additions & 4 deletions spec/twitter/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,26 @@

describe '#[]' do
it 'calls methods using [] with symbol' do
expect(@base[:object_id]).to be_an Integer
capture_warning do
expect(@base[:object_id]).to be_an Integer
end
end
it 'calls methods using [] with string' do
expect(@base['object_id']).to be_an Integer
capture_warning do
expect(@base['object_id']).to be_an Integer
end
end
it 'returns nil for missing method' do
expect(@base[:foo]).to be_nil
expect(@base['foo']).to be_nil
capture_warning do
expect(@base[:foo]).to be_nil
expect(@base['foo']).to be_nil
end
end
it 'outputs a warning' do
warning = capture_warning do
@base[:object_id]
end
expect(warning).to match(/\[DEPRECATION\] #\[:object_id\] is deprecated. Use #object_id to fetch the value./)
end
end

Expand Down

0 comments on commit 2ab6c0d

Please sign in to comment.