Skip to content

Commit

Permalink
Use described_class
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Feb 4, 2023
1 parent ac502be commit d97d3f1
Show file tree
Hide file tree
Showing 47 changed files with 480 additions and 464 deletions.
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0.5
2 changes: 1 addition & 1 deletion spec/twitter/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe Twitter::Base do
before do
@base = Twitter::Base.new(id: 1)
@base = described_class.new(id: 1)
end

describe '#[]' do
Expand Down
10 changes: 5 additions & 5 deletions spec/twitter/basic_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
describe Twitter::BasicUser do
describe '#==' do
it 'returns true when objects IDs are the same' do
saved_search = Twitter::BasicUser.new(id: 1, name: 'foo')
other = Twitter::BasicUser.new(id: 1, name: 'bar')
saved_search = described_class.new(id: 1, name: 'foo')
other = described_class.new(id: 1, name: 'bar')
expect(saved_search == other).to be true
end
it 'returns false when objects IDs are different' do
saved_search = Twitter::BasicUser.new(id: 1)
other = Twitter::BasicUser.new(id: 2)
saved_search = described_class.new(id: 1)
other = described_class.new(id: 2)
expect(saved_search == other).to be false
end
it 'returns false when classes are different' do
saved_search = Twitter::BasicUser.new(id: 1)
saved_search = described_class.new(id: 1)
other = Twitter::Identity.new(id: 1)
expect(saved_search == other).to be false
end
Expand Down
15 changes: 15 additions & 0 deletions spec/twitter/configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'helper'

describe Twitter::Configuration do
describe '#photo_sizes' do
it 'returns a hash of sizes when photo_sizes is set' do
photo_sizes = described_class.new(photo_sizes: {small: {h: 226, w: 340, resize: 'fit'}, large: {h: 466, w: 700, resize: 'fit'}, medium: {h: 399, w: 600, resize: 'fit'}, thumb: {h: 150, w: 150, resize: 'crop'}}).photo_sizes
expect(photo_sizes).to be_a Hash
expect(photo_sizes[:small]).to be_a Twitter::Size
end
it 'is empty when photo_sizes is not set' do
photo_sizes = described_class.new.photo_sizes
expect(photo_sizes).to be_empty
end
end
end
62 changes: 31 additions & 31 deletions spec/twitter/direct_message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,41 @@

describe '#==' do
it 'returns true when objects IDs are the same' do
direct_message = Twitter::DirectMessage.new(id: 1, text: 'foo')
other = Twitter::DirectMessage.new(id: 1, text: 'bar')
direct_message = described_class.new(id: 1, text: 'foo')
other = described_class.new(id: 1, text: 'bar')
expect(direct_message == other).to be true
end
it 'returns false when objects IDs are different' do
direct_message = Twitter::DirectMessage.new(id: 1)
other = Twitter::DirectMessage.new(id: 2)
direct_message = described_class.new(id: 1)
other = described_class.new(id: 2)
expect(direct_message == other).to be false
end
it 'returns false when classes are different' do
direct_message = Twitter::DirectMessage.new(id: 1)
direct_message = described_class.new(id: 1)
other = Twitter::Identity.new(id: 1)
expect(direct_message == other).to be false
end
end

describe '#created_at' do
it 'returns a Time when created_at is set' do
direct_message = Twitter::DirectMessage.new(id: 1_825_786_345, created_at: 'Mon Jul 16 12:59:01 +0000 2007')
direct_message = described_class.new(id: 1_825_786_345, created_at: 'Mon Jul 16 12:59:01 +0000 2007')
expect(direct_message.created_at).to be_a Time
expect(direct_message.created_at).to be_utc
end
it 'returns nil when created_at is not set' do
direct_message = Twitter::DirectMessage.new(id: 1_825_786_345)
direct_message = described_class.new(id: 1_825_786_345)
expect(direct_message.created_at).to be_nil
end
end

