Skip to content

Commit

Permalink
Missing key raises now KeyError, not ArgumentError
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Sep 24, 2013
1 parent 3e3b234 commit f56698c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
10 changes: 3 additions & 7 deletions lib/twitter/creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ module Twitter
class Creator

def self.new(method, klass, attrs={})
type = attrs.delete(method.to_sym)
if type
const_name = type.gsub(/\/(.?)/){"::#{$1.upcase}"}.gsub(/(?:^|_)(.)/){$1.upcase}
klass.const_get(const_name.to_sym).new(attrs)
else
raise ArgumentError, "argument must have :#{method} key"
end
type = attrs.fetch(method.to_sym)
const_name = type.gsub(/\/(.?)/){"::#{$1.upcase}"}.gsub(/(?:^|_)(.)/){$1.upcase}
klass.const_get(const_name.to_sym).new(attrs)
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/identity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class Identity < Twitter::Base
# @raise [ArgumentError] Error raised when supplied argument is missing an :id key.
# @return [Twitter::Identity]
def initialize(attrs={})
attrs.fetch(:id)
super
raise ArgumentError, "argument must have an :id key" unless id
end

end
Expand Down
4 changes: 2 additions & 2 deletions spec/twitter/geo_creator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
geo = Twitter::GeoCreator.new(:type => "Polygon")
expect(geo).to be_a Twitter::Geo::Polygon
end
it "raises an ArgumentError when type is not specified" do
expect{Twitter::GeoCreator.new}.to raise_error ArgumentError
it "raises a KeyError when type is not specified" do
expect{Twitter::GeoCreator.new}.to raise_error KeyError
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/twitter/identifiable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
describe Twitter::Identity do

describe "#initialize" do
it "raises an ArgumentError when type is not specified" do
expect{Twitter::Identity.new}.to raise_error ArgumentError
it "raises a KeyError when id is not specified" do
expect{Twitter::Identity.new}.to raise_error KeyError
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/twitter/media_creator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
media = Twitter::MediaCreator.new(:id => 1, :type => "photo")
expect(media).to be_a Twitter::Media::Photo
end
it "raises an ArgumentError when type is not specified" do
expect{Twitter::MediaCreator.new}.to raise_error ArgumentError
it "raises a KeyError when type is not specified" do
expect{Twitter::MediaCreator.new}.to raise_error KeyError
end
end

Expand Down

0 comments on commit f56698c

Please sign in to comment.