Skip to content

Commit a080fcc

Browse files
Add deprecation warning for Faker::Twitter
Besides renaming the generator to Faker::X, the generator is vastly outdated. Twitter, aka X API, has changed a lot (it's now v2), and most of the attributes being returned in the user have been deprecated: https://docs.x.com/x-api/enterprise-gnip-2.0/fundamentals/data-dictionary#no-longer-supported-deprecated-attributes To maintain backwards compatibility, users still using Faker::Twitter will keep using it but be notified of the upcoming changes. Initially, the goal was to only update the `user` generator but then I realized it wouldn't make sense to leave `status` as it is.
1 parent 0fe0b21 commit a080fcc

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

lib/faker/default/twitter.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class << self
1717
#
1818
# @faker.version 1.7.3
1919
def user(include_status: true, include_email: false)
20+
$stdout.puts('DEPRECATION WARNING: Faker::Internet is deprecated. Use Faker::X instead. Some return attributes \
21+
will be removed, check the CHANGELOG for more details.')
22+
2023
user_id = id
2124
background_image_url = Faker::LoremFlickr.image(size: '600x400')
2225
profile_image_url = Faker::Avatar.image(slug: user_id, size: '48x48')

test/faker/default/test_twitter.rb

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,34 @@ def setup
88
end
99

1010
def test_user
11-
user = @tester.user
11+
assert_deprecated do
12+
user = @tester.user
1213

13-
assert_kind_of Hash, user
14-
assert_equal(41, user.keys.count)
15-
assert_kind_of Hash, user[:status]
16-
assert_nil user[:status][:user]
14+
assert_kind_of Hash, user
15+
assert_equal(41, user.keys.count)
16+
assert_kind_of Hash, user[:status]
17+
assert_nil user[:status][:user]
18+
end
1719
end
1820

1921
def test_user_with_email
20-
user = @tester.user(include_email: true)
22+
assert_deprecated do
23+
user = @tester.user(include_email: true)
2124

22-
assert_kind_of Hash, user
23-
assert_equal(42, user.keys.count)
24-
assert_kind_of String, user[:email]
25+
assert_kind_of Hash, user
26+
assert_equal(42, user.keys.count)
27+
assert_kind_of String, user[:email]
28+
end
2529
end
2630

2731
def test_user_without_status
28-
user = @tester.user(include_status: false)
32+
assert_deprecated do
33+
user = @tester.user(include_status: false)
2934

30-
assert_kind_of Hash, user
31-
assert_equal(40, user.keys.count)
32-
assert_nil user[:status]
35+
assert_kind_of Hash, user
36+
assert_equal(40, user.keys.count)
37+
assert_nil user[:status]
38+
end
3339
end
3440

3541
def test_status
@@ -59,4 +65,13 @@ def test_status_with_photo
5965
assert_equal(1, status[:entities][:media].count)
6066
assert_equal(10, status[:entities][:media].first.keys.count)
6167
end
68+
69+
def assert_deprecated(&block)
70+
warning = with_captured_stdout(&block)
71+
result = yield block
72+
73+
refute_predicate warning, :empty?, 'Expected a deprecation warning within the block but received none'
74+
75+
result
76+
end
6277
end

0 commit comments

Comments
 (0)