describe '#created?' do
it 'returns true when created_at is set' do
direct_message = Twitter::DirectMessage.new(id: 1_825_786_345, created_at: 'Mon Jul 16 12:59:01 +0000 2007')
direct_message = described_class.new(id: 1_825_786_345, created_at: 'Mon Jul 16 12:59:01 +0000 2007')
expect(direct_message.created?).to be true
end
it 'returns false when created_at is not set' do
direct_message = Twitter::DirectMessage.new(id: 1_825_786_345)
direct_message = described_class.new(id: 1_825_786_345)
expect(direct_message.created?).to be false
end
end
Expand All @@ -61,59 +61,59 @@
indices: [10, 33],
},
]
tweet = Twitter::DirectMessage.new(id: 1_825_786_345, entities: {urls: urls_array})
tweet = described_class.new(id: 1_825_786_345, entities: {urls: urls_array})
expect(tweet.entities?).to be true
end
it 'returns false if there are blank lists of entities set' do
tweet = Twitter::DirectMessage.new(id: 1_825_786_345, entities: {urls: []})
tweet = described_class.new(id: 1_825_786_345, entities: {urls: []})
expect(tweet.entities?).to be false
end
it 'returns false if there are no entities set' do
tweet = Twitter::DirectMessage.new(id: 1_825_786_345)
tweet = described_class.new(id: 1_825_786_345)
expect(tweet.entities?).to be false
end
end

describe '#recipient' do
it 'returns a User when recipient is set' do
direct_message = Twitter::DirectMessage.new(id: 1_825_786_345, recipient: {id: 7_505_382})
direct_message = described_class.new(id: 1_825_786_345, recipient: {id: 7_505_382})
expect(direct_message.recipient).to be_a Twitter::User
end
it 'returns nil when recipient is not set' do
direct_message = Twitter::DirectMessage.new(id: 1_825_786_345)
direct_message = described_class.new(id: 1_825_786_345)
expect(direct_message.recipient).to be_nil
end
end

describe '#recipient?' do
it 'returns true when recipient is set' do
direct_message = Twitter::DirectMessage.new(id: 1_825_786_345, recipient: {id: 7_505_382})
direct_message = described_class.new(id: 1_825_786_345, recipient: {id: 7_505_382})
expect(direct_message.recipient?).to be true
end
it 'returns false when recipient is not set' do
direct_message = Twitter::DirectMessage.new(id: 1_825_786_345)
direct_message = described_class.new(id: 1_825_786_345)
expect(direct_message.recipient?).to be false
end
end

describe '#sender' do
it 'returns a User when sender is set' do
direct_message = Twitter::DirectMessage.new(id: 1_825_786_345, sender: {id: 7_505_382})
direct_message = described_class.new(id: 1_825_786_345, sender: {id: 7_505_382})
expect(direct_message.sender).to be_a Twitter::User
end
it 'returns nil when sender is not set' do
direct_message = Twitter::DirectMessage.new(id: 1_825_786_345)
direct_message = described_class.new(id: 1_825_786_345)
expect(direct_message.sender).to be_nil
end
end

describe '#sender?' do
it 'returns true when sender is set' do
direct_message = Twitter::DirectMessage.new(id: 1_825_786_345, sender: {id: 7_505_382})
direct_message = described_class.new(id: 1_825_786_345, sender: {id: 7_505_382})
expect(direct_message.sender?).to be true
end
it 'returns false when sender is not set' do
direct_message = Twitter::DirectMessage.new(id: 1_825_786_345)
direct_message = described_class.new(id: 1_825_786_345)
expect(direct_message.sender?).to be false
end
end
Expand All @@ -126,26 +126,26 @@
indices: [10, 33],
},
]
hashtags = Twitter::DirectMessage.new(id: 1_825_786_345, entities: {hashtags: hashtags_array}).hashtags
hashtags = described_class.new(id: 1_825_786_345, entities: {hashtags: hashtags_array}).hashtags
expect(hashtags).to be_an Array
expect(hashtags.first).to be_a Twitter::Entity::Hashtag
expect(hashtags.first.indices).to eq([10, 33])
expect(hashtags.first.text).to eq('twitter')
end
it 'is empty when not set' do
hashtags = Twitter::DirectMessage.new(id: 1_825_786_345).hashtags
hashtags = described_class.new(id: 1_825_786_345).hashtags
expect(hashtags).to be_empty
end
end

