Skip to content

Commit

Permalink
Enforce code coverage minimums
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Jun 24, 2014
1 parent d96194c commit 005259c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 deletions.
2 changes: 0 additions & 2 deletions lib/twitter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ def define_attribute_method(key1, klass = nil, key2 = nil)
memoize(key1)
end

# Dynamically define a method for an attribute
#
# @param key [Symbol]
def deprecate_attribute_method(key)
define_method(key) do ||
Expand Down
8 changes: 2 additions & 6 deletions lib/twitter/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ def included(base)
end

module ClassMethods
def deprecate_alias(new_name, old_name)
def deprecate_alias(new_name, old_name, &block)
define_method(new_name) do |*args|
warn "#{Kernel.caller.first}: [DEPRECATION] ##{new_name} is deprecated. Use ##{old_name} instead."
if block_given?
send(old_name, *args, &Proc.new)
else
send(old_name, *args)
end
send(old_name, *args, &block)
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions spec/helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
require 'simplecov'
require 'coveralls'

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter]

SimpleCov.start do
add_filter '/spec/'
minimum_coverage(99.63)
end

require 'twitter'
require 'rspec'
require 'stringio'
Expand Down
33 changes: 33 additions & 0 deletions spec/twitter/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,43 @@
end
end

describe '#[]' do
it 'calls methods using [] with symbol' do
capture_warning do
expect(@base[:object_id]).to be_an Integer
end
end
it 'calls methods using [] with string' do
capture_warning do
expect(@base['object_id']).to be_an Integer
end
end
it 'returns nil for missing method' do
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

describe '#attrs' do
it 'returns a hash of attributes' do
expect(@base.attrs).to eq(:id => 1)
end
end

describe '#to_hash' do
it 'outputs a warning' do
warning = capture_warning do
expect(@base.to_hash).to eq(:id => 1)
end
expect(warning).to match(/\[DEPRECATION\] #to_hash is deprecated\. Use #to_h instead\./)
end
end
end
10 changes: 10 additions & 0 deletions spec/twitter/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,16 @@
end
end

describe '#verified' do
it 'outputs a warning' do
user = Twitter::User.new(:id => 7_505_382, :verified => true)
warning = capture_warning do
expect(user.verified).to be true
end
expect(warning).to match(/\[DEPRECATION\] #verified is deprecated\. Use #verified\? instead\./)
end
end

describe '#website' do
it 'returns a URI when the url is set' do
user = Twitter::User.new(:id => 7_505_382, :url => 'https://github.com/sferik')
Expand Down

0 comments on commit 005259c

Please sign in to comment.