describe '#media' do
it 'returns media' do
media = Twitter::DirectMessage.new(id: 1_825_786_345, entities: {media: [{id: 1, type: 'photo'}]}).media
media = described_class.new(id: 1_825_786_345, entities: {media: [{id: 1, type: 'photo'}]}).media
expect(media).to be_an Array
expect(media.first).to be_a Twitter::Media::Photo
end
it 'is empty when not set' do
media = Twitter::DirectMessage.new(id: 1_825_786_345).media
media = described_class.new(id: 1_825_786_345).media
expect(media).to be_empty
end
end
Expand All @@ -156,15 +156,15 @@
{text: 'PEP', indices: [114, 118]},
{text: 'COKE', indices: [128, 133]},
]
symbols = Twitter::DirectMessage.new(id: 1_825_786_345, entities: {symbols: symbols_array}).symbols
symbols = described_class.new(id: 1_825_786_345, entities: {symbols: symbols_array}).symbols
expect(symbols).to be_an Array
expect(symbols.size).to eq(2)
expect(symbols.first).to be_a Twitter::Entity::Symbol
expect(symbols.first.indices).to eq([114, 118])
expect(symbols.first.text).to eq('PEP')
end
it 'is empty when not set' do
symbols = Twitter::DirectMessage.new(id: 1_825_786_345).symbols
symbols = described_class.new(id: 1_825_786_345).symbols
expect(symbols).to be_empty
end
end
Expand All @@ -179,15 +179,15 @@
indices: [10, 33],
},
]
direct_message = Twitter::DirectMessage.new(id: 1_825_786_345, entities: {urls: urls_array})
direct_message = described_class.new(id: 1_825_786_345, entities: {urls: urls_array})
expect(direct_message.uris).to be_an Array
expect(direct_message.uris.first).to be_a Twitter::Entity::URI
expect(direct_message.uris.first.indices).to eq([10, 33])
expect(direct_message.uris.first.display_uri).to be_a String
expect(direct_message.uris.first.display_uri).to eq('example.com/expanded...')
end
it 'is empty when not set' do
direct_message = Twitter::DirectMessage.new(id: 1_825_786_345)
direct_message = described_class.new(id: 1_825_786_345)
expect(direct_message.uris).to be_empty
end
it 'can handle strange urls' do
Expand All @@ -199,7 +199,7 @@
indices: [10, 33],
},
]
direct_message = Twitter::DirectMessage.new(id: 1_825_786_345, entities: {urls: urls_array})
direct_message = described_class.new(id: 1_825_786_345, entities: {urls: urls_array})
uri = direct_message.uris.first
expect { uri.url }.not_to raise_error
expect { uri.expanded_url }.not_to raise_error
Expand All @@ -218,14 +218,14 @@
id: 7_505_382,
},
]
user_mentions = Twitter::DirectMessage.new(id: 1_825_786_345, entities: {user_mentions: user_mentions_array}).user_mentions
user_mentions = described_class.new(id: 1_825_786_345, entities: {user_mentions: user_mentions_array}).user_mentions
expect(user_mentions).to be_an Array
expect(user_mentions.first).to be_a Twitter::Entity::UserMention
expect(user_mentions.first.indices).to eq([0, 6])
expect(user_mentions.first.id).to eq(7_505_382)
end
it 'is empty when not set' do
user_mentions = Twitter::DirectMessage.new(id: 1_825_786_345).user_mentions
user_mentions = described_class.new(id: 1_825_786_345).user_mentions
expect(user_mentions).to be_empty
end
end
Expand Down
24 changes: 12 additions & 12 deletions spec/twitter/entity/uri_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,69 @@
describe Twitter::Entity::URI do
describe '#display_uri' do
it 'returns a String when the display_url is set' do
uri = Twitter::Entity::URI.new(display_url: 'example.com/expanded...')
uri = described_class.new(display_url: 'example.com/expanded...')
expect(uri.display_uri).to be_a String
expect(uri.display_uri).to eq('example.com/expanded...')
end
it 'returns nil when the display_url is not set' do
uri = Twitter::Entity::URI.new
uri = described_class.new
expect(uri.display_uri).to be_nil
end
end

describe '#display_uri?' do
it 'returns true when the display_url is set' do
uri = Twitter::Entity::URI.new(display_url: 'example.com/expanded...')
uri = described_class.new(display_url: 'example.com/expanded...')
expect(uri.display_uri?).to be true
end
it 'returns false when the display_url is not set' do
uri = Twitter::Entity::URI.new
uri = described_class.new
expect(uri.display_uri?).to be false
end
end

describe '#expanded_uri' do
it 'returns a URI when the expanded_url is set' do
uri = Twitter::Entity::URI.new(expanded_url: 'https://github.com/sferik')
uri = described_class.new(expanded_url: 'https://github.com/sferik')
expect(uri.expanded_uri).to be_an Addressable::URI
expect(uri.expanded_uri.to_s).to eq('https://github.com/sferik')
end
it 'returns nil when the expanded_url is not set' do
uri = Twitter::Entity::URI.new
uri = described_class.new
expect(uri.expanded_uri).to be_nil
end
end

describe '#expanded_uri?' do
it 'returns true when the expanded_url is set' do
uri = Twitter::Entity::URI.new(expanded_url: 'https://github.com/sferik')
uri = described_class.new(expanded_url: 'https://github.com/sferik')
expect(uri.expanded_uri?).to be true
end
it 'returns false when the expanded_url is not set' do
uri = Twitter::Entity::URI.new
uri = described_class.new
expect(uri.expanded_uri?).to be false
end
end

describe '#uri' do
it 'returns a URI when the url is set' do
uri = Twitter::Entity::URI.new(url: 'https://github.com/sferik')
uri = described_class.new(url: 'https://github.com/sferik')
expect(uri.uri).to be_an Addressable::URI
expect(uri.uri.to_s).to eq('https://github.com/sferik')
end
it 'returns nil when the url is not set' do
uri = Twitter::Entity::URI.new
uri = described_class.new
expect(uri.uri).to be_nil
end
end

describe '#uri?' do
it 'returns true when the url is set' do
uri = Twitter::Entity::URI.new(url: 'https://github.com/sferik')
uri = described_class.new(url: 'https://github.com/sferik')
expect(uri.uri?).to be true
end
it 'returns false when the url is not set' do
uri = Twitter::Entity::URI.new
uri = described_class.new
expect(uri.uri?).to be false
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/twitter/error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@

describe '#code' do
it 'returns the error code' do
error = Twitter::Error.new('execution expired', {}, 123)
error = described_class.new('execution expired', {}, 123)
expect(error.code).to eq(123)
end
end

describe '#message' do
it 'returns the error message' do
error = Twitter::Error.new('execution expired')
error = described_class.new('execution expired')
expect(error.message).to eq('execution expired')
end
end

describe '#rate_limit' do
it 'returns a rate limit object' do
error = Twitter::Error.new('execution expired')
error = described_class.new('execution expired')
expect(error.rate_limit).to be_a Twitter::RateLimit
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/twitter/geo/point_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

describe Twitter::Geo::Point do
before do
@point = Twitter::Geo::Point.new(coordinates: [-122.399983, 37.788299])
@point = described_class.new(coordinates: [-122.399983, 37.788299])
end

describe '#==' do
it 'returns true for empty objects' do
point = Twitter::Geo::Point.new
other = Twitter::Geo::Point.new
point = described_class.new
other = described_class.new
expect(point == other).to be true
end
it 'returns true when objects coordinates are the same' do
other = Twitter::Geo::Point.new(coordinates: [-122.399983, 37.788299])
other = described_class.new(coordinates: [-122.399983, 37.788299])
expect(@point == other).to be true
end
it 'returns false when objects coordinates are different' do
other = Twitter::Geo::Point.new(coordinates: [37.788299, -122.399983])
other = described_class.new(coordinates: [37.788299, -122.399983])
expect(@point == other).to be false
end
it 'returns false when classes are different' do
Expand Down
Loading

0 comments on commit d97d3f1

Please sign in to comment.